time.c 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (c) 2011 The Chromium OS Authors.
  4. */
  5. #include <common.h>
  6. #include <command.h>
  7. static void report_time(ulong cycles)
  8. {
  9. ulong minutes, seconds, milliseconds;
  10. ulong total_seconds, remainder;
  11. total_seconds = cycles / CONFIG_SYS_HZ;
  12. remainder = cycles % CONFIG_SYS_HZ;
  13. minutes = total_seconds / 60;
  14. seconds = total_seconds % 60;
  15. /* approximate millisecond value */
  16. milliseconds = (remainder * 1000 + CONFIG_SYS_HZ / 2) / CONFIG_SYS_HZ;
  17. printf("\ntime:");
  18. if (minutes)
  19. printf(" %lu minutes,", minutes);
  20. printf(" %lu.%03lu seconds\n", seconds, milliseconds);
  21. }
  22. static int do_time(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  23. {
  24. ulong cycles = 0;
  25. int retval = 0;
  26. int repeatable = 0;
  27. if (argc == 1)
  28. return CMD_RET_USAGE;
  29. retval = cmd_process(0, argc - 1, argv + 1, &repeatable, &cycles);
  30. report_time(cycles);
  31. return retval;
  32. }
  33. U_BOOT_CMD(time, CONFIG_SYS_MAXARGS, 0, do_time,
  34. "run commands and summarize execution time",
  35. "command [args...]\n");