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: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3396>
This commit is contained in:
Ivan Molodetskikh 2023-11-15 07:30:21 +04:00
parent 371d28a766
commit 47814fab71
7 changed files with 32 additions and 39 deletions

View File

@ -766,18 +766,18 @@ clutter_frame_clock_dispatch (ClutterFrameClock *frame_clock,
frame->target_presentation_time_us = frame_clock->next_presentation_time_us; frame->target_presentation_time_us = frame_clock->next_presentation_time_us;
frame->min_render_time_allowed_us = frame_clock->min_render_time_allowed_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) if (iface->before_frame)
iface->before_frame (frame_clock, frame, frame_clock->listener.user_data); iface->before_frame (frame_clock, frame, frame_clock->listener.user_data);
COGL_TRACE_END (ClutterFrameClockEvents); 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) if (frame_clock->is_next_presentation_time_valid)
time_us = frame_clock->next_presentation_time_us; time_us = frame_clock->next_presentation_time_us;
advance_timelines (frame_clock, time_us); advance_timelines (frame_clock, time_us);
COGL_TRACE_END (ClutterFrameClockTimelines); 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); result = iface->frame (frame_clock, frame, frame_clock->listener.user_data);
COGL_TRACE_END (ClutterFrameClockFrame); COGL_TRACE_END (ClutterFrameClockFrame);

View File

