blob: 9808cd6699532bb6b29e785fc56338a9f79a7be6 [file] [log] [blame]
Che-liang Chiouca366d02011-10-06 23:40:48 +00001/*
2 * Copyright (c) 2011 The Chromium OS Authors.
3 * See file CREDITS for list of people who contributed to this
4 * project.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of
9 * the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
19 * MA 02111-1307 USA
20 */
21
22#include <common.h>
23#include <command.h>
24
Che-liang Chiouca366d02011-10-06 23:40:48 +000025static void report_time(ulong cycles)
26{
27 ulong minutes, seconds, milliseconds;
28 ulong total_seconds, remainder;
29
30 total_seconds = cycles / CONFIG_SYS_HZ;
31 remainder = cycles % CONFIG_SYS_HZ;
32 minutes = total_seconds / 60;
33 seconds = total_seconds % 60;
34 /* approximate millisecond value */
35 milliseconds = (remainder * 1000 + CONFIG_SYS_HZ / 2) / CONFIG_SYS_HZ;
36
37 printf("\ntime:");
38 if (minutes)
39 printf(" %lu minutes,", minutes);
40 printf(" %lu.%03lu seconds, %lu ticks\n",
41 seconds, milliseconds, cycles);
42}
43
44static int do_time(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
45{
46 ulong cycles = 0;
47 int retval = 0;
Richard Genoud34765e82012-12-03 06:28:28 +000048 int repeatable;
Che-liang Chiouca366d02011-10-06 23:40:48 +000049
50 if (argc == 1)
Simon Glass4c12eeb2011-12-10 08:44:01 +000051 return CMD_RET_USAGE;
Che-liang Chiouca366d02011-10-06 23:40:48 +000052
Richard Genoud34765e82012-12-03 06:28:28 +000053 retval = cmd_process(0, argc - 1, argv + 1, &repeatable, &cycles);
Che-liang Chiouca366d02011-10-06 23:40:48 +000054 report_time(cycles);
55
56 return retval;
57}
58
59U_BOOT_CMD(time, CONFIG_SYS_MAXARGS, 0, do_time,
60 "run commands and summarize execution time",
61 "command [args...]\n");