@samitouri / QOSamiQemu / commits / e31b29f446

audio: rework DEBUG_POLL

Use more correct GTimer, specific for each backend, with a trace event. Reviewed-by: Mark Cave-Ayland <mark.caveayland@nutanix.com> Reviewed-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>

Marc-André Lureau committed Jan 21, 2026 at 11:55 UTC e31b29f446b578120c533e9a788af1ea9993396a
4 files changed +12 -16
audio/audio-mixeng-be.c
+9 -16
@@ -24,13 +24,13 @@
24 #include "system/replay.h"
25 #include "system/runstate.h"
26 #include "trace.h"
27 +#include "trace/control.h"
28
29 #define AUDIO_CAP "audio"
30 #include "audio_int.h"
31
32 /* #define DEBUG_OUT */
33 /* #define DEBUG_CAPTURE */
33 -/* #define DEBUG_POLL */
34
35 #define SW_NAME(sw) (sw)->name ? (sw)->name : "unknown"
36
@@ -1269,22 +1269,12 @@ void audio_run(AudioMixengBackend *s, const char *msg)
1269 audio_run_in(s);
1270 audio_run_capture(s);
1271
1272 -#ifdef DEBUG_POLL
1273 - {
1274 - static double prevtime;
1275 - double currtime;
1276 - struct timeval tv;
1277 -
1278 - if (gettimeofday (&tv, NULL)) {
1279 - perror ("audio_run: gettimeofday");
1280 - return;
1281 - }
1282 -
1283 - currtime = tv.tv_sec + tv.tv_usec * 1e-6;
1284 - dolog ("Elapsed since last %s: %f\n", msg, currtime - prevtime);
1285 - prevtime = currtime;
1272 + if (trace_event_get_state(TRACE_AUDIO_RUN_POLL)) {
1273 + /* Convert seconds to microseconds for trace event */
1274 + int64_t elapsed_us = g_timer_elapsed(s->run_timer, NULL) * MICROSECONDS_PER_SECOND;
1275 + trace_audio_run_poll(msg, elapsed_us);
1276 + g_timer_start(s->run_timer);
1277 }
1287 -#endif
1278 }
1279
1280 void audio_generic_run_buffer_in(HWVoiceIn *hw)
@@ -1545,6 +1535,7 @@ static void audio_mixeng_backend_init(Object *obj)
1535 QLIST_INIT(&s->hw_head_in);
1536 QLIST_INIT(&s->cap_head);
1537 s->ts = timer_new_ns(QEMU_CLOCK_VIRTUAL, audio_timer, s);
1538 + s->run_timer = g_timer_new();
1539
1540 s->vmse = qemu_add_vm_change_state_handler(audio_vm_change_state_handler, s);
1541 assert(s->vmse != NULL);
@@ -1596,6 +1587,8 @@ static void audio_mixeng_backend_finalize(Object *obj)
1587 s->ts = NULL;
1588 }
1589
1590 + g_clear_pointer(&s->run_timer, g_timer_destroy);
1591 +
1592 if (s->vmse) {
1593 qemu_del_vm_change_state_handler(s->vmse);
1594 s->vmse = NULL;
audio/audio_int.h
+1
@@ -224,6 +224,7 @@ struct AudioMixengBackend {
224 Audiodev *dev;
225
226 QEMUTimer *ts;
227 + GTimer *run_timer;
228 QLIST_HEAD (hw_in_listhead, HWVoiceIn) hw_head_in;
229 QLIST_HEAD (hw_out_listhead, HWVoiceOut) hw_head_out;
230 QLIST_HEAD (cap_listhead, CaptureVoiceOut) cap_head;
audio/trace-events
+1
@@ -61,6 +61,7 @@ audio_timer_delayed(int interval) "interval %d ms"
61
62 # audio-mixeng-be.c
63 audio_get_avail(const char *name, size_t live, uint32_t frontend_frames) "%s: get_avail live %zu frontend frames %u"
64 +audio_run_poll(const char *msg, int64_t elapsed_us) "Elapsed since last %s: %" PRId64 " us"
65
66 # audio_template.h
67 audio_open_out(const char *name, int freq, int nchannels, int fmt) "open %s, freq %d, nchannels %d, fmt %d"
include/qemu/timer.h
+1
@@ -6,6 +6,7 @@
6 #include "qemu/host-utils.h"
7
8 #define NANOSECONDS_PER_SECOND 1000000000LL
9 +#define MICROSECONDS_PER_SECOND 1000000LL
10
11 /* timers */
12