summaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2022-01-03 13:03:10 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2022-01-05 09:07:42 +0100
commitcb0d339074cf17fa806633126ad5146cd2909db7 (patch)
treee593c81c27826d4dbab9ed2cf25cae4ffbb8773f /commands
parentdc8c0a9425a7be301e03e77489a25b14e20b383a (diff)
downloadbarebox-cb0d339074cf17fa806633126ad5146cd2909db7.tar.gz
barebox-cb0d339074cf17fa806633126ad5146cd2909db7.tar.xz
commands: time: add -n option for nanoseconds output
The current millisecond output may be too coarse for debugging timing of barebox functionality. Add an optional nanosecond output. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20220103120310.1729050-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands')
-rw-r--r--commands/time.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/commands/time.c b/commands/time.c
index 25ba2da15e..2d9fb75e7a 100644
--- a/commands/time.c
+++ b/commands/time.c
@@ -9,7 +9,7 @@ static int do_time(int argc, char *argv[])
int i;
unsigned char *buf;
u64 start, end, diff64;
- unsigned long diff;
+ bool nanoseconds = false;
int len = 1; /* '\0' */
if (argc < 2)
@@ -20,7 +20,13 @@ static int do_time(int argc, char *argv[])
buf = xzalloc(len);
- for (i = 1; i < argc; i++) {
+ i = 1;
+ if (!strcmp(argv[i], "-n")) {
+ nanoseconds = true;
+ i++;
+ }
+
+ for (; i < argc; i++) {
strcat(buf, argv[i]);
strcat(buf, " ");
}
@@ -33,11 +39,10 @@ static int do_time(int argc, char *argv[])
diff64 = end - start;
- do_div(diff64, 1000000);
-
- diff = diff64;
+ if (!nanoseconds)
+ do_div(diff64, 1000000);
- printf("time: %lums\n", diff);
+ printf("time: %llu%cs\n", diff64, nanoseconds ? 'n' : 'm');
free(buf);
@@ -47,12 +52,14 @@ static int do_time(int argc, char *argv[])
BAREBOX_CMD_HELP_START(time)
BAREBOX_CMD_HELP_TEXT("Note: This command depends on COMMAND being interruptible,")
BAREBOX_CMD_HELP_TEXT("otherwise the timer may overrun resulting in incorrect results")
+BAREBOX_CMD_HELP_TEXT("Options:")
+BAREBOX_CMD_HELP_OPT ("-n", "output elapsed time in nanoseconds")
BAREBOX_CMD_HELP_END
BAREBOX_CMD_START(time)
.cmd = do_time,
BAREBOX_CMD_DESC("measure execution duration of a command")
- BAREBOX_CMD_OPTS("COMMAND")
+ BAREBOX_CMD_OPTS("[-n] COMMAND")
BAREBOX_CMD_GROUP(CMD_GRP_MISC)
BAREBOX_CMD_HELP(cmd_time_help)
BAREBOX_CMD_END