Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hadess/230450e781141c2236271b55b5e0b8bf to your computer and use it in GitHub Desktop.
Save hadess/230450e781141c2236271b55b5e0b8bf to your computer and use it in GitHub Desktop.
Warn when a GLib source takes too long to process
From 3ad096f33e6d148127d0417dd0e136dde51f309b Mon Sep 17 00:00:00 2001
From: Bastien Nocera <[email protected]>
Date: Sat, 22 Mar 2014 13:18:04 +0100
Subject: [PATCH] XXX Warn when a source takes too long to process
---
glib/gmain.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/glib/gmain.c b/glib/gmain.c
index 227168a0f..89ee6c420 100644
--- a/glib/gmain.c
+++ b/glib/gmain.c
@@ -3135,6 +3135,8 @@ g_main_dispatch (GMainContext *context)
if (!SOURCE_DESTROYED (source))
{
+ GTimer *timer;
+ gdouble elapsed;
gboolean was_in_call;
gpointer user_data = NULL;
GSourceFunc callback = NULL;
@@ -3172,11 +3174,22 @@ g_main_dispatch (GMainContext *context)
current->source = source;
current->depth++;
+ timer = g_timer_new ();
TRACE (GLIB_MAIN_BEFORE_DISPATCH (g_source_get_name (source), source,
dispatch, callback, user_data));
need_destroy = !(* dispatch) (source, callback, user_data);
TRACE (GLIB_MAIN_AFTER_DISPATCH (g_source_get_name (source), source,
dispatch, need_destroy));
+ elapsed = g_timer_elapsed (timer, NULL);
+ g_timer_destroy (timer);
+ if (elapsed >= (1.0 / 60.0))
+ {
+ const char *name;
+ name = g_source_get_name (source);
+ if (name == NULL)
+ g_message ("Source '%p' doesn't have a name", source);
+ g_message ("Source '%s' took %0.0lf msecs", name, elapsed * 1000.0);
+ }
current->source = prev_source;
current->depth--;
--
2.14.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment