blob: eee6084e9685ab77fa5d616d73d4e67a7abe25eb [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Che-liang Chioufd763002011-10-06 23:40:48 +00002/*
3 * Copyright (c) 2011 The Chromium OS Authors.
Che-liang Chioufd763002011-10-06 23:40:48 +00004 */
5
Che-liang Chioufd763002011-10-06 23:40:48 +00006#include <command.h>
7
Che-liang Chioufd763002011-10-06 23:40:48 +00008static void report_time(ulong cycles)
9{
10 ulong minutes, seconds, milliseconds;
11 ulong total_seconds, remainder;
12
13 total_seconds = cycles / CONFIG_SYS_HZ;
14 remainder = cycles % CONFIG_SYS_HZ;
15 minutes = total_seconds / 60;
16 seconds = total_seconds % 60;
17 /* approximate millisecond value */
18 milliseconds = (remainder * 1000 + CONFIG_SYS_HZ / 2) / CONFIG_SYS_HZ;
19
20 printf("\ntime:");
21 if (minutes)
22 printf(" %lu minutes,", minutes);
Masahiro Yamadab1c675c2014-04-18 17:46:13 +090023 printf(" %lu.%03lu seconds\n", seconds, milliseconds);
Che-liang Chioufd763002011-10-06 23:40:48 +000024}
25
Simon Glassed38aef2020-05-10 11:40:03 -060026static int do_time(struct cmd_tbl *cmdtp, int flag, int argc,
27 char *const argv[])
Che-liang Chioufd763002011-10-06 23:40:48 +000028{
29 ulong cycles = 0;
30 int retval = 0;
Tom Rini9ee01672017-09-26 21:12:05 -040031 int repeatable = 0;
Che-liang Chioufd763002011-10-06 23:40:48 +000032
33 if (argc == 1)
Simon Glassa06dfc72011-12-10 08:44:01 +000034 return CMD_RET_USAGE;
Che-liang Chioufd763002011-10-06 23:40:48 +000035
Richard Genoud94ff0672012-12-03 06:28:28 +000036 retval = cmd_process(0, argc - 1, argv + 1, &repeatable, &cycles);
Che-liang Chioufd763002011-10-06 23:40:48 +000037 report_time(cycles);
38
39 return retval;
40}
41
42U_BOOT_CMD(time, CONFIG_SYS_MAXARGS, 0, do_time,
43 "run commands and summarize execution time",
44 "command [args...]\n");