From 8bd75747b1ee565f767a5045583649b8f0ce819a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Tue, 2 Feb 2021 23:32:27 +0100 Subject: [PATCH] cogl/trace: Add scoped trace anchors A trace "anchor" is a trace head (CoglTraceHead) that is placed in a certain scope (e.g. function scope), but then only triggered in another scope, e.g. a condition. This makes it possible to have optional trace instrumentation, that is enabled only given e.g. a debug flag. Part-of: --- cogl/cogl/cogl-trace.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/cogl/cogl/cogl-trace.h b/cogl/cogl/cogl-trace.h index 3a2a20c63..224655594 100644 --- a/cogl/cogl/cogl-trace.h +++ b/cogl/cogl/cogl-trace.h @@ -111,6 +111,18 @@ cogl_auto_trace_end_helper (CoglTraceHead **head) if (g_private_get (&cogl_trace_thread_data)) \ cogl_trace_describe (&CoglTrace##Name, description); +#define COGL_TRACE_SCOPED_ANCHOR(Name) \ + CoglTraceHead G_GNUC_UNUSED CoglTrace##Name = { 0 }; \ + __attribute__((cleanup (cogl_auto_trace_end_helper))) \ + CoglTraceHead *ScopedCoglTrace##Name = NULL; \ + +#define COGL_TRACE_BEGIN_ANCHORED(Name, name) \ + if (g_private_get (&cogl_trace_thread_data)) \ + { \ + cogl_trace_begin (&CoglTrace##Name, name); \ + ScopedCoglTrace##Name = &CoglTrace##Name; \ + } + #else /* COGL_HAS_TRACING */ #include @@ -119,6 +131,8 @@ cogl_auto_trace_end_helper (CoglTraceHead **head) #define COGL_TRACE_END(Name) (void) 0 #define COGL_TRACE_BEGIN_SCOPED(Name, name) (void) 0 #define COGL_TRACE_DESCRIBE(Name, description) (void) 0 +#define COGL_TRACE_ANCHOR(Name) (void) 0 +#define COGL_TRACE_BEGIN_ANCHORED(Name, name) (void) 0 COGL_EXPORT void cogl_set_tracing_enabled_on_thread_with_fd (void *data,