Blame view

cmd/time.c 1.01 KB
83d290c56   Tom Rini   SPDX: Convert all...
1
  // SPDX-License-Identifier: GPL-2.0+
ca366d0e3   Che-liang Chiou   cmd_time: add tim...
2
3
  /*
   * Copyright (c) 2011 The Chromium OS Authors.
ca366d0e3   Che-liang Chiou   cmd_time: add tim...
4
5
6
7
   */
  
  #include <common.h>
  #include <command.h>
ca366d0e3   Che-liang Chiou   cmd_time: add tim...
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  static void report_time(ulong cycles)
  {
  	ulong minutes, seconds, milliseconds;
  	ulong total_seconds, remainder;
  
  	total_seconds = cycles / CONFIG_SYS_HZ;
  	remainder = cycles % CONFIG_SYS_HZ;
  	minutes = total_seconds / 60;
  	seconds = total_seconds % 60;
  	/* approximate millisecond value */
  	milliseconds = (remainder * 1000 + CONFIG_SYS_HZ / 2) / CONFIG_SYS_HZ;
  
  	printf("
  time:");
  	if (minutes)
  		printf(" %lu minutes,", minutes);
1d6437717   Masahiro Yamada   cmd_time: do not ...
24
25
  	printf(" %lu.%03lu seconds
  ", seconds, milliseconds);
ca366d0e3   Che-liang Chiou   cmd_time: add tim...
26
27
28
29
30
31
  }
  
  static int do_time(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  {
  	ulong cycles = 0;
  	int retval = 0;
146dda391   Tom Rini   cmd/time.c: Initi...
32
  	int repeatable = 0;
ca366d0e3   Che-liang Chiou   cmd_time: add tim...
33
34
  
  	if (argc == 1)
4c12eeb8b   Simon Glass   Convert cmd_usage...
35
  		return CMD_RET_USAGE;
ca366d0e3   Che-liang Chiou   cmd_time: add tim...
36

34765e885   Richard Genoud   cmd_time: merge r...
37
  	retval = cmd_process(0, argc - 1, argv + 1, &repeatable, &cycles);
ca366d0e3   Che-liang Chiou   cmd_time: add tim...
38
39
40
41
42
43
44
45
46
  	report_time(cycles);
  
  	return retval;
  }
  
  U_BOOT_CMD(time, CONFIG_SYS_MAXARGS, 0, do_time,
  		"run commands and summarize execution time",
  		"command [args...]
  ");