[gtk+] inspector: Replace reload with record



commit eaa872f6c303ad9a997b376eb99804f4b1af1b67
Author: Benjamin Otte <otte redhat com>
Date:   Tue Oct 14 14:01:42 2014 +0200

    inspector: Replace reload with record
    
    and when pressed, record instance counts at 1fps.

 gtk/inspector/statistics.c    |   32 +++++++++++++++++++++++++++-----
 gtk/inspector/statistics.ui   |    8 ++++----
 gtk/inspector/statistics.ui.h |    4 +++-
 3 files changed, 34 insertions(+), 10 deletions(-)
---
diff --git a/gtk/inspector/statistics.c b/gtk/inspector/statistics.c
index 628c644..69c4bc8 100644
--- a/gtk/inspector/statistics.c
+++ b/gtk/inspector/statistics.c
@@ -42,6 +42,7 @@ struct _GtkInspectorStatisticsPrivate
   GtkTreeViewColumn *column_cumulative2;
   GtkCellRenderer *renderer_cumulative2;
   GHashTable *counts;
+  guint update_source_id;
 };
 
 typedef struct {
@@ -113,9 +114,10 @@ add_type_count (GtkInspectorStatistics *sl, GType type)
   return cumulative;
 }
 
-static void
-update_type_counts (GtkInspectorStatistics *sl)
+static gboolean
+update_type_counts (gpointer data)
 {
+  GtkInspectorStatistics *sl = data;
   GType type;
   gpointer class;
 
@@ -130,12 +132,29 @@ update_type_counts (GtkInspectorStatistics *sl)
 
       add_type_count (sl, type);
     }
+
+  return TRUE;
 }
 
 static void
-refresh_clicked (GtkWidget *button, GtkInspectorStatistics *sl)
+toggle_record (GtkToggleToolButton    *button,
+               GtkInspectorStatistics *sl)
 {
-  update_type_counts (sl);
+  if (gtk_toggle_tool_button_get_active (button) == (sl->priv->update_source_id != 0))
+    return;
+
+  if (gtk_toggle_tool_button_get_active (button))
+    {
+      sl->priv->update_source_id = gdk_threads_add_timeout_seconds (1,
+                                                                    update_type_counts,
+                                                                    sl);
+      update_type_counts (sl);
+    }
+  else
+    {
+      g_source_remove (sl->priv->update_source_id);
+      sl->priv->update_source_id = 0;
+    }
 }
 
 static gboolean
@@ -250,6 +269,9 @@ finalize (GObject *object)
 {
   GtkInspectorStatistics *sl = GTK_INSPECTOR_STATISTICS (object);
 
+  if (sl->priv->update_source_id)
+    g_source_remove (sl->priv->update_source_id);
+
   g_hash_table_unref (sl->priv->counts);
 
   G_OBJECT_CLASS (gtk_inspector_statistics_parent_class)->finalize (object);
@@ -276,7 +298,7 @@ gtk_inspector_statistics_class_init (GtkInspectorStatisticsClass *klass)
   gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorStatistics, column_cumulative2);
   gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorStatistics, renderer_cumulative2);
   gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorStatistics, button);
-  gtk_widget_class_bind_template_callback (widget_class, refresh_clicked);
+  gtk_widget_class_bind_template_callback (widget_class, toggle_record);
 }
 
 // vim: set et sw=2 ts=2:
diff --git a/gtk/inspector/statistics.ui b/gtk/inspector/statistics.ui
index 7c4ca20..9e72d45 100644
--- a/gtk/inspector/statistics.ui
+++ b/gtk/inspector/statistics.ui
@@ -27,11 +27,11 @@
                 <property name="visible">True</property>
                 <property name="icon-size">small-toolbar</property>
                 <child>
-                  <object class="GtkToolButton" id="button">
+                  <object class="GtkToggleToolButton" id="button">
                     <property name="visible">True</property>
-                    <property name="icon-name">view-refresh-symbolic</property>
-                    <property name="tooltip-text" translatable="yes">Refresh</property>
-                    <signal name="clicked" handler="refresh_clicked"/>
+                    <property name="icon-name">media-record-symbolic</property>
+                    <property name="tooltip-text" translatable="yes">Collect Statistics</property>
+                    <signal name="toggled" handler="toggle_record"/>
                   </object>
                 </child>
               </object>
diff --git a/gtk/inspector/statistics.ui.h b/gtk/inspector/statistics.ui.h
index b1fbb46..c937346 100644
--- a/gtk/inspector/statistics.ui.h
+++ b/gtk/inspector/statistics.ui.h
@@ -1,4 +1,4 @@
-N_("Refresh");
+N_("Collect Statistics");
 N_("Type");
 N_("Self 1");
 N_("Cumulative 1");
@@ -6,4 +6,6 @@ N_("Self 2");
 N_("Cumulative 2");
 N_("Self");
 N_("Cumulative");
+N_("Self");
+N_("Cumulative");
 N_("Enable statistics with GOBJECT_DEBUG=instance-count");


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