From ffb88bffc508d95c043bc68872043a56a51fd37a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Tue, 2 Feb 2021 23:57:23 +0100 Subject: [PATCH] x11/window: Add tracing for X11 synchronization events Add tracing and data gathering for processing related to _NET_WM_FRAME_DRAWN and _NET_WM_FRAME_TIMINGS, used by some X11 clients for synchronized rendering. Part-of: --- src/compositor/meta-window-actor-x11.c | 34 ++++++++++++++++++++++++++ src/x11/window-x11.c | 15 ++++++++++++ 2 files changed, 49 insertions(+) diff --git a/src/compositor/meta-window-actor-x11.c b/src/compositor/meta-window-actor-x11.c index e18b1b28b..44cf5a67c 100644 --- a/src/compositor/meta-window-actor-x11.c +++ b/src/compositor/meta-window-actor-x11.c @@ -167,6 +167,9 @@ do_send_frame_drawn (MetaWindowActorX11 *actor_x11, XClientMessageEvent ev = { 0, }; + COGL_TRACE_BEGIN (MetaWindowActorX11FrameDrawn, + "X11: Send _NET_WM_FRAME_DRAWN"); + now_us = g_get_monotonic_time (); frame->frame_drawn_time = meta_compositor_monotonic_to_high_res_xserver_time (display->compositor, @@ -186,6 +189,19 @@ do_send_frame_drawn (MetaWindowActorX11 *actor_x11, XSendEvent (xdisplay, ev.window, False, 0, (XEvent *) &ev); XFlush (xdisplay); meta_x11_error_trap_pop (display->x11_display); + + if (G_UNLIKELY (cogl_is_tracing_enabled ())) + { + g_autofree char *description = NULL; + + description = g_strdup_printf ("frame drawn time: %" G_GINT64_FORMAT ", " + "sync request serial: %" G_GINT64_FORMAT, + frame->frame_drawn_time, + frame->sync_request_serial); + COGL_TRACE_DESCRIBE (MetaWindowActorX11FrameDrawn, + description); + COGL_TRACE_END (MetaWindowActorX11FrameDrawn); + } } static void @@ -201,6 +217,9 @@ do_send_frame_timings (MetaWindowActorX11 *actor_x11, XClientMessageEvent ev = { 0, }; + COGL_TRACE_BEGIN (MetaWindowActorX11FrameTimings, + "X11: Send _NET_WM_FRAME_TIMINGS"); + ev.type = ClientMessage; ev.window = meta_window_get_xwindow (window); ev.message_type = display->x11_display->atom__NET_WM_FRAME_TIMINGS; @@ -231,6 +250,21 @@ do_send_frame_timings (MetaWindowActorX11 *actor_x11, XSendEvent (xdisplay, ev.window, False, 0, (XEvent *) &ev); XFlush (xdisplay); meta_x11_error_trap_pop (display->x11_display); + + if (G_UNLIKELY (cogl_is_tracing_enabled ())) + { + g_autofree char *description = NULL; + + description = + g_strdup_printf ("refresh interval: %d, " + "presentation time: %" G_GINT64_FORMAT ", " + "sync request serial: %" G_GINT64_FORMAT, + refresh_interval, + frame->sync_request_serial, + presentation_time); + COGL_TRACE_DESCRIBE (MetaWindowActorX11FrameTimings, description); + COGL_TRACE_END (MetaWindowActorX11FrameTimings); + } } static void diff --git a/src/x11/window-x11.c b/src/x11/window-x11.c index 204b49e93..9152fde52 100644 --- a/src/x11/window-x11.c +++ b/src/x11/window-x11.c @@ -4025,6 +4025,8 @@ meta_window_x11_update_sync_request_counter (MetaWindow *window, gboolean needs_frame_drawn = FALSE; gboolean no_delay_frame = FALSE; + COGL_TRACE_BEGIN (MetaWindowSyncRequestCounter, "X11: Sync request counter"); + if (window->extended_sync_request_counter && new_counter_value % 2 == 0) { needs_frame_drawn = TRUE; @@ -4071,6 +4073,19 @@ meta_window_x11_update_sync_request_counter (MetaWindow *window, if (needs_frame_drawn) meta_compositor_queue_frame_drawn (window->display->compositor, window, no_delay_frame); + + if (G_UNLIKELY (cogl_is_tracing_enabled ())) + { + g_autofree char *description = NULL; + + description = + g_strdup_printf ("sync request serial: %" G_GINT64_FORMAT ", " + "needs frame drawn: %s", + new_counter_value, + needs_frame_drawn ? "yes" : "no"); + COGL_TRACE_DESCRIBE (MetaWindowSyncRequestCounter, description); + COGL_TRACE_END (MetaWindowSyncRequestCounter); + } } Window