[gtk/action-muxer-speedup: 12/12] dump stats



commit 3b80cbd947981b5dca0d5642fb87dd1ed5fedf70
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Jul 19 09:49:16 2020 -0400

    dump stats

 gtk/gtkactionmuxer.c | 102 +++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 99 insertions(+), 3 deletions(-)
---
diff --git a/gtk/gtkactionmuxer.c b/gtk/gtkactionmuxer.c
index 9637260882..0ec4af40dd 100644
--- a/gtk/gtkactionmuxer.c
+++ b/gtk/gtkactionmuxer.c
@@ -1211,6 +1211,92 @@ gtk_action_muxer_remove (GtkActionMuxer *muxer,
     }
 }
 
+static GList *muxers;
+
+static void
+muxer_weak_notify (gpointer  data,
+                   GObject  *where_the_object_was)
+{
+  muxers = g_list_remove (muxers, where_the_object_was);
+}
+
+static gboolean
+dump_muxer_stats (gpointer data)
+{
+  guint n_muxers;
+  guint n_observers;
+  guint n_groups;
+  guint n_accels;
+  GArray *watcher_stats;
+  GArray *accel_stats;
+  GList *l;
+
+  n_muxers = 0;
+  n_observers = 0;
+  n_groups = 0;
+  n_accels = 0;
+
+  watcher_stats = g_array_new (FALSE, TRUE, sizeof (guint));
+  accel_stats = g_array_new (FALSE, TRUE, sizeof (guint));
+
+  for (l = muxers; l; l = l->next)
+    {
+      GtkActionMuxer *muxer = l->data;
+      Action *action;
+      guint accel_count;
+
+      n_muxers++;
+      if (muxer->groups)
+        n_groups += g_hash_table_size (muxer->groups);
+
+      if (muxer->observed_actions)
+        {
+          GHashTableIter iter;
+
+          n_observers += g_hash_table_size (muxer->observed_actions);
+
+          g_hash_table_iter_init (&iter, muxer->observed_actions);
+          while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&action))
+            {
+              guint n_watchers = g_slist_length (action->watchers);
+              if (watcher_stats->len <= n_watchers)
+                g_array_set_size (watcher_stats, n_watchers + 1);
+              g_array_index (watcher_stats, guint, n_watchers) += 1;
+            }
+        }
+
+      accel_count = g_hash_table_size (muxer->primary_accels);
+      n_accels += accel_count;
+
+      if (accel_stats->len <= accel_count)
+        g_array_set_size (accel_stats, accel_count + 1);
+      g_array_index (accel_stats, guint, accel_count) += 1;
+    }
+
+  g_print ("==\n"
+           "%d muxers\n"
+           "%d observers\n"
+           "%d groups\n"
+           "%d accels\n",
+           n_muxers,
+           n_observers,
+           n_groups,
+           n_accels);
+  g_print ("watchers");
+  for (int i = 0; i < watcher_stats->len; i++)
+    g_print (" %u", g_array_index (watcher_stats, guint, i));
+  g_print ("\n");
+  g_print ("accels");
+  for (int i = 0; i < accel_stats->len; i++)
+    g_print (" %u", g_array_index (accel_stats, guint, i));
+  g_print ("\n");
+
+  g_array_unref (watcher_stats);
+  g_array_unref (accel_stats);
+
+  return G_SOURCE_CONTINUE;
+}
+
 /*< private >
  * gtk_action_muxer_new:
  * @widget: the widget to which the muxer belongs
@@ -1220,9 +1306,19 @@ gtk_action_muxer_remove (GtkActionMuxer *muxer,
 GtkActionMuxer *
 gtk_action_muxer_new (GtkWidget *widget)
 {
-  return g_object_new (GTK_TYPE_ACTION_MUXER,
-                       "widget", widget,
-                       NULL);
+  GtkActionMuxer *muxer;
+
+  muxer = g_object_new (GTK_TYPE_ACTION_MUXER,
+                        "widget", widget,
+                        NULL);
+
+  g_object_weak_ref (G_OBJECT (muxer), muxer_weak_notify, NULL);
+  if (muxers == NULL)
+    g_timeout_add (5000, dump_muxer_stats, NULL);
+
+  muxers = g_list_prepend (muxers, muxer);
+
+  return muxer;
 }
 
 /*< private >


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