[gnome-builder] core: add marks to syscap for log messages



commit 2d2c3f3fa43634f9150e6ed01e012ea4ce15c9f2
Author: Christian Hergert <chergert redhat com>
Date:   Wed May 22 19:06:55 2019 -0700

    core: add marks to syscap for log messages

 src/libide/core/ide-global.c  |  9 +++++++++
 src/libide/core/ide-log.c     |  5 +++++
 src/libide/core/ide-private.h |  6 ++++++
 src/main.c                    | 44 +++++++++++++++++++++++++++++++++++--------
 4 files changed, 56 insertions(+), 8 deletions(-)
---
diff --git a/src/libide/core/ide-global.c b/src/libide/core/ide-global.c
index 8d4e426df..424863e59 100644
--- a/src/libide/core/ide-global.c
+++ b/src/libide/core/ide-global.c
@@ -265,3 +265,12 @@ ide_trace_function (const gchar *strfunc,
   if (trace_vtable.function)
     trace_vtable.function (strfunc, begin_time_usec, end_time_usec);
 }
+
+void
+_ide_trace_log (const gchar *domain,
+                const gchar *level_str,
+                const gchar *message)
+{
+  if (trace_vtable.log)
+    trace_vtable.log (domain, level_str, message);
+}
diff --git a/src/libide/core/ide-log.c b/src/libide/core/ide-log.c
index 4b3d9e542..b5f7c02ae 100644
--- a/src/libide/core/ide-log.c
+++ b/src/libide/core/ide-log.c
@@ -39,6 +39,7 @@
 #include "ide-debug.h"
 #include "ide-log.h"
 #include "ide-macros.h"
+#include "ide-private.h"
 
 /**
  * SECTION:ide-log
@@ -211,6 +212,10 @@ ide_log_handler (const gchar    *log_domain,
   if (g_strcmp0 ("GdkPixbuf", log_domain) == 0)
     return;
 
+  /* Let tracer know about log message */
+  if (log_level < IDE_LOG_LEVEL_TRACE)
+    _ide_trace_log (log_domain, ide_log_level_str (log_level), message);
+
   if (G_LIKELY (channels->len))
     {
       is_debug_level = (log_level == G_LOG_LEVEL_DEBUG || log_level == IDE_LOG_LEVEL_TRACE);
diff --git a/src/libide/core/ide-private.h b/src/libide/core/ide-private.h
index 1c985acf9..155256095 100644
--- a/src/libide/core/ide-private.h
+++ b/src/libide/core/ide-private.h
@@ -31,9 +31,15 @@ typedef struct
   void (*function) (const gchar    *func,
                     gint64          begin_time_usec,
                     gint64          end_time_usec);
+  void (*log)      (const gchar    *domain,
+                    const gchar    *level_str,
+                    const gchar    *message);
 } IdeTraceVTable;
 
 void _ide_trace_init     (IdeTraceVTable *vtable);
+void _ide_trace_log      (const gchar    *domain,
+                          const gchar    *level_str,
+                          const gchar    *message);
 void _ide_trace_shutdown (void);
 
 G_END_DECLS
diff --git a/src/main.c b/src/main.c
index 04127aa39..4ebccc4d4 100644
--- a/src/main.c
+++ b/src/main.c
@@ -47,6 +47,7 @@
 
 #ifdef ENABLE_TRACING_SYSCAP
 static SysprofCaptureWriter *trace_writer;
+static G_LOCK_DEFINE (tracer);
 
 static void
 trace_load (void)
@@ -71,20 +72,47 @@ trace_function (const gchar    *func,
                 gint64          end_time_usec)
 {
   if (trace_writer != NULL)
-    sysprof_capture_writer_add_mark (trace_writer,
-                                     begin_time_usec * 1000L,
-                                     sched_getcpu (),
-                                     getpid (),
-                                     (end_time_usec - begin_time_usec) * 1000L,
-                                     "tracing",
-                                     "function",
-                                     func);
+    {
+      G_LOCK (tracer);
+      sysprof_capture_writer_add_mark (trace_writer,
+                                       begin_time_usec * 1000L,
+                                       sched_getcpu (),
+                                       getpid (),
+                                       (end_time_usec - begin_time_usec) * 1000L,
+                                       "tracing",
+                                       "function",
+                                       func);
+      G_UNLOCK (tracer);
+    }
+}
+
+static void
+trace_log (const gchar *domain,
+           const gchar *level_str,
+           const gchar *message)
+{
+  if (trace_writer != NULL)
+    {
+      g_autofree gchar *tail = g_strdup_printf ("%s: %s", domain, message);
+
+      G_LOCK (tracer);
+      sysprof_capture_writer_add_mark (trace_writer,
+                                       SYSPROF_CAPTURE_CURRENT_TIME,
+                                       sched_getcpu (),
+                                       getpid (),
+                                       0,
+                                       "log",
+                                       level_str,
+                                       tail);
+      G_UNLOCK (tracer);
+    }
 }
 
 static IdeTraceVTable trace_vtable = {
   trace_load,
   trace_unload,
   trace_function,
+  trace_log,
 };
 #endif
 


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