mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <sha@pengutronix.de>
To: Ahmad Fatoum <a.fatoum@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH] commands: time: add -n option for nanoseconds output
Date: Wed, 5 Jan 2022 09:50:23 +0100	[thread overview]
Message-ID: <20220105085023.GP6003@pengutronix.de> (raw)
In-Reply-To: <20220103120310.1729050-1-a.fatoum@pengutronix.de>

On Mon, Jan 03, 2022 at 01:03:10PM +0100, Ahmad Fatoum wrote:
> The current millisecond output may be too coarse for debugging timing
> of barebox functionality. Add an optional nanosecond output.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
>  commands/time.c | 21 ++++++++++++++-------
>  1 file changed, 14 insertions(+), 7 deletions(-)
> 
> diff --git a/commands/time.c b/commands/time.c
> index 25ba2da15ed5..2d9fb75e7a8c 100644
> --- a/commands/time.c
> +++ b/commands/time.c
> @@ -9,7 +9,7 @@ static int do_time(int argc, char *argv[])
>  	int i;
>  	unsigned char *buf;
>  	u64 start, end, diff64;
> -	unsigned long diff;
> +	bool nanoseconds = false;
>  	int len = 1; /* '\0' */
>  
>  	if (argc < 2)
> @@ -20,7 +20,13 @@ static int do_time(int argc, char *argv[])
>  
>  	buf = xzalloc(len);

The argv[] elements are copied into a string allocated here. The number
of bytes needed is calculated before the option parsing, so the space
allocated here unnecessarily includes the space for the options. Not a
big deal, but I think it's more consistent to move the option parsing
before calculating the needed buffer space.

>  
> -	for (i = 1; i < argc; i++) {
> +	i = 1;
> +	if (!strcmp(argv[i], "-n")) {
> +		nanoseconds = true;
> +		i++;
> +	}

I just created a patch to support '+' as the first character of
optstring. This allows you to use regular getopt for option parsing
here.

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


      reply	other threads:[~2022-01-05  8:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-03 12:03 Ahmad Fatoum
2022-01-05  8:50 ` Sascha Hauer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220105085023.GP6003@pengutronix.de \
    --to=sha@pengutronix.de \
    --cc=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox