[mutter/gbsneto/profiling-for-real: 2301/2303] cogl/trace: Add helper to retrieve capture writer




commit 3992594469a7032b256f73c018ea9de9d89be406
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Wed Sep 2 14:56:39 2020 -0300

    cogl/trace: Add helper to retrieve capture writer
    
    This is, as of now, a strict operation. So much so that every
    cogl_aquire_capture_writer() call *must* be paired with a
    cogl_release_capture_writer() call.
    
    Make the sysprof-capture dependency explicit as well, since now
    we expose a Sysprof type on public API when tracing is enabled.

 cogl/cogl/cogl-trace.c | 40 ++++++++++++++++++++++++++++++++++++++--
 cogl/cogl/cogl-trace.h | 15 +++++++++++++++
 cogl/meson.build       |  2 +-
 3 files changed, 54 insertions(+), 3 deletions(-)
---
diff --git a/cogl/cogl/cogl-trace.c b/cogl/cogl/cogl-trace.c
index f2d0f789d7..bad09f1998 100644
--- a/cogl/cogl/cogl-trace.c
+++ b/cogl/cogl/cogl-trace.c
@@ -31,8 +31,6 @@
 
 #ifdef HAVE_TRACING
 
-#include <sysprof-capture.h>
-#include <sysprof-capture-writer.h>
 #include <sysprof-clock.h>
 #include <syscall.h>
 #include <sys/types.h>
@@ -283,6 +281,33 @@ cogl_trace_end_with_description (CoglTraceHead *head,
   g_mutex_unlock (&cogl_trace_mutex);
 }
 
+/**
+ * cogl_acquire_capture_writer: (skip)
+ */
+SysprofCaptureWriter *
+cogl_acquire_capture_writer (void)
+{
+  CoglTraceContext *trace_context;
+
+  g_mutex_lock (&cogl_trace_mutex);
+  trace_context = cogl_trace_context;
+  sysprof_capture_writer_flush (trace_context->writer);
+
+  if (!trace_context)
+    return NULL;
+
+  return trace_context->writer;
+}
+
+/**
+ * cogl_release_capture_writer: (skip)
+ */
+void
+cogl_release_capture_writer (void)
+{
+  g_mutex_unlock (&cogl_trace_mutex);
+}
+
 void
 cogl_trace_end (CoglTraceHead *head)
 {
@@ -324,4 +349,15 @@ cogl_set_tracing_disabled_on_thread (void *data)
   fprintf (stderr, "Tracing not enabled");
 }
 
+void *
+cogl_acquire_capture_writer (void)
+{
+  return NULL;
+}
+
+void
+cogl_release_capture_writer (void)
+{
+}
+
 #endif /* HAVE_TRACING */
diff --git a/cogl/cogl/cogl-trace.h b/cogl/cogl/cogl-trace.h
index a0f9333584..94c7bd22aa 100644
--- a/cogl/cogl/cogl-trace.h
+++ b/cogl/cogl/cogl-trace.h
@@ -37,6 +37,9 @@
 
 #ifdef COGL_HAS_TRACING
 
+#include <sysprof-capture.h>
+#include <sysprof-capture-writer.h>
+
 typedef struct _CoglTraceContext CoglTraceContext;
 
 typedef struct _CoglTraceHead
@@ -66,6 +69,12 @@ cogl_set_tracing_enabled_on_thread (GMainContext *main_context,
 COGL_EXPORT void
 cogl_set_tracing_disabled_on_thread (GMainContext *main_context);
 
+COGL_EXPORT
+SysprofCaptureWriter * cogl_acquire_capture_writer (void);
+
+COGL_EXPORT
+void cogl_release_capture_writer (void);
+
 static inline void
 cogl_trace_begin (CoglTraceHead *head,
                   const char    *name)
@@ -151,6 +160,12 @@ cogl_set_tracing_enabled_on_thread (void       *data,
 COGL_EXPORT void
 cogl_set_tracing_disabled_on_thread (void *data);
 
+COGL_EXPORT
+void * cogl_acquire_capture_writer (void);
+
+COGL_EXPORT
+void cogl_release_capture_writer (void);
+
 #endif /* COGL_HAS_TRACING */
 
 #endif /* COGL_TRACE_H */
diff --git a/cogl/meson.build b/cogl/meson.build
index a87cd18235..a717679fe9 100644
--- a/cogl/meson.build
+++ b/cogl/meson.build
@@ -30,7 +30,7 @@ cogl_pkg_private_deps = [
 ]
 
 if have_profiler
-  cogl_pkg_private_deps += [
+  cogl_pkg_deps += [
     sysprof_dep,
   ]
 endif


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