diff mbox

[PATCHv1,3/4] Timers: Instrument timer_mod

Message ID 1382740234-21345-4-git-send-email-alex@alex.org.uk
State New
Headers show

Commit Message

Alex Bligh Oct. 25, 2013, 10:30 p.m. UTC
Add instrumentation for timer_mod to allow measurement of the
average time delta to expiry plus the number of short delta
periods. This is only run when logging to a file because
getting the clock value may add appreciable expense.

Signed-off-by: Alex Bligh <alex@alex.org.uk>
---
 qemu-timer.c |   17 +++++++++++++++++
 1 file changed, 17 insertions(+)
diff mbox

Patch

diff --git a/qemu-timer.c b/qemu-timer.c
index 84a8932..16eaa1f 100644
--- a/qemu-timer.c
+++ b/qemu-timer.c
@@ -376,6 +376,23 @@  static bool timer_mod_ns_locked(QEMUTimerList *timer_list,
     ts->next = *pt;
     *pt = ts;
 
+    if (timer_debug_log) {
+        int64_t delta;
+
+        delta = ts->expire_time -
+            qemu_clock_get_ns(ts->timer_list->clock->type);
+        if (delta <= 0) {
+            delta = 0;
+        }
+
+        ts->tot_deltas += delta;
+        ts->num_deltas++;
+
+        if (delta < SCALE_US) {
+            ts->num_short++;
+        }
+    }
+
     return pt == &timer_list->active_timers;
 }