Skip to contentSkip to conversation

cmd_time: add time command

PATCH Superseded Che-Liang Chiou 3 participants 9 messages Oct 5, 2011 – Oct 9, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cmd_time: add time command

The 'time' command runs and reports execution time of commands.

Sameple usage:
--------------------
u-boot# time crc 0x1000 1000
CRC32 for 00001000 ... 00001fff ==> ae94dc4b

time: 0.004 seconds, 4 ticks
--------------------

---
 README                   |    1 +
 common/Makefile          |    1 +
 common/cmd_time.c        |   84 ++++++++++++++++++++++++++++++++++++++++++++++
 include/config_cmd_all.h |    1 +
 4 files changed, 87 insertions(+), 0 deletions(-)
 create mode 100644 common/cmd_time.c
README +1 -0
index 91b6695..d6017e5 100644
@@ -769,6 +769,7 @@ The following options need to be configured:
 		CONFIG_CMD_SOURCE	  "source" command Support
 		CONFIG_CMD_SPI		* SPI serial bus support
 		CONFIG_CMD_TFTPSRV	* TFTP transfer in server mode
+		CONFIG_CMD_TIME		* run command and report execution time
 		CONFIG_CMD_USB		* USB support
 		CONFIG_CMD_CDP		* Cisco Discover Protocol support
 		CONFIG_CMD_FSL		* Microblaze FSL support
common/Makefile +1 -0
index 371a0d9..fdc4206 100644
@@ -147,6 +147,7 @@ COBJS-$(CONFIG_CMD_SPI) += cmd_spi.o
 COBJS-$(CONFIG_CMD_SPIBOOTLDR) += cmd_spibootldr.o
 COBJS-$(CONFIG_CMD_STRINGS) += cmd_strings.o
 COBJS-$(CONFIG_CMD_TERMINAL) += cmd_terminal.o
+COBJS-$(CONFIG_CMD_TIME) += cmd_time.o
 COBJS-$(CONFIG_SYS_HUSH_PARSER) += cmd_test.o
 COBJS-$(CONFIG_CMD_TSI148) += cmd_tsi148.o
 COBJS-$(CONFIG_CMD_UBI) += cmd_ubi.o
common/cmd_time.c new file +84 -0

84 lines not on this page · raw message

include/config_cmd_all.h +1 -0
index 9716f9c..181674b 100644
@@ -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		/* run command and report execution time */
 #define CONFIG_CMD_UBI		/* UBI Support			*/
 #define CONFIG_CMD_UBIFS	/* UBIFS Support		*/
 #define CONFIG_CMD_UNIVERSE	/* Tundra Universe Support	*/
Signature · 1 line
1.7.3.1
#1 lore raw

PATCH 1/1 cmd_time: add time command

Quoted 1 line · On Wednesday 05 October 2011 03:09:15 Che-Liang Chiou wrote:

The 'time' command runs and reports execution time of commands.

cool

Quoted 1 line

Sameple usage:

typo: Sample

common/cmd_time.c line 27

Quoted 6 lines
common/cmd_time.c new file +3 -0
 
+static void report_time(unsigned long int cycles)
+{
+#ifdef CONFIG_SYS_HZ

CONFIG_SYS_HZ is required to be defined, so please drop this ifdef check

Quoted 5 lines
common/cmd_time.c new file +5 -0
+	unsigned long int minutes, seconds, milliseconds;
+	unsigned long int total_seconds, remainder;
+
+	total_seconds = cycles / CONFIG_SYS_HZ;
+	remainder = cycles % CONFIG_SYS_HZ;

common/cmd_time.c line 42

Quoted 10 lines
common/cmd_time.c new file +10 -0
+	minutes = total_seconds / 60;
+	seconds = total_seconds % 60;
+	/* approximate millisecond value */
+	milliseconds = (remainder * 1000 + CONFIG_SYS_HZ / 2) / CONFIG_SYS_HZ;
+
+	printf("time:");
+	if (minutes)
+		printf(" %lu minutes,", minutes);
+	printf(" %lu.%03lu seconds, %lu ticks\n",
+			seconds, milliseconds, cycles);

looks like this could use the new timer api that Graeme is throwing around

Quoted 1 line

+int do_time(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])

