From 47814fab7165ba80c2d361ad1d51e800fb40d053 Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Wed, 15 Nov 2023 07:30:21 +0400 Subject: [PATCH] Remove COGL_TRACE_BEGIN in favor of BEGIN_SCOPED Scoped traces are less error prone, and they can still be ended prematurely if needed (this commit makes that work). The only case this doesn't support is starting a trace inside a scope but ending outside, but this is pretty unusual, plus we have anchored traces for a limited variation of that. Part-of: --- clutter/clutter/clutter-frame-clock.c | 6 +++--- cogl/cogl/cogl-trace.h | 19 ++++++++----------- src/backends/native/meta-seat-impl.c | 4 ++-- src/core/display.c | 8 ++++---- src/core/stack-tracker.c | 16 ++++++++-------- src/x11/events.c | 5 ++--- src/x11/meta-sync-counter.c | 13 +++++-------- 7 files changed, 32 insertions(+), 39 deletions(-) diff --git a/clutter/clutter/clutter-frame-clock.c b/clutter/clutter/clutter-frame-clock.c index a4dc1eedc..dd64ebb06 100644 --- a/clutter/clutter/clutter-frame-clock.c +++ b/clutter/clutter/clutter-frame-clock.c @@ -766,18 +766,18 @@ clutter_frame_clock_dispatch (ClutterFrameClock *frame_clock, frame->target_presentation_time_us = frame_clock->next_presentation_time_us; frame->min_render_time_allowed_us = frame_clock->min_render_time_allowed_us; - COGL_TRACE_BEGIN (ClutterFrameClockEvents, "Frame Clock (before frame)"); + COGL_TRACE_BEGIN_SCOPED (ClutterFrameClockEvents, "Frame Clock (before frame)"); if (iface->before_frame) iface->before_frame (frame_clock, frame, frame_clock->listener.user_data); COGL_TRACE_END (ClutterFrameClockEvents); - COGL_TRACE_BEGIN (ClutterFrameClockTimelines, "Frame Clock (timelines)"); + COGL_TRACE_BEGIN_SCOPED (ClutterFrameClockTimelines, "Frame Clock (timelines)"); if (frame_clock->is_next_presentation_time_valid) time_us = frame_clock->next_presentation_time_us; advance_timelines (frame_clock, time_us); COGL_TRACE_END (ClutterFrameClockTimelines); - COGL_TRACE_BEGIN (ClutterFrameClockFrame, "Frame Clock (frame)"); + COGL_TRACE_BEGIN_SCOPED (ClutterFrameClockFrame, "Frame Clock (frame)"); result = iface->frame (frame_clock, frame, frame_clock->listener.user_data); COGL_TRACE_END (ClutterFrameClockFrame); diff --git a/cogl/cogl/cogl-trace.h b/cogl/cogl/cogl-trace.h index 49d6121c2..a8376904c 100644 --- a/cogl/cogl/cogl-trace.h +++ b/cogl/cogl/cogl-trace.h @@ -102,15 +102,6 @@ cogl_is_tracing_enabled (void) return !!g_private_get (&cogl_trace_thread_data); } -#define COGL_TRACE_BEGIN(Name, name) \ - CoglTraceHead CoglTrace##Name = { 0 }; \ - if (cogl_is_tracing_enabled ()) \ - cogl_trace_begin (&CoglTrace##Name, name); \ - -#define COGL_TRACE_END(Name)\ - if (cogl_is_tracing_enabled ()) \ - cogl_trace_end (&CoglTrace##Name); - #define COGL_TRACE_BEGIN_SCOPED(Name, name) \ CoglTraceHead CoglTrace##Name = { 0 }; \ __attribute__((cleanup (cogl_auto_trace_end_helper))) \ @@ -121,6 +112,13 @@ cogl_is_tracing_enabled (void) ScopedCoglTrace##Name = &CoglTrace##Name; \ } +#define COGL_TRACE_END(Name)\ + if (cogl_is_tracing_enabled ()) \ + { \ + cogl_trace_end (&CoglTrace##Name); \ + ScopedCoglTrace##Name = NULL; \ + } + #define COGL_TRACE_DESCRIBE(Name, description)\ if (cogl_is_tracing_enabled ()) \ cogl_trace_describe (&CoglTrace##Name, description); @@ -141,9 +139,8 @@ cogl_is_tracing_enabled (void) #include -#define COGL_TRACE_BEGIN(Name, name) (void) 0 -#define COGL_TRACE_END(Name) (void) 0 #define COGL_TRACE_BEGIN_SCOPED(Name, name) (void) 0 +#define COGL_TRACE_END(Name) (void) 0 #define COGL_TRACE_DESCRIBE(Name, description) (void) 0 #define COGL_TRACE_SCOPED_ANCHOR(Name) (void) 0 #define COGL_TRACE_BEGIN_ANCHORED(Name, name) (void) 0 diff --git a/src/backends/native/meta-seat-impl.c b/src/backends/native/meta-seat-impl.c index 4ce3a0c4e..d9eeb3fc8 100644 --- a/src/backends/native/meta-seat-impl.c +++ b/src/backends/native/meta-seat-impl.c @@ -243,8 +243,8 @@ meta_seat_impl_clear_repeat_source (MetaSeatImpl *seat_impl) static void dispatch_libinput (MetaSeatImpl *seat_impl) { - COGL_TRACE_BEGIN (MetaSeatImplDispatchLibinput, - "MetaSeatImpl (dispatch libinput)"); + COGL_TRACE_BEGIN_SCOPED (MetaSeatImplDispatchLibinput, + "MetaSeatImpl (dispatch libinput)"); libinput_dispatch (seat_impl->libinput); COGL_TRACE_END (MetaSeatImplDispatchLibinput); diff --git a/src/core/display.c b/src/core/display.c index e9c5388e7..ae41f3bd6 100644 --- a/src/core/display.c +++ b/src/core/display.c @@ -3641,18 +3641,18 @@ update_window_visibilities (MetaDisplay *display, should_show = g_list_sort (should_show, window_stack_cmp); should_show = g_list_reverse (should_show); - COGL_TRACE_BEGIN (MetaDisplayShowUnplacedWindows, - "Display: Show unplaced windows"); + COGL_TRACE_BEGIN_SCOPED (MetaDisplayShowUnplacedWindows, + "Display: Show unplaced windows"); g_list_foreach (unplaced, (GFunc) meta_window_update_visibility, NULL); COGL_TRACE_END (MetaDisplayShowUnplacedWindows); meta_stack_freeze (display->stack); - COGL_TRACE_BEGIN (MetaDisplayShowWindows, "Display: Show windows"); + COGL_TRACE_BEGIN_SCOPED (MetaDisplayShowWindows, "Display: Show windows"); g_list_foreach (should_show, (GFunc) meta_window_update_visibility, NULL); COGL_TRACE_END (MetaDisplayShowWindows); - COGL_TRACE_BEGIN (MetaDisplayHideWindows, "Display: Hide windows"); + COGL_TRACE_BEGIN_SCOPED (MetaDisplayHideWindows, "Display: Hide windows"); g_list_foreach (should_hide, (GFunc) meta_window_update_visibility, NULL); COGL_TRACE_END (MetaDisplayHideWindows); diff --git a/src/core/stack-tracker.c b/src/core/stack-tracker.c index bc109381b..e9e09c0f0 100644 --- a/src/core/stack-tracker.c +++ b/src/core/stack-tracker.c @@ -1289,8 +1289,8 @@ meta_stack_tracker_restack_managed (MetaStackTracker *tracker, if (n_managed == 0) return; - COGL_TRACE_BEGIN (StackTrackerRestackManagedGet, - "StackTracker: Restack Managed (get)"); + COGL_TRACE_BEGIN_SCOPED (StackTrackerRestackManagedGet, + "StackTracker: Restack Managed (get)"); meta_stack_tracker_get_stack (tracker, &windows, &n_windows); /* If the top window has to be restacked, we don't want to move it to the very @@ -1309,8 +1309,8 @@ meta_stack_tracker_restack_managed (MetaStackTracker *tracker, g_assert (old_pos >= 0); COGL_TRACE_END (StackTrackerRestackManagedGet); - COGL_TRACE_BEGIN (StackTrackerRestackManagedRaise, - "StackTracker: Restack Managed (raise)"); + COGL_TRACE_BEGIN_SCOPED (StackTrackerRestackManagedRaise, + "StackTracker: Restack Managed (raise)"); new_pos = n_managed - 1; if (managed[new_pos] != windows[old_pos]) { @@ -1324,8 +1324,8 @@ meta_stack_tracker_restack_managed (MetaStackTracker *tracker, old_pos--; new_pos--; - COGL_TRACE_BEGIN (StackTrackerRestackManagedRestack, - "StackTracker: Restack Managed (restack)"); + COGL_TRACE_BEGIN_SCOPED (StackTrackerRestackManagedRestack, + "StackTracker: Restack Managed (restack)"); while (old_pos >= 0 && new_pos >= 0) { if (meta_stack_tracker_is_guard_window (tracker, windows[old_pos])) @@ -1354,8 +1354,8 @@ meta_stack_tracker_restack_managed (MetaStackTracker *tracker, } COGL_TRACE_END (StackTrackerRestackManagedRestack); - COGL_TRACE_BEGIN (StackTrackerRestackManagedLower, - "StackTracker: Restack Managed (lower)"); + COGL_TRACE_BEGIN_SCOPED (StackTrackerRestackManagedLower, + "StackTracker: Restack Managed (lower)"); while (new_pos > 0) { meta_stack_tracker_lower_below (tracker, managed[new_pos], managed[new_pos - 1]); diff --git a/src/x11/events.c b/src/x11/events.c index 722e5ba64..764a3cd09 100644 --- a/src/x11/events.c +++ b/src/x11/events.c @@ -1845,8 +1845,8 @@ meta_x11_display_handle_xevent (MetaX11Display *x11_display, MetaWaylandCompositor *wayland_compositor; #endif - COGL_TRACE_BEGIN (MetaX11DisplayHandleXevent, - "X11Display (handle X11 event)"); + COGL_TRACE_BEGIN_SCOPED (MetaX11DisplayHandleXevent, + "X11Display (handle X11 event)"); if (event->type == GenericEvent) XGetEventData (x11_display->xdisplay, &event->xcookie); @@ -1959,7 +1959,6 @@ meta_x11_display_handle_xevent (MetaX11Display *x11_display, COGL_TRACE_DESCRIBE (MetaX11DisplayHandleXevent, get_event_name (x11_display, event)); - COGL_TRACE_END (MetaX11DisplayHandleXevent); } diff --git a/src/x11/meta-sync-counter.c b/src/x11/meta-sync-counter.c index b7fc4245a..49a70fb21 100644 --- a/src/x11/meta-sync-counter.c +++ b/src/x11/meta-sync-counter.c @@ -283,7 +283,7 @@ meta_sync_counter_update (MetaSyncCounter *sync_counter, gboolean needs_frame_drawn = FALSE; gboolean no_delay_frame = FALSE; - COGL_TRACE_BEGIN (MetaWindowSyncRequestCounter, "X11: Sync request counter"); + COGL_TRACE_BEGIN_SCOPED (MetaWindowSyncRequestCounter, "X11: Sync request counter"); if (sync_counter->extended_sync_request_counter && new_counter_value % 2 == 0) { @@ -327,7 +327,6 @@ meta_sync_counter_update (MetaSyncCounter *sync_counter, new_counter_value, needs_frame_drawn ? "yes" : "no"); COGL_TRACE_DESCRIBE (MetaWindowSyncRequestCounter, description); - COGL_TRACE_END (MetaWindowSyncRequestCounter); } #endif } @@ -361,8 +360,8 @@ do_send_frame_drawn (MetaSyncCounter *sync_counter, int64_t now_us; XClientMessageEvent ev = { 0, }; - COGL_TRACE_BEGIN (MetaWindowActorX11FrameDrawn, - "X11: Send _NET_WM_FRAME_DRAWN"); + COGL_TRACE_BEGIN_SCOPED (MetaWindowActorX11FrameDrawn, + "X11: Send _NET_WM_FRAME_DRAWN"); now_us = g_get_monotonic_time (); frame->frame_drawn_time = @@ -395,7 +394,6 @@ do_send_frame_drawn (MetaSyncCounter *sync_counter, frame->sync_request_serial); COGL_TRACE_DESCRIBE (MetaWindowActorX11FrameDrawn, description); - COGL_TRACE_END (MetaWindowActorX11FrameDrawn); } #endif } @@ -411,8 +409,8 @@ do_send_frame_timings (MetaSyncCounter *sync_counter, Display *xdisplay = meta_x11_display_get_xdisplay (display->x11_display); XClientMessageEvent ev = { 0, }; - COGL_TRACE_BEGIN (MetaWindowActorX11FrameTimings, - "X11: Send _NET_WM_FRAME_TIMINGS"); + COGL_TRACE_BEGIN_SCOPED (MetaWindowActorX11FrameTimings, + "X11: Send _NET_WM_FRAME_TIMINGS"); ev.type = ClientMessage; ev.window = sync_counter->xwindow; @@ -458,7 +456,6 @@ do_send_frame_timings (MetaSyncCounter *sync_counter, frame->sync_request_serial, presentation_time); COGL_TRACE_DESCRIBE (MetaWindowActorX11FrameTimings, description); - COGL_TRACE_END (MetaWindowActorX11FrameTimings); } #endif }