OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
| 3 * Use of this source code is governed by a BSD-style license that can be |
| 4 * found in the LICENSE file. |
| 5 * |
| 6 * Alternatively, this software may be distributed under the terms of the |
| 7 * GNU General Public License ("GPL") version 2 as published by the Free |
| 8 * Software Foundation. |
| 9 */ |
| 10 |
| 11 /* time - run a command and report its run time */ |
| 12 |
| 13 #include <common.h> |
| 14 #include <command.h> |
| 15 |
| 16 static void report_time(unsigned long int cycles) |
| 17 { |
| 18 #ifdef CONFIG_SYS_HZ |
| 19 unsigned long int minutes, seconds, milliseconds; |
| 20 unsigned long int total_seconds, remainder; |
| 21 |
| 22 total_seconds = cycles / CONFIG_SYS_HZ; |
| 23 remainder = cycles % CONFIG_SYS_HZ; |
| 24 minutes = total_seconds / 60; |
| 25 seconds = total_seconds % 60; |
| 26 /* approximate millisecond value */ |
| 27 milliseconds = (remainder * 1000 + CONFIG_SYS_HZ / 2) / CONFIG_SYS_HZ; |
| 28 |
| 29 printf("time:"); |
| 30 if (minutes) |
| 31 printf(" %lu minutes,", minutes); |
| 32 printf(" %lu.%03lu seconds,", seconds, milliseconds); |
| 33 printf(" %lu ticks\n", cycles); |
| 34 #else |
| 35 printf("CONFIG_SYS_HZ not defined\n"); |
| 36 printf("time: %lu ticks\n", cycles); |
| 37 #endif |
| 38 } |
| 39 |
| 40 int do_time(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 41 { |
| 42 const int target_argc = argc - 1; |
| 43 int retval = 0; |
| 44 unsigned long int cycles = 0; |
| 45 cmd_tbl_t *target_cmdtp = NULL; |
| 46 |
| 47 if (argc == 1) { |
| 48 printf("no command provided\n"); |
| 49 return 1; |
| 50 } |
| 51 |
| 52 /* parse command */ |
| 53 target_cmdtp = find_cmd(argv[1]); |
| 54 if (!target_cmdtp) { |
| 55 printf("command not found: %s\n", argv[1]); |
| 56 return 1; |
| 57 } |
| 58 |
| 59 if (target_argc > target_cmdtp->maxargs) { |
| 60 printf("maxarags exceeded: %d > %d\n", target_argc, |
| 61 target_cmdtp->maxargs); |
| 62 return 1; |
| 63 } |
| 64 |
| 65 /* run the command and report run time */ |
| 66 cycles = get_timer_masked(); |
| 67 retval = target_cmdtp->cmd(target_cmdtp, 0, target_argc, argv + 1); |
| 68 cycles = get_timer_masked() - cycles; |
| 69 |
| 70 putc('\n'); |
| 71 report_time(cycles); |
| 72 |
| 73 return retval; |
| 74 } |
| 75 |
| 76 U_BOOT_CMD(time, CONFIG_SYS_MAXARGS, 0, do_time, |
| 77 "run a command and report its run time", |
| 78 "command [args...]\n" |
| 79 "the return value of time is the return value of " |
| 80 "the command it executed, " |
| 81 "or non-zero if there is an internal error of time.\n"); |
OLD | NEW |