[gnome-builder] rg: share a single CpuTable
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] rg: share a single CpuTable
- Date: Tue, 2 Jun 2015 05:10:24 +0000 (UTC)
commit 4b523e165ad2e4bd0a08ef09010bbe10c2f8b84b
Author: Christian Hergert <christian hergert me>
Date: Mon Jun 1 22:10:18 2015 -0700
rg: share a single CpuTable
This prevents doing the same work multiple times (even though having
multiple cpu graphs is sort of a non-feature). It's useful for testing
purposes to ensure we get the drawing locations right.
contrib/rg/rg-cpu-graph.c | 26 +++++++++++++++++++-------
1 files changed, 19 insertions(+), 7 deletions(-)
---
diff --git a/contrib/rg/rg-cpu-graph.c b/contrib/rg/rg-cpu-graph.c
index fc6861c..561f63c 100644
--- a/contrib/rg/rg-cpu-graph.c
+++ b/contrib/rg/rg-cpu-graph.c
@@ -61,19 +61,31 @@ rg_cpu_graph_new (void)
static void
rg_cpu_graph_constructed (GObject *object)
{
+ static RgCpuTable *table;
RgCpuGraph *self = (RgCpuGraph *)object;
- RgTable *table;
guint n_cpu;
guint i;
G_OBJECT_CLASS (rg_cpu_graph_parent_class)->constructed (object);
- table = g_object_new (RG_TYPE_CPU_TABLE,
- "timespan", self->timespan,
- "max-samples", self->max_samples + 1,
- NULL);
- rg_graph_set_table (RG_GRAPH (self), table);
- g_clear_object (&table);
+ /*
+ * Create a table, but allow it to be destroyed after the last
+ * graph releases it. We will recreate it on demand.
+ */
+ if (table == NULL)
+ {
+ table = g_object_new (RG_TYPE_CPU_TABLE,
+ "timespan", self->timespan,
+ "max-samples", self->max_samples + 1,
+ NULL);
+ g_object_add_weak_pointer (G_OBJECT (table), (gpointer *)&table);
+ rg_graph_set_table (RG_GRAPH (self), RG_TABLE (table));
+ g_object_unref (table);
+ }
+ else
+ {
+ rg_graph_set_table (RG_GRAPH (self), RG_TABLE (table));
+ }
n_cpu = g_get_num_processors ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]