[mutter] cogl/trace: Add scoped trace anchors



commit 8bd75747b1ee565f767a5045583649b8f0ce819a
Author: Jonas Ã…dahl <jadahl gmail com>
Date:   Tue Feb 2 23:32:27 2021 +0100

    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: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1700>

 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 3a2a20c630..224655594f 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 <stdio.h>
@@ -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,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]