[gtk/matthiasc/css-values: 1/2] dump css value stats



commit 79cc2232c213bf650301bb1253781c943cdd00cf
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Jan 9 23:48:30 2020 -0500

    dump css value stats

 gtk/gtkcssvalue.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)
---
diff --git a/gtk/gtkcssvalue.c b/gtk/gtkcssvalue.c
index 3f965bdf0c..63a23b0f6c 100644
--- a/gtk/gtkcssvalue.c
+++ b/gtk/gtkcssvalue.c
@@ -29,6 +29,47 @@ struct _GtkCssValue {
 
 G_DEFINE_BOXED_TYPE (GtkCssValue, _gtk_css_value, _gtk_css_value_ref, _gtk_css_value_unref)
 
+static GHashTable *counters;
+
+static void
+dump_value_counts (void)
+{
+  GHashTableIter iter;
+  gpointer key;
+  gpointer value;
+
+  g_hash_table_iter_init (&iter, counters);
+  while (g_hash_table_iter_next (&iter, &key, &value))
+    {
+       const char *class = key;
+       int *c = value;
+       g_print ("%d %d %s\n", c[0], c[0] - c[1], class);
+    }
+}
+
+static void
+count_value (const char *class, int delta)
+{
+  int *c;
+
+  if (!counters)
+    {
+      counters = g_hash_table_new (g_str_hash, g_str_equal);
+      atexit (dump_value_counts);
+    }
+  c = g_hash_table_lookup (counters, class);
+  if (!c)
+    {
+       c = g_new0 (int, 2);
+       g_hash_table_insert (counters, (gpointer)class, c);
+    }
+
+  if (delta == 1)
+    c[0]++;
+  else
+    c[1]++;
+}
+
 GtkCssValue *
 _gtk_css_value_alloc (const GtkCssValueClass *klass,
                       gsize                   size)
@@ -40,6 +81,8 @@ _gtk_css_value_alloc (const GtkCssValueClass *klass,
   value->class = klass;
   value->ref_count = 1;
 
+  count_value (klass->type_name, 1);
+
   return value;
 }
 
@@ -63,6 +106,8 @@ gtk_css_value_unref (GtkCssValue *value)
   if (value->ref_count > 0)
     return;
 
+  count_value (value->class->type_name, -1);
+
   value->class->free (value);
 }
 


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