[gegl] gegl_instrument: only track times when enabled



commit 5da570e84cbaffd03cd037b1f74044943822c051
Author: Daniel Sabo <DanielSabo gmail com>
Date:   Mon May 20 23:52:44 2013 -0700

    gegl_instrument: only track times when enabled

 gegl/gegl-init.c       |    6 +++++-
 gegl/gegl-instrument.c |   14 +++++++++++---
 gegl/gegl-instrument.h |   11 ++++++++++-
 3 files changed, 26 insertions(+), 5 deletions(-)
---
diff --git a/gegl/gegl-init.c b/gegl/gegl-init.c
index 56a9bf3..fd976cc 100644
--- a/gegl/gegl-init.c
+++ b/gegl/gegl-init.c
@@ -422,7 +422,7 @@ gegl_exit (void)
   global_time = gegl_ticks () - global_time;
   gegl_instrument ("gegl", "gegl", global_time);
 
-  if (g_getenv ("GEGL_DEBUG_TIME") != NULL)
+  if (gegl_instrument_enabled)
     {
       g_printf ("\n%s", gegl_instrument_utf8 ());
     }
@@ -512,6 +512,10 @@ gegl_post_parse_hook (GOptionContext *context,
   global_time = gegl_ticks ();
   g_type_init ();
   babl_init ();
+
+  if (g_getenv ("GEGL_DEBUG_TIME") != NULL)
+    gegl_instrument_enable ();
+
   gegl_instrument ("gegl", "gegl_init", 0);
 
 #ifdef GEGL_ENABLE_DEBUG
diff --git a/gegl/gegl-instrument.c b/gegl/gegl-instrument.c
index a46b3ca..290f93e 100644
--- a/gegl/gegl-instrument.c
+++ b/gegl/gegl-instrument.c
@@ -38,6 +38,8 @@ struct _Timing
   Timing *next;
 };
 
+gboolean gegl_instrument_enabled = FALSE;
+
 static Timing *root = NULL;
 
 static Timing *iter_next (Timing *iter)
@@ -97,9 +99,15 @@ static Timing *timing_find (Timing      *root,
 }
 
 void
-gegl_instrument (const gchar *parent_name,
-                 const gchar *name,
-                 long         usecs)
+gegl_instrument_enable (void)
+{
+  gegl_instrument_enabled = TRUE;
+}
+
+void
+real_gegl_instrument (const gchar *parent_name,
+                      const gchar *name,
+                      long         usecs)
 {
   Timing *iter;
   Timing *parent;
diff --git a/gegl/gegl-instrument.h b/gegl/gegl-instrument.h
index ef29a04..a888b99 100644
--- a/gegl/gegl-instrument.h
+++ b/gegl/gegl-instrument.h
@@ -18,13 +18,22 @@
 #ifndef GEGL_INSTRUMENT_H
 #define GEGL_INSTRUMENT_H
 
+extern gboolean gegl_instrument_enabled;
+
 /* return number of usecs since gegl was initialized */
 long gegl_ticks               (void);
 
+/* start tracking times with gegl_instrument */
+void gegl_instrument_enable   (void);
 
 /* store a timing instrumentation (parent is expected to exist,
  * and to keep it's own record of the time-slice reported) */
-void gegl_instrument          (const gchar *parent,
+#define gegl_instrument(parent, scale, usecs) \
+  { if (gegl_instrument_enabled) { \
+real_gegl_instrument (parent, scale, usecs); \
+                                 } }
+
+void real_gegl_instrument     (const gchar *parent,
                                const gchar *scale,
                                long         usecs);
 


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