From: Mike Frysinger Date: Wed, 5 Oct 2011 13:24:03 -0400 Subject: [U-Boot] [PATCH] cmd_time: add time command In-Reply-To: <1317798555-2720-1-git-send-email-clchiou@chromium.org> References: <1317798555-2720-1-git-send-email-clchiou@chromium.org> Message-ID: <201110051324.03697.vapier@gentoo.org> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de 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