From: marcandre.lureau@redhat.com
To: qemu-devel@nongnu.org
Cc: "Marek Vasut" <marex@denx.de>, "Kevin Wolf" <kwolf@redhat.com>,
"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>,
"Laurent Vivier" <laurent@vivier.eu>,
"Markus Armbruster" <armbru@redhat.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Hanna Reitz" <hreitz@redhat.com>,
qemu-ppc@nongnu.org, "Stefan Weil" <sw@weilnetz.de>,
"Paolo Bonzini" <pbonzini@redhat.com>
Subject: [PATCH 2/4] qtest: replace gettimeofday with GTimer
Date: Fri, 4 Mar 2022 19:27:02 +0400 [thread overview]
Message-ID: <20220304152704.3466036-3-marcandre.lureau@redhat.com> (raw)
In-Reply-To: <20220304152704.3466036-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>
---
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 15:54 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-04 15:27 [PATCH 0/4] RFC: remove qemu_gettimeofday() marcandre.lureau
2022-03-04 15:27 ` [PATCH 1/4] m68k/nios2-semi: fix gettimeofday() result check marcandre.lureau
2022-03-04 15:45 ` Laurent Vivier
2022-03-04 20:44 ` Richard Henderson
2022-03-04 15:27 ` marcandre.lureau [this message]
2022-03-04 15:54 ` [PATCH 2/4] qtest: replace gettimeofday with GTimer Laurent Vivier
2022-03-04 15:55 ` Laurent Vivier
2022-03-04 20:50 ` Richard Henderson
2022-03-04 21:12 ` Marc-André Lureau
2022-03-04 15:27 ` [PATCH 3/4] Replace qemu_gettimeofday() with g_get_real_time() marcandre.lureau
2022-03-04 16:08 ` Laurent Vivier
2022-03-04 16:13 ` Laurent Vivier
2022-03-04 16:48 ` Marc-André Lureau
2022-03-04 20:39 ` BALATON Zoltan
2022-03-04 20:45 ` Marc-André Lureau
2022-03-04 15:27 ` [PATCH 4/4] oslib: drop qemu_gettimeofday() marcandre.lureau
2022-03-04 16:09 ` Laurent Vivier
2022-03-04 16:21 ` Stefan Weil
2022-03-04 20:58 ` Richard Henderson
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=20220304152704.3466036-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=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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.