[gtk: 1/14] Add gdk_profiler_add_markf() to do printf formating



commit 6de85c0a68ac3a3bae21c780559de74e671419ae
Author: Alexander Larsson <alexl redhat com>
Date:   Wed Feb 12 09:56:10 2020 +0100

    Add gdk_profiler_add_markf() to do printf formating
    
    This allows us to avoid hand-rolling g_strdup_printf calls,
    but also moves the printf into the called function where
    it doesn't bloat the code of the calling function if the profiler
    is not running.

 gdk/gdkprofiler.c        | 25 +++++++++++++++++++++++++
 gdk/gdkprofilerprivate.h |  5 +++++
 2 files changed, 30 insertions(+)
---
diff --git a/gdk/gdkprofiler.c b/gdk/gdkprofiler.c
index 5b4e976110..3554c0104b 100644
--- a/gdk/gdkprofiler.c
+++ b/gdk/gdkprofiler.c
@@ -100,6 +100,31 @@ gdk_profiler_add_mark (gint64      start,
                                    "gtk", name, message);
 }
 
+void
+gdk_profiler_add_markf (gint64      start,
+                        guint64     duration,
+                        const char *name,
+                        const char *format,
+                        ...)
+{
+  va_list args;
+  char *message;
+
+  if (!running)
+    return;
+
+  va_start (args, format);
+  message = g_strdup_vprintf (format, args);
+  va_end (args);
+
+  sysprof_capture_writer_add_mark (writer,
+                                   start,
+                                   -1, getpid (),
+                                   duration,
+                                   "gtk", name, message);
+  g_free (message);
+}
+
 static guint
 define_counter (const char *name,
                 const char *description,
diff --git a/gdk/gdkprofilerprivate.h b/gdk/gdkprofilerprivate.h
index 9696c7e2dc..99558e3adf 100644
--- a/gdk/gdkprofilerprivate.h
+++ b/gdk/gdkprofilerprivate.h
@@ -30,6 +30,11 @@ void     gdk_profiler_add_mark   (gint64           start,
                                   guint64          duration,
                                   const char      *name,
                                   const char      *message);
+void     gdk_profiler_add_markf   (gint64           start,
+                                   guint64          duration,
+                                   const char      *name,
+                                   const char      *format,
+                                   ...)  G_GNUC_PRINTF (4, 5);
 guint    gdk_profiler_define_counter (const char *name,
                                       const char *description);
 void     gdk_profiler_set_counter    (guint  id,


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