From: Stefano Brivio <sbrivio@redhat.com>
To: David Gibson <david@gibson.dropbear.id.au>
Cc: passt-dev@passt.top
Subject: Re: [PATCH v2 2/4] log: Correct formatting of timestamps
Date: Wed, 7 Aug 2024 10:17:46 +0200 [thread overview]
Message-ID: <20240807101746.35d08f0c@elisabeth> (raw)
In-Reply-To: <ZrLIrPredB_41eQ0@zatzit.fritz.box>
On Wed, 7 Aug 2024 11:06:52 +1000
David Gibson <david@gibson.dropbear.id.au> wrote:
> On Tue, Aug 06, 2024 at 09:08:07PM +0200, Stefano Brivio wrote:
> > On Tue, 6 Aug 2024 16:18:37 +1000
> > David Gibson <david@gibson.dropbear.id.au> wrote:
> >
> > > logtime_fmt_and_arg() is a rather odd macro, producing both a format
> > > string and an argument, which can only be used in quite specific printf()
> > > like formulations. It also has a significant bug: it tries to display 4
> > > digits after the decimal point (so down to tenths of milliseconds) using
> > > %04i. But the field width in printf() is always a *minimum* not maximum
> > > field width, so this will not truncate the given value, but will redisplay
> > > the entire tenth-of-milliseconds difference again after the decimal point.
> >
> > Weird, not for me (glibc 2.38). But anyway, yes, it's much better this
> > way, and definitely, it's specified as minimum width (I never noticed).
> >
> > Just one nit:
> >
> > > Replace the macro with an snprintf() like function which will format the
> > > timestamp, and use an explicit % to correct the display.
> > >
> > > Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
> > > ---
> > > log.c | 36 ++++++++++++++++++++++++------------
> > > 1 file changed, 24 insertions(+), 12 deletions(-)
> > >
> > > diff --git a/log.c b/log.c
> > > index eb3a780a..e60852f7 100644
> > > --- a/log.c
> > > +++ b/log.c
> > > @@ -46,14 +46,24 @@ int log_trace; /* --trace mode enabled */
> > > bool log_conf_parsed; /* Logging options already parsed */
> > > bool log_runtime; /* Daemonised, or ready in foreground */
> > >
> > > +#define LL_STRLEN (sizeof("-9223372036854775808"))
> > > +#define LOGTIME_STRLEN (LL_STRLEN + 5)
> > > +
> > > /**
> > > - * logtime_fmt_and_arg() - Build format and arguments to print relative log time
> > > - * @x: Current timestamp
> > > + * logtime_fmt() - Format timestamp into a string for the log
> > > + * @buf: Buffer into which to format the time
> > > + * @size: Size of @buf
> > > + * @ts: Time to format
> > > + *
> > > + * Return: number of characters written to @buf (excluding \0)
> > > */
> > > -#define logtime_fmt_and_arg(x) \
> > > - "%lli.%04lli", \
> > > - (timespec_diff_us((x), &log_start) / 1000000LL), \
> > > - (timespec_diff_us((x), &log_start) / 100LL)
> > > +int logtime_fmt(char *buf, size_t size, const struct timespec *ts)
> >
> > Shouldn't this be static?
>
> Yes, yes it should.
>
> > The rest of the series looks good to me, so I can also fix this up
> > on merge, as you prefer.
>
> If you can fix on merge that would be great.
Done. Series applied.
--
Stefano
next prev parent reply other threads:[~2024-08-07 8:17 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-06 6:18 [PATCH v2 0/4] Fix several small errors in log time handling David Gibson
2024-08-06 6:18 ` [PATCH v2 1/4] util: Some corrections for timespec_diff_us David Gibson
2024-08-06 6:18 ` [PATCH v2 2/4] log: Correct formatting of timestamps David Gibson
2024-08-06 19:08 ` Stefano Brivio
2024-08-07 1:06 ` David Gibson
2024-08-07 8:17 ` Stefano Brivio [this message]
2024-08-06 6:18 ` [PATCH v2 3/4] log: Handle errors from clock_gettime() David Gibson
2024-08-06 6:18 ` [PATCH v2 4/4] log: Avoid duplicate calls to logtime() David Gibson
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=20240807101746.35d08f0c@elisabeth \
--to=sbrivio@redhat.com \
--cc=david@gibson.dropbear.id.au \
--cc=passt-dev@passt.top \
/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.
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).