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->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);

View File

@ -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 <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_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

View File

@ -243,7 +243,7 @@ meta_seat_impl_clear_repeat_source (MetaSeatImpl *seat_impl)
static void
dispatch_libinput (MetaSeatImpl *seat_impl)
{
COGL_TRACE_BEGIN (MetaSeatImplDispatchLibinput,
COGL_TRACE_BEGIN_SCOPED (MetaSeatImplDispatchLibinput,
"MetaSeatImpl (dispatch libinput)");
libinput_dispatch (seat_impl->libinput);
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_reverse (should_show);
COGL_TRACE_BEGIN (MetaDisplayShowUnplacedWindows,
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);

View File

@ -1289,7 +1289,7 @@ meta_stack_tracker_restack_managed (MetaStackTracker *tracker,
if (n_managed == 0)
return;
COGL_TRACE_BEGIN (StackTrackerRestackManagedGet,
COGL_TRACE_BEGIN_SCOPED (StackTrackerRestackManagedGet,
"StackTracker: Restack Managed (get)");
meta_stack_tracker_get_stack (tracker, &windows, &n_windows);
@ -1309,7 +1309,7 @@ meta_stack_tracker_restack_managed (MetaStackTracker *tracker,
g_assert (old_pos >= 0);
COGL_TRACE_END (StackTrackerRestackManagedGet);
COGL_TRACE_BEGIN (StackTrackerRestackManagedRaise,
COGL_TRACE_BEGIN_SCOPED (StackTrackerRestackManagedRaise,
"StackTracker: Restack Managed (raise)");
new_pos = n_managed - 1;
if (managed[new_pos] != windows[old_pos])
@ -1324,7 +1324,7 @@ meta_stack_tracker_restack_managed (MetaStackTracker *tracker,
old_pos--;
new_pos--;
COGL_TRACE_BEGIN (StackTrackerRestackManagedRestack,
COGL_TRACE_BEGIN_SCOPED (StackTrackerRestackManagedRestack,
"StackTracker: Restack Managed (restack)");
while (old_pos >= 0 && new_pos >= 0)
{
@ -1354,7 +1354,7 @@ meta_stack_tracker_restack_managed (MetaStackTracker *tracker,
}
COGL_TRACE_END (StackTrackerRestackManagedRestack);
COGL_TRACE_BEGIN (StackTrackerRestackManagedLower,
COGL_TRACE_BEGIN_SCOPED (StackTrackerRestackManagedLower,
"StackTracker: Restack Managed (lower)");
while (new_pos > 0)
{

View File

@ -1845,7 +1845,7 @@ meta_x11_display_handle_xevent (MetaX11Display *x11_display,
MetaWaylandCompositor *wayland_compositor;
#endif
COGL_TRACE_BEGIN (MetaX11DisplayHandleXevent,
COGL_TRACE_BEGIN_SCOPED (MetaX11DisplayHandleXevent,
"X11Display (handle X11 event)");
if (event->type == GenericEvent)
@ -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);
}

View File

@ -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,7 +360,7 @@ do_send_frame_drawn (MetaSyncCounter *sync_counter,
int64_t now_us;
XClientMessageEvent ev = { 0, };
COGL_TRACE_BEGIN (MetaWindowActorX11FrameDrawn,
COGL_TRACE_BEGIN_SCOPED (MetaWindowActorX11FrameDrawn,
"X11: Send _NET_WM_FRAME_DRAWN");
now_us = g_get_monotonic_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,7 +409,7 @@ do_send_frame_timings (MetaSyncCounter *sync_counter,
Display *xdisplay = meta_x11_display_get_xdisplay (display->x11_display);
XClientMessageEvent ev = { 0, };
COGL_TRACE_BEGIN (MetaWindowActorX11FrameTimings,
COGL_TRACE_BEGIN_SCOPED (MetaWindowActorX11FrameTimings,
"X11: Send _NET_WM_FRAME_TIMINGS");
ev.type = ClientMessage;
@ -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
}