static

common/cmd_time.c line 54

Quoted 1 line
common/cmd_time.c new file +1 -0
+	cmd_tbl_t *target_cmdtp = NULL;

const

common/cmd_time.c line 59

Quoted 4 lines
common/cmd_time.c new file +4 -0
+	if (argc == 1) {
+		printf("no command provided\n");
+		return 1;
+	}

return cmd_usage(cmdtp);

common/cmd_time.c line 65

Quoted 4 lines
common/cmd_time.c new file +4 -0
+	if (!target_cmdtp) {
+		printf("command not found: %s\n", argv[1]);
+		return 1;
+	}

shells typically display:
%s: command not found

common/cmd_time.c line 73

Quoted 7 lines
common/cmd_time.c new file +6 -0
+	if (target_argc > target_cmdtp->maxargs) {
+		printf("maxarags exceeded: %d > %d\n", target_argc,
+				target_cmdtp->maxargs);
+		return 1;
+	}
...
+	retval = target_cmdtp->cmd(target_cmdtp, 0, target_argc, argv + 1);

hmm, this looks like we should add a helper like run_command() and put this logic there ...

common/cmd_time.c line 77

Quoted 2 lines
common/cmd_time.c new file +2 -0
+	putc('\n');
+	report_time(cycles);

why not just integrate that \n into the report_time() code ?
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20111005/16af5c12/attachment.pgp

#2 lore raw

PATCH 1/1 cmd_time: add time command

Hi Mike,

Thanks for comments. Reply inlined.

Quoted 8 lines · Mike Frysinger
Quoted 1 line · On Wednesday 05 October 2011 03:09:15 Che-Liang Chiou wrote:

The 'time' command runs and reports execution time of commands.

cool

Quoted 1 line

Sameple usage:

typo: Sample

Done.

Quoted 10 lines

common/cmd_time.c line 27

Quoted 7 lines
common/cmd_time.c new file +3 -0
 
+static void report_time(unsigned long int cycles)
+{
+#ifdef CONFIG_SYS_HZ

CONFIG_SYS_HZ is required to be defined, so please drop this ifdef check

Done.

Quoted 9 lines
Quoted 9 lines

+ ? ? unsigned long int minutes, seconds, milliseconds;
+ ? ? unsigned long int total_seconds, remainder;
+
+ ? ? total_seconds = cycles / CONFIG_SYS_HZ;
+ ? ? remainder = cycles % CONFIG_SYS_HZ;
+ ? ? minutes = total_seconds / 60;
+ ? ? seconds = total_seconds % 60;
+ ? ? /* approximate millisecond value */
+ ? ? milliseconds = (remainder * 1000 + CONFIG_SYS_HZ / 2) / CONFIG_SYS_HZ;

Quoted 9 lines
Quoted 6 lines

+
+ ? ? printf("time:");
+ ? ? if (minutes)
+ ? ? ? ? ? ? printf(" %lu minutes,", minutes);
+ ? ? printf(" %lu.%03lu seconds, %lu ticks\n",
+ ? ? ? ? ? ? ? ? ? ? seconds, milliseconds, cycles);

looks like this could use the new timer api that Graeme is throwing around

Exactly. Add TODO comments.

Quoted 4 lines
Quoted 1 line

+int do_time(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])

static

Done.

Quoted 4 lines
Quoted 1 line

+ ? ? cmd_tbl_t *target_cmdtp = NULL;

const

I guess I cannot change it to a const pointer. cmdtp->cmd() signature requires a non-const pointer to cmdtp.

Quoted 7 lines
Quoted 4 lines

+ ? ? if (argc == 1) {
+ ? ? ? ? ? ? printf("no command provided\n");
+ ? ? ? ? ? ? return 1;
+ ? ? }

return cmd_usage(cmdtp);

Done.

Quoted 8 lines
Quoted 4 lines

+ ? ? if (!target_cmdtp) {
+ ? ? ? ? ? ? printf("command not found: %s\n", argv[1]);
+ ? ? ? ? ? ? return 1;
+ ? ? }

shells typically display:
? ? ? ?%s: command not found

Done.

