[PATCH 34/43] audio: rework DEBUG_POLL

marcandre.lureau@redhat.com posted 43 patches 1 week, 6 days ago
Maintainers: Gerd Hoffmann <kraxel@redhat.com>, Christian Schoenebeck <qemu_oss@crudebyte.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>, Thomas Huth <huth@tuxfamily.org>, Alexandre Ratchov <alex@caoua.org>, Laurent Vivier <laurent@vivier.eu>, Manos Pitsidianakis <manos.pitsidianakis@linaro.org>, "Michael S. Tsirkin" <mst@redhat.com>, Alistair Francis <alistair@alistair23.me>, "Edgar E. Iglesias" <edgar.iglesias@gmail.com>, Peter Maydell <peter.maydell@linaro.org>
[PATCH 34/43] audio: rework DEBUG_POLL
Posted by marcandre.lureau@redhat.com 1 week, 6 days ago
From: Marc-André Lureau <marcandre.lureau@redhat.com>

Use more correct GTimer, specific for each backend, with a trace event.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 audio/audio_int.h       |  1 +
 audio/audio-mixeng-be.c | 25 +++++++++----------------
 audio/trace-events      |  1 +
 3 files changed, 11 insertions(+), 16 deletions(-)

diff --git a/audio/audio_int.h b/audio/audio_int.h
index dd5f2220d75..e0ed6af67ed 100644
--- a/audio/audio_int.h
+++ b/audio/audio_int.h
@@ -224,6 +224,7 @@ struct AudioMixengBackend {
     Audiodev *dev;
 
     QEMUTimer *ts;
+    GTimer *run_timer;
     QLIST_HEAD (hw_in_listhead, HWVoiceIn) hw_head_in;
     QLIST_HEAD (hw_out_listhead, HWVoiceOut) hw_head_out;
     QLIST_HEAD (cap_listhead, CaptureVoiceOut) cap_head;
diff --git a/audio/audio-mixeng-be.c b/audio/audio-mixeng-be.c
index 343f6ec181e..1b2c1fafa87 100644
--- a/audio/audio-mixeng-be.c
+++ b/audio/audio-mixeng-be.c
@@ -24,13 +24,13 @@
 #include "system/replay.h"
 #include "system/runstate.h"
 #include "trace.h"
+#include "trace/control.h"
 
 #define AUDIO_CAP "audio"
 #include "audio_int.h"
 
 /* #define DEBUG_OUT */
 /* #define DEBUG_CAPTURE */
-/* #define DEBUG_POLL */
 
 #define SW_NAME(sw) (sw)->name ? (sw)->name : "unknown"
 
@@ -1269,22 +1269,12 @@ void audio_run(AudioMixengBackend *s, const char *msg)
     audio_run_in(s);
     audio_run_capture(s);
 
-#ifdef DEBUG_POLL
-    {
-        static double prevtime;
-        double currtime;
-        struct timeval tv;
-
-        if (gettimeofday (&tv, NULL)) {
-            perror ("audio_run: gettimeofday");
-            return;
-        }
-
-        currtime = tv.tv_sec + tv.tv_usec * 1e-6;
-        dolog ("Elapsed since last %s: %f\n", msg, currtime - prevtime);
-        prevtime = currtime;
+    if (trace_event_get_state(TRACE_AUDIO_RUN_POLL)) {
+        /* Convert seconds to microseconds for trace event */
+        int64_t elapsed_us = g_timer_elapsed(s->run_timer, NULL) * 1000000;
+        trace_audio_run_poll(msg, elapsed_us);
+        g_timer_start(s->run_timer);
     }
-#endif
 }
 
 void audio_generic_run_buffer_in(HWVoiceIn *hw)
@@ -1545,6 +1535,7 @@ static void audio_mixeng_backend_init(Object *obj)
     QLIST_INIT(&s->hw_head_in);
     QLIST_INIT(&s->cap_head);
     s->ts = timer_new_ns(QEMU_CLOCK_VIRTUAL, audio_timer, s);
+    s->run_timer = g_timer_new();
 
     s->vmse = qemu_add_vm_change_state_handler(audio_vm_change_state_handler, s);
     assert(s->vmse != NULL);
@@ -1596,6 +1587,8 @@ static void audio_mixeng_backend_finalize(Object *obj)
         s->ts = NULL;
     }
 
+    g_clear_pointer(&s->run_timer, g_timer_destroy);
+
     if (s->vmse) {
         qemu_del_vm_change_state_handler(s->vmse);
         s->vmse = NULL;
diff --git a/audio/trace-events b/audio/trace-events
index 4749c54fc04..d66a712e871 100644
--- a/audio/trace-events
+++ b/audio/trace-events
@@ -61,6 +61,7 @@ audio_timer_delayed(int interval) "interval %d ms"
 
 # audio-mixeng-be.c
 audio_get_avail(const char *name, size_t live, uint32_t frontend_frames) "%s: get_avail live %zu frontend frames %u"
+audio_run_poll(const char *msg, int64_t elapsed_us) "Elapsed since last %s: %" PRId64 " us"
 
 # audio_template.h
 audio_open_out(const char *name, int freq, int nchannels, int fmt) "open %s, freq %d, nchannels %d, fmt %d"
-- 
2.52.0