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 2D2FA5A004E for ; Tue, 06 Aug 2024 21:08:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1722971295; 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=vRqbf1BwTt2XESS/Ui+qwt+djSt45ZBo5rM1gYHUaTs=; b=c2xuBxSmtGty4wELwRn7hC+WfADU0RW94J0CTn3EPoWfJJLdReNwZ7WfxK2/NKZTbJuPqf Ht1efDpvony7puQXbO1LjixnINa4C2OriB41UU5WysByXKxrpAmdnyysXNLqm191BI23MA NvCv0g2NMAS02XL6xbqsD1Lgx0Wcb88= Received: from mail-pj1-f70.google.com (mail-pj1-f70.google.com [209.85.216.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-643-t6CBBV3aP2Srx-stWxfufA-1; Tue, 06 Aug 2024 15:08:13 -0400 X-MC-Unique: t6CBBV3aP2Srx-stWxfufA-1 Received: by mail-pj1-f70.google.com with SMTP id 98e67ed59e1d1-2cb5ba80e77so1066401a91.1 for ; Tue, 06 Aug 2024 12:08:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722971292; x=1723576092; 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=vRqbf1BwTt2XESS/Ui+qwt+djSt45ZBo5rM1gYHUaTs=; b=IQuiI2WcO4mlpu6s/85PpRMT1Og19ncCjD1KV2LB8zMzJ6FTRBtX6nC4qkqcN6+Be5 LKmxwKEZjcclwuibMd/afcvPqW9AKxecFhHRzMN+PfjnOG8W2OQBs8Rjhbq+1+REfUxq gso6qLtWtP19z+q7nk/Si9dH+zm0M69P7LGc8t6FUgjnL6maY9dTsUXH+bNkbA+h8rOh D4reda8qblZ2KvKLEzdMT36c+K1wcm7pzseWyx+IxE6sFxVKV6AukWxkt/EScGql+qm9 qwGjQXn0OXosEUV9YqSos+/gZ+qC3Ia8WZpMxEqkkR1ztrt2UzpcB/BVPCSMLpNzy0Ty 15CA== X-Gm-Message-State: AOJu0Yz3m6Ey7JAWDWyHGxNtrQPMUgDgfrSnssZkxwBk3HPOwvM5eObb BF2ACcKfop3I5a4PUoDq3mBzq6Bpq0P168pw7gBtDJ4iivMeHihF8qgZJvoFM756kcytM8ssaS1 PZ1S4eMH+pnuXHUVb5AWzZHRtH9Hqh3mtzRFu+L9nSBbeXjq8RA== X-Received: by 2002:a17:90a:6441:b0:2c3:40b7:1f6d with SMTP id 98e67ed59e1d1-2cff913570emr19383460a91.0.1722971292184; Tue, 06 Aug 2024 12:08:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGY4ebywiefGzY0gzt9l7z/fT0c17ZFmX8I/F0Cl4UaCv/AUCh5UvRBl8hCwQxoqTnXPYTtnw== X-Received: by 2002:a17:90a:6441:b0:2c3:40b7:1f6d with SMTP id 98e67ed59e1d1-2cff913570emr19383424a91.0.1722971291616; Tue, 06 Aug 2024 12:08:11 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [176.103.220.4]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2cffb36eac6sm9504267a91.39.2024.08.06.12.08.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Aug 2024 12:08:10 -0700 (PDT) Date: Tue, 6 Aug 2024 21:08:07 +0200 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH v2 2/4] log: Correct formatting of timestamps Message-ID: <20240806210807.2672b2f7@elisabeth> In-Reply-To: <20240806061839.1950144-3-david@gibson.dropbear.id.au> References: <20240806061839.1950144-1-david@gibson.dropbear.id.au> <20240806061839.1950144-3-david@gibson.dropbear.id.au> 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: RSGSYW3PSS5SIGC36WSP3JTZA7KHDHVW X-Message-ID-Hash: RSGSYW3PSS5SIGC36WSP3JTZA7KHDHVW 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 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? The rest of the series looks good to me, so I can also fix this up on merge, as you prefer. -- Stefano