From: marcandre.lureau@redhat.com
To: qemu-devel@nongnu.org
Cc: "Kevin Wolf" <kwolf@redhat.com>, "Marek Vasut" <marex@denx.de>,
"Thomas Huth" <thuth@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
qemu-block@nongnu.org, "David Hildenbrand" <david@redhat.com>,
"Laurent Vivier" <lvivier@redhat.com>,
"Michael Roth" <michael.roth@amd.com>,
"Chris Wulff" <crwulff@gmail.com>,
"Markus Armbruster" <armbru@redhat.com>,
"Konstantin Kostiuk" <kkostiuk@redhat.com>,
"Hanna Reitz" <hreitz@redhat.com>,
qemu-ppc@nongnu.org,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Stefan Weil" <sw@weilnetz.de>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Laurent Vivier" <laurent@vivier.eu>
Subject: [PATCH v2 2/5] qtest: replace gettimeofday with GTimer
Date: Sat, 5 Mar 2022 01:16:15 +0400 [thread overview]
Message-ID: <20220304211618.3715999-3-marcandre.lureau@redhat.com> (raw)
In-Reply-To: <20220304211618.3715999-1-marcandre.lureau@redhat.com>
From: Marc-André Lureau <marcandre.lureau@redhat.com>
glib provides a convenience helper to measure elapsed time. It isn't
subject to wall-clock time changes.
Note that this changes the initial OPENED time, which used to print the
current time.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
---
softmmu/qtest.c | 39 ++++++++++-----------------------------
1 file changed, 10 insertions(+), 29 deletions(-)
diff --git a/softmmu/qtest.c b/softmmu/qtest.c
index 8b7cb6aa8e46..b2bb7777d17d 100644
--- a/softmmu/qtest.c
+++ b/softmmu/qtest.c
@@ -58,12 +58,12 @@ static FILE *qtest_log_fp;
static QTest *qtest;
static GString *inbuf;
static int irq_levels[MAX_IRQ];
-static qemu_timeval start_time;
+static GTimer *timer;
static bool qtest_opened;
static void (*qtest_server_send)(void*, const char*);
static void *qtest_server_send_opaque;
-#define FMT_timeval "%ld.%06ld"
+#define FMT_timeval "%.06f"
/**
* DOC: QTest Protocol
@@ -264,28 +264,13 @@ static int hex2nib(char ch)
}
}
-static void qtest_get_time(qemu_timeval *tv)
-{
- qemu_gettimeofday(tv);
- tv->tv_sec -= start_time.tv_sec;
- tv->tv_usec -= start_time.tv_usec;
- if (tv->tv_usec < 0) {
- tv->tv_usec += 1000000;
- tv->tv_sec -= 1;
- }
-}
-
static void qtest_send_prefix(CharBackend *chr)
{
- qemu_timeval tv;
-
if (!qtest_log_fp || !qtest_opened) {
return;
}
- qtest_get_time(&tv);
- fprintf(qtest_log_fp, "[S +" FMT_timeval "] ",
- (long) tv.tv_sec, (long) tv.tv_usec);
+ fprintf(qtest_log_fp, "[S +" FMT_timeval "] ", g_timer_elapsed(timer, NULL));
}
static void GCC_FMT_ATTR(1, 2) qtest_log_send(const char *fmt, ...)
@@ -386,12 +371,9 @@ static void qtest_process_command(CharBackend *chr, gchar **words)
command = words[0];
if (qtest_log_fp) {
- qemu_timeval tv;
int i;
- qtest_get_time(&tv);
- fprintf(qtest_log_fp, "[R +" FMT_timeval "]",
- (long) tv.tv_sec, (long) tv.tv_usec);
+ fprintf(qtest_log_fp, "[R +" FMT_timeval "]", g_timer_elapsed(timer, NULL));
for (i = 0; words[i]; i++) {
fprintf(qtest_log_fp, " %s", words[i]);
}
@@ -846,21 +828,20 @@ static void qtest_event(void *opaque, QEMUChrEvent event)
for (i = 0; i < ARRAY_SIZE(irq_levels); i++) {
irq_levels[i] = 0;
}
- qemu_gettimeofday(&start_time);
+
+ g_clear_pointer(&timer, g_timer_destroy);
+ timer = g_timer_new();
qtest_opened = true;
if (qtest_log_fp) {
- fprintf(qtest_log_fp, "[I " FMT_timeval "] OPENED\n",
- (long) start_time.tv_sec, (long) start_time.tv_usec);
+ fprintf(qtest_log_fp, "[I " FMT_timeval "] OPENED\n", g_timer_elapsed(timer, NULL));
}
break;
case CHR_EVENT_CLOSED:
qtest_opened = false;
if (qtest_log_fp) {
- qemu_timeval tv;
- qtest_get_time(&tv);
- fprintf(qtest_log_fp, "[I +" FMT_timeval "] CLOSED\n",
- (long) tv.tv_sec, (long) tv.tv_usec);
+ fprintf(qtest_log_fp, "[I +" FMT_timeval "] CLOSED\n", g_timer_elapsed(timer, NULL));
}
+ g_clear_pointer(&timer, g_timer_destroy);
break;
default:
break;
--
2.35.1.273.ge6ebfd0e8cbb
next prev parent reply other threads:[~2022-03-04 21:21 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-04 21:16 [PATCH v2 0/5] Remove qemu_gettimeofday() marcandre.lureau
2022-03-04 21:16 ` [PATCH v2 1/5] m68k/nios2-semi: fix gettimeofday() result check marcandre.lureau
2022-03-04 21:16 ` marcandre.lureau [this message]
2022-03-04 21:16 ` [PATCH v2 3/5] qga: replace qemu_gettimeofday() with g_get_real_time() marcandre.lureau
2022-03-04 21:16 ` [PATCH v2 4/5] Replace " marcandre.lureau
2022-03-05 19:17 ` Marc-André Lureau
2022-03-07 10:02 ` Laurent Vivier
2022-03-07 10:35 ` Marc-André Lureau
2022-03-07 11:36 ` Laurent Vivier
2022-03-04 21:16 ` [PATCH v2 5/5] oslib: drop qemu_gettimeofday() marcandre.lureau
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=20220304211618.3715999-3-marcandre.lureau@redhat.com \
--to=marcandre.lureau@redhat.com \
--cc=armbru@redhat.com \
--cc=crwulff@gmail.com \
--cc=david@redhat.com \
--cc=hreitz@redhat.com \
--cc=kkostiuk@redhat.com \
--cc=kwolf@redhat.com \
--cc=laurent@vivier.eu \
--cc=lvivier@redhat.com \
--cc=marex@denx.de \
--cc=michael.roth@amd.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=sw@weilnetz.de \
--cc=thuth@redhat.com \
/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;
as well as URLs for NNTP newsgroup(s).