dump css value stats

This commit is contained in:
Matthias Clasen 2020-01-09 23:48:30 -05:00 committed by Timm Bäder
parent 91aa60b210
commit 741e12012d

View File

@ -29,6 +29,54 @@ 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;
int sum1 = 0, sum2 = 0;
g_hash_table_iter_init (&iter, counters);
while (g_hash_table_iter_next (&iter, &key, &value))
{
const char *class = key;
int *c = value;
if (c[0] != 1)
g_print ("%d %d %s\n", c[0], c[0] - c[1], class);
sum1 += c[0];
sum2 += c[0] - c[1];
}
g_print ("SUM: %d, %d\n", sum1, sum2);
}
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 +88,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 +113,8 @@ gtk_css_value_unref (GtkCssValue *value)
if (value->ref_count > 0)
return;
count_value (value->class->type_name, -1);
value->class->free (value);
}