@ -102,15 +102,6 @@ cogl_is_tracing_enabled (void)
return !!g_private_get (&cogl_trace_thread_data); 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) \ #define COGL_TRACE_BEGIN_SCOPED(Name, name) \
CoglTraceHead CoglTrace##Name = { 0 }; \ CoglTraceHead CoglTrace##Name = { 0 }; \
__attribute__((cleanup (cogl_auto_trace_end_helper))) \ __attribute__((cleanup (cogl_auto_trace_end_helper))) \
@ -121,6 +112,13 @@ cogl_is_tracing_enabled (void)
ScopedCoglTrace##Name = &CoglTrace##Name; \ 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)\ #define COGL_TRACE_DESCRIBE(Name, description)\
if (cogl_is_tracing_enabled ()) \ if (cogl_is_tracing_enabled ()) \
cogl_trace_describe (&CoglTrace##Name, description); cogl_trace_describe (&CoglTrace##Name, description);
@ -141,9 +139,8 @@ cogl_is_tracing_enabled (void)
#include <stdio.h> #include <stdio.h>
#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_BEGIN_SCOPED(Name, name) (void) 0
#define COGL_TRACE_END(Name) (void) 0
#define COGL_TRACE_DESCRIBE(Name, description) (void) 0 #define COGL_TRACE_DESCRIBE(Name, description) (void) 0
#define COGL_TRACE_SCOPED_ANCHOR(Name) (void) 0 #define COGL_TRACE_SCOPED_ANCHOR(Name) (void) 0
#define COGL_TRACE_BEGIN_ANCHORED(Name, name) (void) 0 #define COGL_TRACE_BEGIN_ANCHORED(Name, name) (void) 0

View File

@ -243,8 +243,8 @@ meta_seat_impl_clear_repeat_source (MetaSeatImpl *seat_impl)
static void static void
dispatch_libinput (MetaSeatImpl *seat_impl) dispatch_libinput (MetaSeatImpl *seat_impl)
{ {
COGL_TRACE_BEGIN (MetaSeatImplDispatchLibinput, COGL_TRACE_BEGIN_SCOPED (MetaSeatImplDispatchLibinput,
"MetaSeatImpl (dispatch libinput)"); "MetaSeatImpl (dispatch libinput)");
libinput_dispatch (seat_impl->libinput); libinput_dispatch (seat_impl->libinput);
COGL_TRACE_END (MetaSeatImplDispatchLibinput); COGL_TRACE_END (MetaSeatImplDispatchLibinput);

View File

@ -3641,18 +3641,18 @@ update_window_visibilities (MetaDisplay *display,
should_show = g_list_sort (should_show, window_stack_cmp); should_show = g_list_sort (should_show, window_stack_cmp);
should_show = g_list_reverse (should_show); should_show = g_list_reverse (should_show);
COGL_TRACE_BEGIN (MetaDisplayShowUnplacedWindows, COGL_TRACE_BEGIN_SCOPED (MetaDisplayShowUnplacedWindows,
"Display: Show unplaced windows"); "Display: Show unplaced windows");
g_list_foreach (unplaced, (GFunc) meta_window_update_visibility, NULL); g_list_foreach (unplaced, (GFunc) meta_window_update_visibility, NULL);
COGL_TRACE_END (MetaDisplayShowUnplacedWindows); COGL_TRACE_END (MetaDisplayShowUnplacedWindows);
meta_stack_freeze (display->stack); 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); g_list_foreach (should_show, (GFunc) meta_window_update_visibility, NULL);
COGL_TRACE_END (MetaDisplayShowWindows); 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); g_list_foreach (should_hide, (GFunc) meta_window_update_visibility, NULL);
COGL_TRACE_END (MetaDisplayHideWindows); COGL_TRACE_END (MetaDisplayHideWindows);

View File

@ -1289,8 +1289,8 @@ meta_stack_tracker_restack_managed (MetaStackTracker *tracker,
if (n_managed == 0) if (n_managed == 0)
return; return;
COGL_TRACE_BEGIN (StackTrackerRestackManagedGet, COGL_TRACE_BEGIN_SCOPED (StackTrackerRestackManagedGet,
"StackTracker: Restack Managed (get)"); "StackTracker: Restack Managed (get)");
meta_stack_tracker_get_stack (tracker, &windows, &n_windows); 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 /* 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); g_assert (old_pos >= 0);
COGL_TRACE_END (StackTrackerRestackManagedGet); COGL_TRACE_END (StackTrackerRestackManagedGet);
COGL_TRACE_BEGIN (StackTrackerRestackManagedRaise, COGL_TRACE_BEGIN_SCOPED (StackTrackerRestackManagedRaise,
"StackTracker: Restack Managed (raise)"); "StackTracker: Restack Managed (raise)");
new_pos = n_managed - 1; new_pos = n_managed - 1;
if (managed[new_pos] != windows[old_pos]) if (managed[new_pos] != windows[old_pos])
{ {
@ -1324,8 +1324,8 @@ meta_stack_tracker_restack_managed (MetaStackTracker *tracker,
old_pos--; old_pos--;
new_pos--; new_pos--;
COGL_TRACE_BEGIN (StackTrackerRestackManagedRestack, COGL_TRACE_BEGIN_SCOPED (StackTrackerRestackManagedRestack,
"StackTracker: Restack Managed (restack)"); "StackTracker: Restack Managed (restack)");
while (old_pos >= 0 && new_pos >= 0) while (old_pos >= 0 && new_pos >= 0)
{ {
if (meta_stack_tracker_is_guard_window (tracker, windows[old_pos])) 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_END (StackTrackerRestackManagedRestack);
COGL_TRACE_BEGIN (StackTrackerRestackManagedLower, COGL_TRACE_BEGIN_SCOPED (StackTrackerRestackManagedLower,
"StackTracker: Restack Managed (lower)"); "StackTracker: Restack Managed (lower)");
while (new_pos > 0) while (new_pos > 0)
{ {
meta_stack_tracker_lower_below (tracker, managed[new_pos], managed[new_pos - 1]); meta_stack_tracker_lower_below (tracker, managed[new_pos], managed[new_pos - 1]);

View File

@ -1845,8 +1845,8 @@ meta_x11_display_handle_xevent (MetaX11Display *x11_display,
MetaWaylandCompositor *wayland_compositor; MetaWaylandCompositor *wayland_compositor;
#endif #endif
COGL_TRACE_BEGIN (MetaX11DisplayHandleXevent, COGL_TRACE_BEGIN_SCOPED (MetaX11DisplayHandleXevent,
"X11Display (handle X11 event)"); "X11Display (handle X11 event)");
if (event->type == GenericEvent) if (event->type == GenericEvent)
XGetEventData (x11_display->xdisplay, &event->xcookie); XGetEventData (x11_display->xdisplay, &event->xcookie);
@ -1959,7 +1959,6 @@ meta_x11_display_handle_xevent (MetaX11Display *x11_display,
COGL_TRACE_DESCRIBE (MetaX11DisplayHandleXevent, COGL_TRACE_DESCRIBE (MetaX11DisplayHandleXevent,
get_event_name (x11_display, event)); get_event_name (x11_display, event));
COGL_TRACE_END (MetaX11DisplayHandleXevent);
} }

View File

@ -283,7 +283,7 @@ meta_sync_counter_update (MetaSyncCounter *sync_counter,
gboolean needs_frame_drawn = FALSE; gboolean needs_frame_drawn = FALSE;
gboolean no_delay_frame = 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) 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, new_counter_value,
needs_frame_drawn ? "yes" : "no"); needs_frame_drawn ? "yes" : "no");
COGL_TRACE_DESCRIBE (MetaWindowSyncRequestCounter, description); COGL_TRACE_DESCRIBE (MetaWindowSyncRequestCounter, description);
COGL_TRACE_END (MetaWindowSyncRequestCounter);
} }
#endif #endif
} }
@ -361,8 +360,8 @@ do_send_frame_drawn (MetaSyncCounter *sync_counter,
int64_t now_us; int64_t now_us;
XClientMessageEvent ev = { 0, }; XClientMessageEvent ev = { 0, };
COGL_TRACE_BEGIN (MetaWindowActorX11FrameDrawn, COGL_TRACE_BEGIN_SCOPED (MetaWindowActorX11FrameDrawn,
"X11: Send _NET_WM_FRAME_DRAWN"); "X11: Send _NET_WM_FRAME_DRAWN");
now_us = g_get_monotonic_time (); now_us = g_get_monotonic_time ();
frame->frame_drawn_time = frame->frame_drawn_time =
@ -395,7 +394,6 @@ do_send_frame_drawn (MetaSyncCounter *sync_counter,
frame->sync_request_serial); frame->sync_request_serial);
COGL_TRACE_DESCRIBE (MetaWindowActorX11FrameDrawn, COGL_TRACE_DESCRIBE (MetaWindowActorX11FrameDrawn,
description); description);
COGL_TRACE_END (MetaWindowActorX11FrameDrawn);
} }
#endif #endif
} }
@ -411,8 +409,8 @@ do_send_frame_timings (MetaSyncCounter *sync_counter,
Display *xdisplay = meta_x11_display_get_xdisplay (display->x11_display); Display *xdisplay = meta_x11_display_get_xdisplay (display->x11_display);
XClientMessageEvent ev = { 0, }; XClientMessageEvent ev = { 0, };
COGL_TRACE_BEGIN (MetaWindowActorX11FrameTimings, COGL_TRACE_BEGIN_SCOPED (MetaWindowActorX11FrameTimings,
"X11: Send _NET_WM_FRAME_TIMINGS"); "X11: Send _NET_WM_FRAME_TIMINGS");
ev.type = ClientMessage; ev.type = ClientMessage;
ev.window = sync_counter->xwindow; ev.window = sync_counter->xwindow;
@ -458,7 +456,6 @@ do_send_frame_timings (MetaSyncCounter *sync_counter,
frame->sync_request_serial, frame->sync_request_serial,
presentation_time); presentation_time);
COGL_TRACE_DESCRIBE (MetaWindowActorX11FrameTimings, description); COGL_TRACE_DESCRIBE (MetaWindowActorX11FrameTimings, description);
COGL_TRACE_END (MetaWindowActorX11FrameTimings);
} }
#endif #endif
} }