[glib/wip/hadess/add-memory-monitor: 196/202] XXX Warn when a source takes too long to process



commit 51b53c4b7822c9c80aca74e35e622dbd10fd6225
Author: Bastien Nocera <hadess hadess net>
Date:   Sat Mar 22 13:18:04 2014 +0100

    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 ae86d5a2c..2207bfdcd 100644
--- a/glib/gmain.c
+++ b/glib/gmain.c
@@ -3138,6 +3138,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;
@@ -3175,11 +3177,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--;


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