>From f5e82d7f87033ccdc1ede30c0d24e880852f7790 Mon Sep 17 00:00:00 2001
From: Peter Barada <peter.bar...@logicpd.com>
Date: Sat, 29 Oct 2011 10:44:32 -0400
Subject: [PATCH] Add 'time' command to show execution of sub command.

Add 'time <cmd> <args>' which executes <cmd> with <args> and shows the
execution time in seconds.  Requires get_timer().

Signed-off-by: Peter Barada <peter.bar...@gmail.com>
CC: Wolfgang Denk <w...@denx.de>

---
 README                   |    1 +
 common/cmd_misc.c        |   41 +++++++++++++++++++++++++++++++++++++++++
 include/config_cmd_all.h |    1 +
 3 files changed, 43 insertions(+), 0 deletions(-)

diff --git a/README b/README
index c05c40a..94743af 100644
--- a/README
+++ b/README
@@ -787,6 +787,7 @@ The following options need to be configured:
                                          (requires CONFIG_CMD_MEMORY)
                CONFIG_CMD_SOURCE         "source" command Support
                CONFIG_CMD_SPI          * SPI serial bus support
+               CONFIG_CMD_TIME           times execution of u-boot command
                CONFIG_CMD_TFTPSRV      * TFTP transfer in server mode
                CONFIG_CMD_TFTPPUT      * TFTP put command (upload)
                CONFIG_CMD_TIME         * run command and report execution time
diff --git a/common/cmd_misc.c b/common/cmd_misc.c
index 061b1bb..d789d44 100644
--- a/common/cmd_misc.c
+++ b/common/cmd_misc.c
@@ -53,3 +53,44 @@ U_BOOT_CMD(
        "N\n"
        "    - delay execution for N seconds (N is _decimal_ !!!)"
 );
+
+#ifdef CONFIG_CMD_TIME
+int do_time(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       ulong start;
+       ulong delta;
+       cmd_tbl_t *cmdtp2;
+       int ret;
+       unsigned int secs, msecs;
+
+       if (argc < 2)
+               return cmd_usage(cmdtp);
+
+       cmdtp2 = find_cmd(argv[1]);
+       if (!cmdtp2) {
+               printf("Unknown command '%s' - try help\n", argv[1]);
+               return 1;
+       }
+
+       start = get_timer(0);
+
+       /* Execute command */
+       ret = (cmdtp2->cmd)(cmdtp2, flag, argc-1, argv+1);
+
+       delta = get_timer(start);
+
+       secs = (delta * 1000) / CONFIG_SYS_HZ;
+       msecs = secs % 1000;
+       secs /= 1000;
+
+       printf("'%s' took %u.%03u seconds\n", argv[1], secs, msecs);
+       return ret;
+}
+
+U_BOOT_CMD(
+       time ,    CONFIG_SYS_MAXARGS,    1,     do_time,
+       "time execution of command",
+       "command to time\n"
+       "    - time execution of command in seconds"
+);
+#endif
diff --git a/include/config_cmd_all.h b/include/config_cmd_all.h
index 9716f9c..77adc3d 100644
--- a/include/config_cmd_all.h
+++ b/include/config_cmd_all.h
@@ -82,6 +82,7 @@
 #define CONFIG_CMD_SOURCE      /* "source" command support     */
 #define CONFIG_CMD_SPI         /* SPI utility                  */
 #define CONFIG_CMD_TERMINAL    /* built-in Serial Terminal     */
+#define CONFIG_CMD_TIME                /* time execution of u-boot cmd */
 #define CONFIG_CMD_UBI         /* UBI Support                  */
 #define CONFIG_CMD_UBIFS       /* UBIFS Support                */
 #define CONFIG_CMD_UNIVERSE    /* Tundra Universe Support      */
-- 
1.7.1



-- 
Peter Barada
peter.bar...@logicpd.com

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to