public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: Stefano Brivio <sbrivio@redhat.com>
To: passt-dev@passt.top, David Gibson <david@gibson.dropbear.id.au>
Subject: [PATCH 2/3] log: Initialise timestamp for relative log time also if we use a log file
Date: Thu, 25 Jul 2024 18:26:33 +0200	[thread overview]
Message-ID: <20240725162634.107697-3-sbrivio@redhat.com> (raw)
In-Reply-To: <20240725162634.107697-1-sbrivio@redhat.com>

...not just for debug messages. Otherwise, timestamps in the log file
are consistent but the starting point is not zero.

Do this right away as we enter main(), so that the resulting
timestamps are as closely as possible relative to when we start.

Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
---
 log.c   | 4 +---
 log.h   | 1 +
 passt.c | 2 ++
 3 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/log.c b/log.c
index 32157a8..9474bad 100644
--- a/log.c
+++ b/log.c
@@ -40,7 +40,7 @@ static size_t	log_written;		/* Currently used bytes in log file */
 static size_t	log_cut_size;		/* Bytes to cut at start on rotation */
 static char	log_header[BUFSIZ];	/* File header, written back on cuts */
 
-static struct timespec log_start;	/* Start timestamp */
+struct timespec	log_start;		/* Start timestamp */
 
 int		log_trace;		/* --trace mode enabled */
 bool		log_conf_parsed;	/* Logging options already parsed */
@@ -154,8 +154,6 @@ void __openlog(const char *ident, int option, int facility)
 {
 	(void)option;
 
-	clock_gettime(CLOCK_REALTIME, &log_start);
-
 	if (log_sock < 0) {
 		struct sockaddr_un a = { .sun_family = AF_UNIX, };
 
diff --git a/log.h b/log.h
index 51ddafa..e03199c 100644
--- a/log.h
+++ b/log.h
@@ -44,6 +44,7 @@ void logmsg_perror(int pri, const char *format, ...)
 extern int log_trace;
 extern bool log_conf_parsed;
 extern bool log_runtime;
+extern struct timespec log_start;
 
 void trace_init(int enable);
 #define trace(...)							\
diff --git a/passt.c b/passt.c
index eed74ec..72ad704 100644
--- a/passt.c
+++ b/passt.c
@@ -207,6 +207,8 @@ int main(int argc, char **argv)
 	struct timespec now;
 	struct sigaction sa;
 
+	clock_gettime(CLOCK_REALTIME, &log_start);
+
 	arch_avx2_exec(argv);
 
 	isolate_initial();
-- 
@@ -207,6 +207,8 @@ int main(int argc, char **argv)
 	struct timespec now;
 	struct sigaction sa;
 
+	clock_gettime(CLOCK_REALTIME, &log_start);
+
 	arch_avx2_exec(argv);
 
 	isolate_initial();
-- 
2.43.0


  parent reply	other threads:[~2024-07-25 16:26 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-25 16:26 [PATCH 0/3] Fixes for log timestamps Stefano Brivio
2024-07-25 16:26 ` [PATCH 1/3] log, util: Fix sub-second part in relative log time calculation Stefano Brivio
2024-07-25 23:11   ` David Gibson
2024-07-25 16:26 ` Stefano Brivio [this message]
2024-07-25 16:26 ` [PATCH 3/3] log: Fetch log times with CLOCK_MONOTONIC, not CLOCK_REALTIME Stefano Brivio
2024-07-25 23:15   ` David Gibson
2024-07-26  9:32     ` Stefano Brivio
2024-07-29  1:12       ` 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=20240725162634.107697-3-sbrivio@redhat.com \
    --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).