[U-Boot] [PATCH] cmd_time: add time command

Mike Frysinger vapier at gentoo.org
Wed Oct 5 19:24:03 CEST 2011


On Wednesday 05 October 2011 03:09:15 Che-Liang Chiou wrote:
> The 'time' command runs and reports execution time of commands.

cool

> Sameple usage:

typo: Sample

> --- /dev/null
> +++ b/common/cmd_time.c
>
> +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

> +	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;
> +
> +	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

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

static

> +	cmd_tbl_t *target_cmdtp = NULL;

const

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

return cmd_usage(cmdtp);

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

shells typically display:
	%s: command not found

> +	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 ...

> +	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 


More information about the U-Boot mailing list