[gtk/matthiasc/css-change: 5/10] wip: css node stats



commit 88ab78499d18e525d87b46e485fcbcc58c470f3b
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Jan 15 19:03:50 2020 -0500

    wip: css node stats
    
    Dump out some numbers about the amount of nodes we have for
    each change flag.

 gtk/gtkcssnode.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 gtk/gtkwindow.c  |  3 +++
 2 files changed, 54 insertions(+)
---
diff --git a/gtk/gtkcssnode.c b/gtk/gtkcssnode.c
index b61b70f822..2d8da43200 100644
--- a/gtk/gtkcssnode.c
+++ b/gtk/gtkcssnode.c
@@ -1431,3 +1431,54 @@ gtk_css_node_print (GtkCssNode                *cssnode,
         gtk_css_node_print (node, flags, string, indent + 2);
     }
 }
+
+void print_css_node_stats (GtkCssNode *root);
+
+static int node_count;
+static int change_count[64];
+
+static void
+collect_css_node_stats (GtkCssNode *node)
+{
+  GtkCssStyle *style;
+  GtkCssChange change;
+  int i;
+
+  node_count++;
+
+  style = gtk_css_node_get_style (node);
+  style = gtk_css_style_get_static_style (style);
+  change = gtk_css_static_style_get_change (GTK_CSS_STATIC_STYLE (style));
+  for (i = 0; i < 64; i++)
+    {
+      if (change & (1ULL << i))
+        change_count[i]++;
+    }
+ 
+  for (node = gtk_css_node_get_first_child (node);
+       node != NULL;
+       node = gtk_css_node_get_next_sibling (node))
+    collect_css_node_stats (node);
+}
+
+void
+print_css_node_stats (GtkCssNode *root)
+{
+  int i;
+
+  collect_css_node_stats (root);
+  
+  g_print ("%d nodes\n", node_count);
+  node_count = 0;
+
+  for (i = 0; i < 64; i++)
+    {
+      if (change_count[i])
+        {
+          char *s = gtk_css_change_to_string (1ULL << i);
+          g_print ("%s %d\n", s, change_count[i]);
+          g_free (s);
+          change_count[i] = 0;
+        }
+    }
+}
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index c0a5067a52..320c563773 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -6008,11 +6008,14 @@ surface_size_changed (GtkWidget *widget,
   gtk_window_configure (GTK_WINDOW (widget), width, height);
 }
 
+extern void print_css_node_stats (GtkCssNode *root);
+
 static gboolean
 surface_render (GdkSurface     *surface,
                 cairo_region_t *region,
                 GtkWidget      *widget)
 {
+  print_css_node_stats (gtk_widget_get_css_node (widget));
   gtk_widget_render (widget, surface, region);
   return TRUE;
 }


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