blob: 2cd8b1a57777e077f63ac9f918b26e405b200524 [file] [log] [blame]
Che-liang Chiouca366d02011-10-06 23:40:48 +00001/*
2 * Copyright (c) 2011 The Chromium OS Authors.
Wolfgang Denk1a459662013-07-08 09:37:19 +02003 * SPDX-License-Identifier: GPL-2.0+
Che-liang Chiouca366d02011-10-06 23:40:48 +00004 */
5
6#include <common.h>
7#include <command.h>
8
Che-liang Chiouca366d02011-10-06 23:40:48 +00009static void report_time(ulong cycles)
10{
11 ulong minutes, seconds, milliseconds;
12 ulong total_seconds, remainder;
13
14 total_seconds = cycles / CONFIG_SYS_HZ;
15 remainder = cycles % CONFIG_SYS_HZ;
16 minutes = total_seconds / 60;
17 seconds = total_seconds % 60;
18 /* approximate millisecond value */
19 milliseconds = (remainder * 1000 + CONFIG_SYS_HZ / 2) / CONFIG_SYS_HZ;
20
21 printf("\ntime:");
22 if (minutes)
23 printf(" %lu minutes,", minutes);
Masahiro Yamada1d643772014-04-18 17:46:13 +090024 printf(" %lu.%03lu seconds\n", seconds, milliseconds);
Che-liang Chiouca366d02011-10-06 23:40:48 +000025}
26
27static int do_time(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
28{
29 ulong cycles = 0;
30 int retval = 0;
Tom Rini146dda32017-09-26 21:12:05 -040031 int repeatable = 0;
Che-liang Chiouca366d02011-10-06 23:40:48 +000032
33 if (argc == 1)
Simon Glass4c12eeb2011-12-10 08:44:01 +000034 return CMD_RET_USAGE;
Che-liang Chiouca366d02011-10-06 23:40:48 +000035
Richard Genoud34765e82012-12-03 06:28:28 +000036 retval = cmd_process(0, argc - 1, argv + 1, &repeatable, &cycles);
Che-liang Chiouca366d02011-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");