From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTP id 6D28B5A004F for ; Wed, 07 Aug 2024 10:17:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1723018672; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MMKP5yZRfFx9eaChj2SdOO7ra4NBBiC5luRiSljTAYY=; b=ePVeViC0xiO+gDZFGtyIEBd3IxHxnmLehnFQ/esb3EPkuwGusZI9wBR24/zXDOnjyEmXER X6T5hLss2wsf09WTYaV5ZLeIUWx4nnEKsN/FmXHXl/sRjkGr0Sfit2+f46zyLnPqidTxpg TpYAWcXjTkKHbuhFBbQxjw0U7D/D6FI= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-97-qlchFQCKOziXEg-S1ehH4Q-1; Wed, 07 Aug 2024 04:17:51 -0400 X-MC-Unique: qlchFQCKOziXEg-S1ehH4Q-1 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-36841edbc32so615110f8f.3 for ; Wed, 07 Aug 2024 01:17:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723018669; x=1723623469; h=content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=MMKP5yZRfFx9eaChj2SdOO7ra4NBBiC5luRiSljTAYY=; b=DRbdfogVQQ37rbZ3/r7098BUakZG43gshxe02lDprf/5Skbww4M3Tl9E9RrgwBRhJp M0lISdP89U3oBTvHo6kCiewbfvLx6hLJ/OcUyrepCHsllNqPN7PBlzeel7GSrenHdBli Ti44oxWMctACZfluwhnt0k82nc5/stncsHH5/QQAr+5M6FS+UGqHcx0A6u41kIcNvD7N C5wxjzQwjrC1KresDEBA24EpHNHusnFzICYOuD/FN/V7quukSJ05CjI3SoHBulVx38aL c8izXui/cG/tDjVokqV6cIUZtLuwzf7DZkzAcHkn2NOw3Oo19aPs2kNkQA+EeR0tagOV ukhg== X-Gm-Message-State: AOJu0YybJrSxNa2wYcdBsUzFwtcxvGPkxQUR2tc9efRCnumgse+bSpxD 0yrKT0PXtoiKOmRpGc8xzwdLTTAj5PDCSIXZjPJX7iisbLkSS06ZcuscWZ63svjdkHEzJzWEZsE 54m0/fMX349iMA88dVCiIC7w185UxtCdLQaygI8ITlZhSalF0L6U3fbnuEA== X-Received: by 2002:adf:eb12:0:b0:368:31c7:19d3 with SMTP id ffacd0b85a97d-36bbc0c2750mr10941773f8f.9.1723018669239; Wed, 07 Aug 2024 01:17:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFLL8c2Y2uI/QqaAEQx0xzx289pEiuQuveI02YqbgMdpm9cnq9pYfx/KbHZ9DThIRJBHIQDAg== X-Received: by 2002:adf:eb12:0:b0:368:31c7:19d3 with SMTP id ffacd0b85a97d-36bbc0c2750mr10941759f8f.9.1723018668742; Wed, 07 Aug 2024 01:17:48 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [2a10:fc81:a806:d6a9::1]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-36bbcf0cc8esm15093729f8f.19.2024.08.07.01.17.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Aug 2024 01:17:48 -0700 (PDT) Date: Wed, 7 Aug 2024 10:17:46 +0200 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH v2 2/4] log: Correct formatting of timestamps Message-ID: <20240807101746.35d08f0c@elisabeth> In-Reply-To: References: <20240806061839.1950144-1-david@gibson.dropbear.id.au> <20240806061839.1950144-3-david@gibson.dropbear.id.au> <20240806210807.2672b2f7@elisabeth> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: MHYO3GXH3GKEPSNGCNAFO4BZLNEI4VF6 X-Message-ID-Hash: MHYO3GXH3GKEPSNGCNAFO4BZLNEI4VF6 X-MailFrom: sbrivio@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On Wed, 7 Aug 2024 11:06:52 +1000 David Gibson 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 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 > > > --- > > > 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