From e7a210d963d52310c354fa6345f0e8c17b8a73bd Mon Sep 17 00:00:00 2001 From: Daniel van Vugt Date: Tue, 20 Jun 2023 16:29:24 +0800 Subject: [PATCH] clutter/frame-clock: Add dispatch jitter to frame timing measurements Dispatch jitter is how much the dispatch interval has changed between frames. It's a measure of sampling smoothness for events that are occurring at a higher rate than the screen is refreshing: * Mouse movement * Clients rendering at swap interval zero * Keyframe animation position Zero jitter is ideal but will practically never happen, and a jitter value of several thousand microseconds will be visible to the naked eye as stutter even if you're maintaining a perfect frame rate. To make the numbers easier to interpret we also log the jitter as a percentage of the refresh interval. Part-of: --- clutter/clutter/clutter-frame-clock.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/clutter/clutter/clutter-frame-clock.c b/clutter/clutter/clutter-frame-clock.c index 0ddda800d..2fb20f689 100644 --- a/clutter/clutter/clutter-frame-clock.c +++ b/clutter/clutter/clutter-frame-clock.c @@ -116,6 +116,8 @@ struct _ClutterFrameClock int n_missed_frames; int64_t missed_frame_report_time_us; + + int64_t last_dispatch_interval_us; }; G_DEFINE_TYPE (ClutterFrameClock, clutter_frame_clock, @@ -767,6 +769,19 @@ clutter_frame_clock_dispatch (ClutterFrameClock *frame_clock, MAX (frame_clock->shortterm.max_dispatch_lateness_us, frame_clock->last_dispatch_lateness_us); + if (G_UNLIKELY (CLUTTER_HAS_DEBUG (FRAME_TIMINGS))) + { + int64_t dispatch_interval_us, jitter_us; + + dispatch_interval_us = time_us - frame_clock->last_dispatch_time_us; + jitter_us = llabs (dispatch_interval_us - + frame_clock->last_dispatch_interval_us); + frame_clock->last_dispatch_interval_us = dispatch_interval_us; + CLUTTER_NOTE (FRAME_TIMINGS, "dispatch jitter %5ldµs (%3ld%%)", + jitter_us, + jitter_us * 100 / frame_clock->refresh_interval_us); + } + frame_clock->last_dispatch_time_us = time_us; g_source_set_ready_time (frame_clock->source, -1);