cmd_time.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright (c) 2011 The Chromium OS Authors.
  3. * SPDX-License-Identifier: GPL-2.0+
  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, %lu ticks\n",
  21. seconds, milliseconds, cycles);
  22. }
  23. static int do_time(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  24. {
  25. ulong cycles = 0;
  26. int retval = 0;
  27. int repeatable;
  28. if (argc == 1)
  29. return CMD_RET_USAGE;
  30. retval = cmd_process(0, argc - 1, argv + 1, &repeatable, &cycles);
  31. report_time(cycles);
  32. return retval;
  33. }
  34. U_BOOT_CMD(time, CONFIG_SYS_MAXARGS, 0, do_time,
  35. "run commands and summarize execution time",
  36. "command [args...]\n");