debug: Group debug messages by timestamps

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.
This commit is contained in:
Emmanuele Bassi 2012-06-07 11:51:33 +01:00
parent a3a2fbfd5a
commit 42b933eeaf

View 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);