Quoted 11 lines
Quoted 7 lines

+ ? ? if (target_argc > target_cmdtp->maxargs) {
+ ? ? ? ? ? ? printf("maxarags exceeded: %d > %d\n", target_argc,
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? target_cmdtp->maxargs);
+ ? ? ? ? ? ? return 1;
+ ? ? }
...
+ ? ? retval = target_cmdtp->cmd(target_cmdtp, 0, target_argc, argv + 1);

hmm, this looks like we should add a helper like run_command() and put this logic there ...

I agree. I moved these codes to a separate function. It can be merged with run_command() if necessary after the timer API is landed.

Quoted 4 lines
Quoted 2 lines

+ ? ? putc('\n');
+ ? ? report_time(cycles);

why not just integrate that \n into the report_time() code ?

Done.

Quoted 2 lines

-mike

Regards,
Che-Liang

#3 lore raw

PATCH 1/1 cmd_time: add time command

Quoted 8 lines · Che-liang Chiou
Quoted 4 lines · Mike Frysinger
Quoted 1 line · On Wednesday 05 October 2011 03:09:15 Che-Liang Chiou wrote:

+ ? ? cmd_tbl_t *target_cmdtp = NULL;

const

I guess I cannot change it to a const pointer. cmdtp->cmd() signature requires a non-const pointer to cmdtp.

ah, yeah, that's something i've been meaning to fix for a while -mike

#4 lore raw

PATCH v2 1/1 cmd_time: add time command

In reply to Che-Liang Chiou

The 'time' command runs and reports execution time of commands.

Sample usage:
--------------------
u-boot# time crc 0x1000 1000
CRC32 for 00001000 ... 00001fff ==> ae94dc4b

time: 0.004 seconds, 4 ticks
--------------------

---
Changes Since V1
- Switch unsigned long int to ulong to match function prototype
- Remove unnecessary 'ifdef CONFIG_SYS_HZ' guard
- Factor out codes into the run_command_and_time_it() function

 README                   |    1 +
 common/Makefile          |    1 +
 common/cmd_time.c        |   90 ++++++++++++++++++++++++++++++++++++++++++++++
 include/config_cmd_all.h |    1 +
 4 files changed, 93 insertions(+), 0 deletions(-)
 create mode 100644 common/cmd_time.c
README +1 -0
index 91b6695..d6017e5 100644
@@ -769,6 +769,7 @@ The following options need to be configured:
 		CONFIG_CMD_SOURCE	  "source" command Support
 		CONFIG_CMD_SPI		* SPI serial bus support
 		CONFIG_CMD_TFTPSRV	* TFTP transfer in server mode
+		CONFIG_CMD_TIME		* run command and report execution time
 		CONFIG_CMD_USB		* USB support
 		CONFIG_CMD_CDP		* Cisco Discover Protocol support
 		CONFIG_CMD_FSL		* Microblaze FSL support
common/Makefile +1 -0
index 371a0d9..fdc4206 100644
@@ -147,6 +147,7 @@ COBJS-$(CONFIG_CMD_SPI) += cmd_spi.o
 COBJS-$(CONFIG_CMD_SPIBOOTLDR) += cmd_spibootldr.o
 COBJS-$(CONFIG_CMD_STRINGS) += cmd_strings.o
 COBJS-$(CONFIG_CMD_TERMINAL) += cmd_terminal.o
+COBJS-$(CONFIG_CMD_TIME) += cmd_time.o
 COBJS-$(CONFIG_SYS_HUSH_PARSER) += cmd_test.o
 COBJS-$(CONFIG_CMD_TSI148) += cmd_tsi148.o
 COBJS-$(CONFIG_CMD_UBI) += cmd_ubi.o
common/cmd_time.c new file +90 -0

90 lines not on this page · raw message

include/config_cmd_all.h +1 -0
index 9716f9c..181674b 100644
@@ -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		/* run command and report execution time */
 #define CONFIG_CMD_UBI		/* UBI Support			*/
 #define CONFIG_CMD_UBIFS	/* UBIFS Support		*/
 #define CONFIG_CMD_UNIVERSE	/* Tundra Universe Support	*/
Signature · 1 line
1.7.3.1
#5 lore raw

