From f9802ca2a44c368b74206e75353e68181e47491b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Thu, 15 Dec 2022 12:18:52 +0100 Subject: [PATCH] clutter/frame-clock: Debug log frame drops per second if there were any Part-of: --- clutter/clutter/clutter-frame-clock.c | 35 +++++++++++++++++++++++++++ clutter/clutter/clutter-main.c | 1 + clutter/clutter/clutter-main.h | 1 + 3 files changed, 37 insertions(+) diff --git a/clutter/clutter/clutter-frame-clock.c b/clutter/clutter/clutter-frame-clock.c index 95f694eda..e5d1a44e2 100644 --- a/clutter/clutter/clutter-frame-clock.c +++ b/clutter/clutter/clutter-frame-clock.c @@ -111,6 +111,9 @@ struct _ClutterFrameClock int inhibit_count; GList *timelines; + + int n_missed_frames; + int64_t missed_frame_report_time_us; }; G_DEFINE_TYPE (ClutterFrameClock, clutter_frame_clock, @@ -240,6 +243,38 @@ clutter_frame_clock_notify_presented (ClutterFrameClock *frame_clock, COGL_TRACE_BEGIN_SCOPED (ClutterFrameClockNotifyPresented, "Frame Clock (presented)"); + if (G_UNLIKELY (CLUTTER_HAS_DEBUG (FRAME_CLOCK))) + { + int64_t now_us; + + if (frame_clock->is_next_presentation_time_valid && + frame_info->presentation_time != 0) + { + int64_t diff_us; + int n_missed_frames; + + diff_us = llabs (frame_info->presentation_time - + frame_clock->next_presentation_time_us); + n_missed_frames = + (int) roundf ((float) diff_us / + (float) frame_clock->refresh_interval_us); + + frame_clock->n_missed_frames = n_missed_frames; + } + + now_us = g_get_monotonic_time (); + if ((now_us - frame_clock->missed_frame_report_time_us) > G_USEC_PER_SEC) + { + if (frame_clock->n_missed_frames > 0) + { + CLUTTER_NOTE (FRAME_CLOCK, "Missed %d frames the last second", + frame_clock->n_missed_frames); + } + frame_clock->n_missed_frames = 0; + frame_clock->missed_frame_report_time_us = now_us; + } + } + #ifdef COGL_HAS_TRACING if (G_UNLIKELY (cogl_is_tracing_enabled ())) { diff --git a/clutter/clutter/clutter-main.c b/clutter/clutter/clutter-main.c index 837bfced9..23ca58b7a 100644 --- a/clutter/clutter/clutter-main.c +++ b/clutter/clutter/clutter-main.c @@ -117,6 +117,7 @@ static const GDebugKey clutter_debug_keys[] = { { "frame-timings", CLUTTER_DEBUG_FRAME_TIMINGS }, { "detailed-trace", CLUTTER_DEBUG_DETAILED_TRACE }, { "grabs", CLUTTER_DEBUG_GRABS }, + { "frame-clock", CLUTTER_DEBUG_FRAME_CLOCK }, }; #endif /* CLUTTER_ENABLE_DEBUG */ diff --git a/clutter/clutter/clutter-main.h b/clutter/clutter/clutter-main.h index 3315b7896..5b1ed7e8c 100644 --- a/clutter/clutter/clutter-main.h +++ b/clutter/clutter/clutter-main.h @@ -56,6 +56,7 @@ typedef enum CLUTTER_DEBUG_FRAME_TIMINGS = 1 << 17, CLUTTER_DEBUG_DETAILED_TRACE = 1 << 18, CLUTTER_DEBUG_GRABS = 1 << 19, + CLUTTER_DEBUG_FRAME_CLOCK = 1 << 20, } ClutterDebugFlag; typedef enum