debug: Group debug messages by timestamps
authorEmmanuele Bassi <ebassi@linux.intel.com>
Thu, 7 Jun 2012 10:51:33 +0000 (11:51 +0100)
committerEmmanuele Bassi <ebassi@linux.intel.com>
Thu, 7 Jun 2012 10:57:53 +0000 (11:57 +0100)
Instead of showing the full timestamp for debugging messages that happen
within a second, showing the delta from the previous full timestamp can
be more useful when debugging; this allows immediately seeing the time
difference, instead of doing the math in our heads.

clutter/clutter-main.c

index 744301b..3069837 100644 (file)
@@ -3850,10 +3850,30 @@ void
 _clutter_debug_messagev (const char *format,
                          va_list     var_args)
 {
+  static gint64 last_debug_stamp;
   gchar *stamp, *fmt;
+  gint64 cur_time, debug_stamp;
+
+  cur_time = g_get_monotonic_time ();
+
+  /* if the last debug message happened less than a second ago, just
+   * show the increments instead of the full timestamp
+   */
+  if (last_debug_stamp == 0 ||
+      cur_time - last_debug_stamp >= G_USEC_PER_SEC)
+    {
+      debug_stamp = cur_time;
+      last_debug_stamp = debug_stamp;
+
+      stamp = g_strdup_printf ("[%16" G_GINT64_FORMAT "]", debug_stamp);
+    }
+  else
+    {
+      debug_stamp = cur_time - last_debug_stamp;
+
+      stamp = g_strdup_printf ("[%+16" G_GINT64_FORMAT "]", debug_stamp);
+    }
 
-  stamp = g_strdup_printf ("[%16" G_GINT64_FORMAT "]",
-                           g_get_monotonic_time ());
   fmt = g_strconcat (stamp, ":", format, NULL);
   g_free (stamp);