PATCH v2 1/1 cmd_time: add time command

Quoted 8 lines · Che-Liang Chiou

+ ? ? ? /*
+ ? ? ? ?* TODO(clchiou): get_timer_masked() is only defined in certain ARM
+ ? ? ? ?* boards. ?We could use the new timer API that Graeme is proposing
+ ? ? ? ?* so that this piece of code would be arch-independent.
+ ? ? ? ?*/
+ ? ? ? *cycles = get_timer_masked();
+ ? ? ? retval = cmdtp->cmd(cmdtp, flag, argc, argv);
+ ? ? ? *cycles = get_timer_masked() - *cycles;

if that's true, this can't be added to config_cmd_all.h -mike

#6 lore raw

PATCH v3 1/1 cmd_time: add time command

In reply to Che-Liang Chiou

The 'time' command runs and reports execution time of commands.

Sample usage:
--------------------
u-boot# time crc 0x1000 1000
CRC32 for 00001000 ... 00001fff ==> ae94dc4b

time: 0.004 seconds, 4 ticks
--------------------

---

Changes since V2
- Remove CONFIG_CMD_TIME from config_cmd_all.h

Changes Since V1
- Switch unsigned long int to ulong to match function prototype
- Remove unnecessary 'ifdef CONFIG_SYS_HZ' guard
- Factor out codes into the run_command_and_time_it() function

 README            |    1 +
 common/Makefile   |    1 +
 common/cmd_time.c |   90 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 92 insertions(+), 0 deletions(-)
 create mode 100644 common/cmd_time.c
README +1 -0
index 0868531..246e76f 100644
@@ -783,6 +783,7 @@ The following options need to be configured:
 		CONFIG_CMD_SOURCE	  "source" command Support
 		CONFIG_CMD_SPI		* SPI serial bus support
 		CONFIG_CMD_TFTPSRV	* TFTP transfer in server mode
+		CONFIG_CMD_TIME		* run command and report execution time
 		CONFIG_CMD_USB		* USB support
 		CONFIG_CMD_CDP		* Cisco Discover Protocol support
 		CONFIG_CMD_FSL		* Microblaze FSL support
common/Makefile +1 -0
index 371a0d9..fdc4206 100644
@@ -147,6 +147,7 @@ COBJS-$(CONFIG_CMD_SPI) += cmd_spi.o
 COBJS-$(CONFIG_CMD_SPIBOOTLDR) += cmd_spibootldr.o
 COBJS-$(CONFIG_CMD_STRINGS) += cmd_strings.o
 COBJS-$(CONFIG_CMD_TERMINAL) += cmd_terminal.o
+COBJS-$(CONFIG_CMD_TIME) += cmd_time.o
 COBJS-$(CONFIG_SYS_HUSH_PARSER) += cmd_test.o
 COBJS-$(CONFIG_CMD_TSI148) += cmd_tsi148.o
 COBJS-$(CONFIG_CMD_UBI) += cmd_ubi.o
common/cmd_time.c new file +90 -0

90 lines not on this page · raw message

Signature · 1 line
1.7.3.1
#8 lore raw

PATCH v3 1/1 cmd_time: add time command

In reply to Che-Liang Chiou

Dear Che-Liang Chiou,

Quoted 21 lines · In message <[email protected]> you wrote:

The 'time' command runs and reports execution time of commands.

Sample usage:
--------------------
u-boot# time crc 0x1000 1000
CRC32 for 00001000 ... 00001fff ==> ae94dc4b

time: 0.004 seconds, 4 ticks
--------------------

---

Changes since V2
- Remove CONFIG_CMD_TIME from config_cmd_all.h

Changes Since V1
- Switch unsigned long int to ulong to match function prototype
- Remove unnecessary 'ifdef CONFIG_SYS_HZ' guard
- Factor out codes into the run_command_and_time_it() function

Quoted 5 lines
 README            |    1 +
 common/Makefile   |    1 +
 common/cmd_time.c |   90 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 92 insertions(+), 0 deletions(-)
 create mode 100644 common/cmd_time.c

Applied, thanks.

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
War is never imperative.
	-- McCoy, "Balance of Terror", stardate 1709.2