[mutter] cogl/trace: Add way to add a description to trace



commit b1ac1327cdf85c7b70e630660c8fcf6b630b21da
Author: Jonas Ã…dahl <jadahl gmail com>
Date:   Tue Feb 2 23:30:53 2021 +0100

    cogl/trace: Add way to add a description to trace
    
    This is useful to pass more complex information, generated at runtime.
    
    Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1700>

 cogl/cogl/cogl-trace.c | 21 ++++++++++++++++++---
 cogl/cogl/cogl-trace.h | 10 ++++++++++
 2 files changed, 28 insertions(+), 3 deletions(-)
---
diff --git a/cogl/cogl/cogl-trace.c b/cogl/cogl/cogl-trace.c
index 80c3da77f2..f2d0f789d7 100644
--- a/cogl/cogl/cogl-trace.c
+++ b/cogl/cogl/cogl-trace.c
@@ -251,8 +251,9 @@ cogl_set_tracing_disabled_on_thread (GMainContext *main_context)
   g_source_unref (source);
 }
 
-void
-cogl_trace_end (CoglTraceHead *head)
+static void
+cogl_trace_end_with_description (CoglTraceHead *head,
+                                 const char    *description)
 {
   SysprofTimeStamp end_time;
   CoglTraceContext *trace_context;
@@ -270,7 +271,7 @@ cogl_trace_end (CoglTraceHead *head)
                                         (uint64_t) end_time - head->begin_time,
                                         trace_thread_context->group,
                                         head->name,
-                                        NULL))
+                                        description))
     {
       /* XXX: g_main_context_get_thread_default() might be wrong, it probably
        * needs to store the GMainContext in CoglTraceThreadContext when creating
@@ -282,6 +283,20 @@ cogl_trace_end (CoglTraceHead *head)
   g_mutex_unlock (&cogl_trace_mutex);
 }
 
+void
+cogl_trace_end (CoglTraceHead *head)
+{
+  cogl_trace_end_with_description (head, head->description);
+  g_free (head->description);
+}
+
+void
+cogl_trace_describe (CoglTraceHead *head,
+                     const char    *description)
+{
+  head->description = g_strdup (description);
+}
+
 #else
 
 #include <string.h>
diff --git a/cogl/cogl/cogl-trace.h b/cogl/cogl/cogl-trace.h
index 4d1e52aaee..3a2a20c630 100644
--- a/cogl/cogl/cogl-trace.h
+++ b/cogl/cogl/cogl-trace.h
@@ -43,6 +43,7 @@ typedef struct _CoglTraceHead
 {
   uint64_t begin_time;
   const char *name;
+  char *description;
 } CoglTraceHead;
 
 COGL_EXPORT
@@ -76,6 +77,10 @@ cogl_trace_begin (CoglTraceHead *head,
 COGL_EXPORT void
 cogl_trace_end (CoglTraceHead *head);
 
+COGL_EXPORT void
+cogl_trace_describe (CoglTraceHead *head,
+                     const char    *description);
+
 static inline void
 cogl_auto_trace_end_helper (CoglTraceHead **head)
 {
@@ -102,6 +107,10 @@ cogl_auto_trace_end_helper (CoglTraceHead **head)
       ScopedCoglTrace##Name = &CoglTrace##Name; \
     }
 
+#define COGL_TRACE_DESCRIBE(Name, description)\
+  if (g_private_get (&cogl_trace_thread_data)) \
+    cogl_trace_describe (&CoglTrace##Name, description);
+
 #else /* COGL_HAS_TRACING */
 
 #include <stdio.h>
@@ -109,6 +118,7 @@ cogl_auto_trace_end_helper (CoglTraceHead **head)
 #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_DESCRIBE(Name, description) (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]