summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2008-04-25 17:37:21 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2008-04-25 17:37:21 +0100
commitf1158d65f8544fd375ea591a55c65db4f6e2a6fe (patch)
tree0871eb59a282d379b6502989f70f0406eb3111b0
parent694b76d2a5e96a33090b7cdc0be50f213008ecaa (diff)
Differentiate between the total and current summary chart view in tooltip.
-rw-r--r--src/summary-chart.c98
-rw-r--r--src/summary.c2
-rw-r--r--src/summary.h2
3 files changed, 80 insertions, 22 deletions
diff --git a/src/summary-chart.c b/src/summary-chart.c
index c632bb0..b67afb6 100644
--- a/src/summary-chart.c
+++ b/src/summary-chart.c
@@ -38,6 +38,9 @@ typedef struct _summary_chart {
AllocatorsStore *store;
struct _sum_allocator others;
+ gboolean total;
+
+ guint dirty;
} SummaryChart;
typedef struct _summary_chart_class {
@@ -51,14 +54,27 @@ G_DEFINE_TYPE (SummaryChart, summary_chart, GTK_TYPE_WIDGET)
enum {
PROP_0 = 0,
- PROP_MODEL
+ PROP_MODEL,
+ PROP_TOTAL
};
-static void
-summary_chart_mark_dirty (SummaryChart *self)
+static gboolean
+_summary_chart_mark_dirty (SummaryChart *self)
{
gtk_widget_queue_draw (&self->widget);
gtk_widget_trigger_tooltip_query (&self->widget);
+ self->dirty = 0;
+ return FALSE;
+}
+
+static void
+summary_chart_mark_dirty (SummaryChart *self)
+{
+ if (self->dirty == 0) {
+ self->dirty = gdk_threads_add_idle (
+ (GSourceFunc) _summary_chart_mark_dirty,
+ self);
+ }
}
static void
@@ -89,6 +105,9 @@ summary_chart_set_property (GObject *obj, guint id, const GValue *v, GParamSpec
case PROP_MODEL:
summary_chart_set_model (self, g_value_get_object (v));
break;
+ case PROP_TOTAL:
+ self->total = g_value_get_boolean (v);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, spec);
break;
@@ -103,6 +122,9 @@ summary_chart_get_property (GObject *obj, guint id, GValue *v, GParamSpec *spec)
case PROP_MODEL:
g_value_set_object (v, self->store);
break;
+ case PROP_TOTAL:
+ g_value_set_boolean (v, self->total);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, spec);
break;
@@ -180,6 +202,29 @@ summary_chart_load_background (SummaryChart *self, cairo_surface_t *target)
}
}
+static void
+summary_chart_screen_changed (GtkWidget *widget, GdkScreen *old_screen)
+{
+ SummaryChart *self = (SummaryChart *) widget;
+ PangoContext *ctx;
+ PangoFontDescription *merge, *desc;
+
+ if (GTK_WIDGET_CLASS (summary_chart_parent_class)->screen_changed)
+ GTK_WIDGET_CLASS (summary_chart_parent_class)->screen_changed (widget,
+ old_screen);
+
+ ctx = gtk_widget_get_pango_context (&self->widget);
+
+ merge = pango_context_get_font_description (ctx);
+ desc = pango_font_description_new ();
+ pango_font_description_set_family_static (desc, "sans");
+ pango_font_description_set_size (desc, PANGO_SCALE * 8);
+ pango_font_description_set_weight (desc, PANGO_WEIGHT_NORMAL);
+ pango_font_description_merge (desc, merge, FALSE);
+ pango_context_set_font_description (ctx, desc);
+ pango_font_description_free (desc);
+}
+
static gboolean
summary_chart_expose (GtkWidget *widget, GdkEventExpose *ev)
{
@@ -196,17 +241,6 @@ summary_chart_expose (GtkWidget *widget, GdkEventExpose *ev)
PangoContext *ctx;
PangoLayout *text;
PangoRectangle logical;
- PangoFontDescription *merge, *desc;
-
- ctx = gtk_widget_create_pango_context (&self->widget);
- merge = pango_context_get_font_description (ctx);
- desc = pango_font_description_new ();
- pango_font_description_set_family_static (desc, "sans");
- pango_font_description_set_size (desc, PANGO_SCALE * 8);
- pango_font_description_set_weight (desc, PANGO_WEIGHT_NORMAL);
- pango_font_description_merge (desc, merge, FALSE);
- pango_context_set_font_description (ctx, desc);
- pango_font_description_free (desc);
sort = allocators_store_get_sort (self->store);
@@ -293,6 +327,7 @@ summary_chart_expose (GtkWidget *widget, GdkEventExpose *ev)
}
/* outlines */
+ ctx = gtk_widget_get_pango_context (&self->widget);
cairo_set_line_width (cr, 1.);
theta = theta_offset;
for (n = 0; n < allocators->len; n++) {
@@ -360,7 +395,6 @@ summary_chart_expose (GtkWidget *widget, GdkEventExpose *ev)
theta += dtheta;
}
- g_object_unref (ctx);
if (theta == theta_offset)
cairo_arc (cr, ww, hh, r, 0, 2*G_PI);
@@ -384,6 +418,11 @@ summary_chart_unrealize (GtkWidget *widget)
self->image = NULL;
}
+ if (self->dirty) {
+ g_source_remove (self->dirty);
+ self->dirty = 0;
+ }
+
GTK_WIDGET_CLASS (summary_chart_parent_class)->unrealize (widget);
}
@@ -508,14 +547,18 @@ summary_chart_query_tooltip (GtkWidget *widget,
A = sum->largest;
if (A != NULL) {
const gchar *main_fn, *last;
- guint n, m, depth;
+ guint n, m, depth, n_allocs;
+
+ n_allocs = A->time_tail->n_allocs;
+ if (! self->total && A->time_tail->prev)
+ n_allocs -= A->time_tail->freed;
g_string_append (string, "\n\nMost frequent allocation callsite, ");
- len = g_snprintf (calls + 40, 40, "%u", A->time_tail->n_allocs);
+ len = g_snprintf (calls + 40, 40, "%u", n_allocs);
pretty_print_number (calls + 40, len, calls);
g_string_append (string, calls);
g_string_append_printf (string, " calls (%.1f%%)",
- A->time_tail->n_allocs * 100. / sum->count);
+ n_allocs * 100. / sum->count);
for (n = 0; n < A->n_frames; n++)
if (A->frames[n]->function == A->alloc_fn)
@@ -566,6 +609,7 @@ summary_chart_class_init (SummaryChartClass *klass)
widget_class->realize = summary_chart_realize;
widget_class->unrealize = summary_chart_unrealize;
+ widget_class->screen_changed = summary_chart_screen_changed;
widget_class->expose_event = summary_chart_expose;
widget_class->query_tooltip = summary_chart_query_tooltip;
@@ -580,6 +624,17 @@ summary_chart_class_init (SummaryChartClass *klass)
G_PARAM_STATIC_BLURB |
G_PARAM_STATIC_NAME |
G_PARAM_READWRITE));
+
+ g_object_class_install_property (object_class,
+ PROP_TOTAL,
+ g_param_spec_boolean ("total",
+ _("total"),
+ _("Total"),
+ TRUE,
+ G_PARAM_STATIC_NICK |
+ G_PARAM_STATIC_BLURB |
+ G_PARAM_STATIC_NAME |
+ G_PARAM_READWRITE));
}
@@ -591,7 +646,10 @@ summary_chart_init (SummaryChart *self)
}
GtkWidget *
-summary_chart_new (AllocatorsStore *store)
+summary_chart_new (AllocatorsStore *store, gboolean total)
{
- return g_object_new (summary_chart_get_type (), "model", store, NULL);
+ return g_object_new (summary_chart_get_type (),
+ "model", store,
+ "total", total,
+ NULL);
}
diff --git a/src/summary.c b/src/summary.c
index 91a7a8b..3f341b9 100644
--- a/src/summary.c
+++ b/src/summary.c
@@ -167,7 +167,7 @@ summary_init (Summary *self)
gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 2);
gtk_widget_show (vbox);
- w = summary_chart_new (self->store);
+ w = summary_chart_new (self->store, self->total);
gtk_box_pack_start (GTK_BOX (hbox), w, TRUE, TRUE, 2);
gtk_widget_show (w);
diff --git a/src/summary.h b/src/summary.h
index 5537d4a..2a3d4db 100644
--- a/src/summary.h
+++ b/src/summary.h
@@ -30,6 +30,6 @@ GtkWidget *
summary_view_new (AllocatorsStore *store);
GtkWidget *
-summary_chart_new (AllocatorsStore *store);
+summary_chart_new (AllocatorsStore *store, gboolean total);
#endif /* SUMMARY_H */