summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2011-08-04 09:03:38 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2011-08-04 09:03:38 +0200
commit24eb43256f156adfcdd162806355c16be533adaa (patch)
tree31a1544a2b2abfab968fa67606e427297244bfd8
parent46a16b72a04e936f28d788a41a091dd348de7fd7 (diff)
parent5de95712d99eff5c628b19681b12a88dd20ec021 (diff)
downloadbarebox-24eb43256f156adfcdd162806355c16be533adaa.tar.gz
barebox-24eb43256f156adfcdd162806355c16be533adaa.tar.xz
Merge branch 'pu-time' into next
-rw-r--r--commands/Kconfig10
-rw-r--r--commands/Makefile1
-rw-r--r--commands/mem.c3
-rw-r--r--commands/time.c57
4 files changed, 71 insertions, 0 deletions
diff --git a/commands/Kconfig b/commands/Kconfig
index 5700dc2890..e9222601c4 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -97,6 +97,16 @@ endchoice
endif
+config CMD_TIME
+ bool "time"
+ help
+ Just like the unix time command this command allows to measure the
+ execution time of a command. Note: barebox does not use interrupts,
+ so the system timer can overrun during the execution of the command
+ resulting in incorrect results. The timer gets updated in the function
+ checking for ctrl-c, so the time command can be used with commands
+ which are interruptible with ctrl-c.
+
endmenu
menu "file commands "
diff --git a/commands/Makefile b/commands/Makefile
index 8ee4aba726..7c88b488f2 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -57,3 +57,4 @@ obj-$(CONFIG_CMD_LOGIN) += login.o
obj-$(CONFIG_CMD_LED) += led.o
obj-$(CONFIG_CMD_LED_TRIGGER) += trigger.o
obj-$(CONFIG_CMD_USB) += usb.o
+obj-$(CONFIG_CMD_TIME) += time.o
diff --git a/commands/mem.c b/commands/mem.c
index a5eea36049..88af55c1b8 100644
--- a/commands/mem.c
+++ b/commands/mem.c
@@ -483,6 +483,9 @@ static int do_mem_cp(struct command *cmdtp, int argc, char *argv[])
}
count -= r;
+
+ if (ctrlc())
+ goto out;
}
if (count) {
diff --git a/commands/time.c b/commands/time.c
new file mode 100644
index 0000000000..9a769451aa
--- /dev/null
+++ b/commands/time.c
@@ -0,0 +1,57 @@
+#include <common.h>
+#include <command.h>
+#include <clock.h>
+#include <asm-generic/div64.h>
+#include <malloc.h>
+
+static int do_time(struct command *cmdtp, int argc, char *argv[])
+{
+ int i;
+ unsigned char *buf;
+ u64 start, end, diff64;
+ unsigned long diff;
+ int len = 0;
+
+ 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();
+
+ run_command(buf, 0);
+
+ end = get_time_ns();
+
+ diff64 = end - start;
+
+ do_div(diff64, 1000000);
+
+ diff = diff64;
+
+ printf("time: %ldms\n", diff);
+
+ 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",
+ BAREBOX_CMD_HELP(cmd_time_help)
+BAREBOX_CMD_END