2011-03-16 20:32:05 +00:00
|
|
|
#include <common.h>
|
|
|
|
#include <command.h>
|
|
|
|
#include <clock.h>
|
|
|
|
#include <asm-generic/div64.h>
|
|
|
|
#include <malloc.h>
|
|
|
|
|
2011-12-21 13:18:57 +00:00
|
|
|
static int do_time(int argc, char *argv[])
|
2011-03-16 20:32:05 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
unsigned char *buf;
|
|
|
|
u64 start, end, diff64;
|
|
|
|
unsigned long diff;
|
2011-12-08 08:38:44 +00:00
|
|
|
int len = 1; /* '\0' */
|
2011-03-16 20:32:05 +00:00
|
|
|
|
|
|
|
if (argc < 2)
|
|
|
|
return COMMAND_ERROR_USAGE;
|
|
|
|
|
|
|
|
for (i = 1; i < argc; i++)
|
|
|
|
len += strlen(argv[i]) + 1;
|
|
|
|
|
|
|
|
buf = xzalloc(len);
|
|
|
|
|
|
|
|
for (i = 1; i < argc; i++) {
|
|
|
|
strcat(buf, argv[i]);
|
|
|
|
strcat(buf, " ");
|
|
|
|
}
|
|
|
|
|
|
|
|
start = get_time_ns();
|
|
|
|
|
2014-02-27 11:23:29 +00:00
|
|
|
run_command(buf);
|
2011-03-16 20:32:05 +00:00
|
|
|
|
|
|
|
end = get_time_ns();
|
|
|
|
|
|
|
|
diff64 = end - start;
|
|
|
|
|
|
|
|
do_div(diff64, 1000000);
|
|
|
|
|
|
|
|
diff = diff64;
|
|
|
|
|
2014-04-21 20:15:22 +00:00
|
|
|
printf("time: %lums\n", diff);
|
2011-03-16 20:32:05 +00:00
|
|
|
|
|
|
|
free(buf);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
BAREBOX_CMD_HELP_START(time)
|
|
|
|
BAREBOX_CMD_HELP_USAGE("time <command>\n")
|
|
|
|
BAREBOX_CMD_HELP_SHORT("note: This command depends on <command> being interruptible,\n")
|
|
|
|
BAREBOX_CMD_HELP_SHORT("Otherwise the timer may overrun resulting in incorrect results\n")
|
|
|
|
BAREBOX_CMD_HELP_END
|
|
|
|
|
|
|
|
BAREBOX_CMD_START(time)
|
|
|
|
.cmd = do_time,
|
|
|
|
.usage = "measure execution time of a command",
|
commands: group 'help' output
The old output of "help" was just producing a long list, that usually
scrolled of the screen (even on a X11 terminal). This list is more
compact, and also sorted by groups.
The old output format (plus grouping) is now available with 'help -v'.
Example:
Information commands:
?, devinfo, help, iomem, meminfo, version
Boot commands:
boot, bootm, go, loadb, loads, loadx, loady, saves, uimage
...
Signed-off-by: Holger Schurig <holgerschurig@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2014-05-13 14:14:05 +00:00
|
|
|
BAREBOX_CMD_GROUP(CMD_GRP_MISC)
|
2011-03-16 20:32:05 +00:00
|
|
|
BAREBOX_CMD_HELP(cmd_time_help)
|
|
|
|
BAREBOX_CMD_END
|