inspector: Add a GraphData object for recording data

This way we can keep more data than just the 2 last values.
This commit is contained in:
Benjamin Otte 2014-10-14 12:59:18 +02:00
parent 14e0283413
commit 0a6755b57c
4 changed files with 34 additions and 14 deletions

View File

@ -29,6 +29,8 @@ libgtkinspector_la_SOURCES = \
general.c \
gestures.h \
gestures.c \
graphdata.h \
graphdata.c \
init.h \
init.c \
inspect-button.c \

View File

@ -30,6 +30,7 @@
#include "data-list.h"
#include "general.h"
#include "gestures.h"
#include "graphdata.h"
#include "menu.h"
#include "misc-info.h"
#include "object-hierarchy.h"
@ -50,6 +51,7 @@ gtk_inspector_init (void)
{
gtk_inspector_register_resource ();
g_type_ensure (GTK_TYPE_GRAPH_DATA);
g_type_ensure (GTK_TYPE_INSPECTOR_ACTIONS);
g_type_ensure (GTK_TYPE_INSPECTOR_CLASSES_LIST);
g_type_ensure (GTK_TYPE_INSPECTOR_CSS_EDITOR);

View File

@ -20,6 +20,7 @@
#include "statistics.h"
#include "graphdata.h"
#include "gtkstack.h"
#include "gtktreeview.h"
#include "gtkcellrenderertext.h"
@ -46,10 +47,8 @@ struct _GtkInspectorStatisticsPrivate
typedef struct {
GType type;
GtkTreeIter treeiter;
gint self1;
gint cumulative1;
gint self2;
gint cumulative2;
GtkGraphData *self;
GtkGraphData *cumulative;
} TypeData;
enum
@ -59,7 +58,9 @@ enum
COLUMN_SELF1,
COLUMN_CUMULATIVE1,
COLUMN_SELF2,
COLUMN_CUMULATIVE2
COLUMN_CUMULATIVE2,
COLUMN_SELF_DATA,
COLUMN_CUMULATIVE_DATA
};
G_DEFINE_TYPE_WITH_PRIVATE (GtkInspectorStatistics, gtk_inspector_statistics, GTK_TYPE_BOX)
@ -85,10 +86,14 @@ add_type_count (GtkInspectorStatistics *sl, GType type)
{
data = g_new0 (TypeData, 1);
data->type = type;
data->self = gtk_graph_data_new (60);
data->cumulative = gtk_graph_data_new (60);
gtk_list_store_append (GTK_LIST_STORE (sl->priv->model), &data->treeiter);
gtk_list_store_set (GTK_LIST_STORE (sl->priv->model), &data->treeiter,
COLUMN_TYPE, data->type,
COLUMN_TYPE_NAME, g_type_name (data->type),
COLUMN_SELF_DATA, data->self,
COLUMN_CUMULATIVE_DATA, data->cumulative,
-1);
g_hash_table_insert (sl->priv->counts, GSIZE_TO_POINTER (type), data);
}
@ -96,16 +101,14 @@ add_type_count (GtkInspectorStatistics *sl, GType type)
self = g_type_get_instance_count (type);
cumulative += self;
data->self1 = data->self2;
data->cumulative1 = data->cumulative2;
data->self2 = self;
data->cumulative2 = cumulative;
gtk_graph_data_prepend_value (data->self, self);
gtk_graph_data_prepend_value (data->cumulative, cumulative);
gtk_list_store_set (GTK_LIST_STORE (sl->priv->model), &data->treeiter,
COLUMN_SELF1, data->self1,
COLUMN_CUMULATIVE1, data->cumulative1,
COLUMN_SELF2, data->self2,
COLUMN_CUMULATIVE2, data->cumulative2,
COLUMN_SELF1, (int) gtk_graph_data_get_value (data->self, 1),
COLUMN_CUMULATIVE1, (int) gtk_graph_data_get_value (data->cumulative, 1),
COLUMN_SELF2, (int) gtk_graph_data_get_value (data->self, 0),
COLUMN_CUMULATIVE2, (int) gtk_graph_data_get_value (data->cumulative, 0),
-1);
return cumulative;
}
@ -202,6 +205,17 @@ cell_data_delta (GtkCellLayout *layout,
g_free (text);
}
static void
type_data_free (gpointer data)
{
TypeData *type_data = data;
g_object_unref (type_data->self);
g_object_unref (type_data->cumulative);
g_free (type_data);
}
static void
gtk_inspector_statistics_init (GtkInspectorStatistics *sl)
{
@ -223,7 +237,7 @@ gtk_inspector_statistics_init (GtkInspectorStatistics *sl)
sl->priv->renderer_cumulative2,
cell_data_delta,
GINT_TO_POINTER (COLUMN_CUMULATIVE2), NULL);
sl->priv->counts = g_hash_table_new_full (NULL, NULL, NULL, g_free);
sl->priv->counts = g_hash_table_new_full (NULL, NULL, NULL, type_data_free);
if (has_instance_counts ())
update_type_counts (sl);

View File

@ -8,6 +8,8 @@
<column type="gint"/>
<column type="gint"/>
<column type="gint"/>
<column type="GtkGraphData"/>
<column type="GtkGraphData"/>
</columns>
</object>
<template class="GtkInspectorStatistics" parent="GtkBox">