cmd_time.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  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. #include <common.h>
  22. #include <command.h>
  23. static void report_time(ulong cycles)
  24. {
  25. ulong minutes, seconds, milliseconds;
  26. ulong total_seconds, remainder;
  27. total_seconds = cycles / CONFIG_SYS_HZ;
  28. remainder = cycles % CONFIG_SYS_HZ;
  29. minutes = total_seconds / 60;
  30. seconds = total_seconds % 60;
  31. /* approximate millisecond value */
  32. milliseconds = (remainder * 1000 + CONFIG_SYS_HZ / 2) / CONFIG_SYS_HZ;
  33. printf("\ntime:");
  34. if (minutes)
  35. printf(" %lu minutes,", minutes);
  36. printf(" %lu.%03lu seconds, %lu ticks\n",
  37. seconds, milliseconds, cycles);
  38. }
  39. static int do_time(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  40. {
  41. ulong cycles = 0;
  42. int retval = 0;
  43. int repeatable;
  44. if (argc == 1)
  45. return CMD_RET_USAGE;
  46. retval = cmd_process(0, argc - 1, argv + 1, &repeatable, &cycles);
  47. report_time(cycles);
  48. return retval;
  49. }
  50. U_BOOT_CMD(time, CONFIG_SYS_MAXARGS, 0, do_time,
  51. "run commands and summarize execution time",
  52. "command [args...]\n");