[sysprof/wip/chergert/mem-preload] memprof: rename column to "Size" from "Hits"



commit 915ed39afcdc3a5914d2e1f42f10a39ea7211e07
Author: Christian Hergert <chergert redhat com>
Date:   Tue Feb 4 16:50:41 2020 -0800

    memprof: rename column to "Size" from "Hits"
    
    This was c&p from the callgraph view, and size more accurately represents
    what we want to display. Also make the column int64, and show the cell
    text as a formatted size for pow^2 data.

 src/libsysprof-ui/sysprof-memprof-page.c  | 39 +++++++++++++++++++++++++------
 src/libsysprof-ui/sysprof-memprof-page.ui |  9 +++----
 src/libsysprof/sysprof-memprof-profile.c  | 13 +++++++++--
 3 files changed, 46 insertions(+), 15 deletions(-)
---
diff --git a/src/libsysprof-ui/sysprof-memprof-page.c b/src/libsysprof-ui/sysprof-memprof-page.c
index 02c061b..6ffb5df 100644
--- a/src/libsysprof-ui/sysprof-memprof-page.c
+++ b/src/libsysprof-ui/sysprof-memprof-page.c
@@ -56,6 +56,8 @@ typedef struct
   GtkTreeView              *functions_view;
   GtkTreeView              *descendants_view;
   GtkTreeViewColumn        *descendants_name_column;
+  GtkTreeViewColumn        *function_size_column;
+  GtkCellRendererText      *function_size_cell;
   GtkStack                 *stack;
 
   GQueue                   *history;
@@ -82,7 +84,7 @@ enum {
   COLUMN_SELF,
   COLUMN_TOTAL,
   COLUMN_POINTER,
-  COLUMN_HITS,
+  COLUMN_SIZE,
 };
 
 static void sysprof_memprof_page_update_descendants (SysprofMemprofPage *self,
@@ -622,12 +624,28 @@ sysprof_memprof_page_caller_activated (SysprofMemprofPage *self,
     sysprof_memprof_page_set_node (self, node);
 }
 
+static void
+sysprof_memprof_page_size_data_func (GtkTreeViewColumn *column,
+                                     GtkCellRenderer   *cell,
+                                     GtkTreeModel      *model,
+                                     GtkTreeIter       *iter,
+                                     gpointer           data)
+{
+  g_autofree gchar *size_str = NULL;
+  guint64 size;
+
+  gtk_tree_model_get (model, iter, COLUMN_SIZE, &size, -1);
+  if (size)
+    size_str = g_format_size_full (size, G_FORMAT_SIZE_IEC_UNITS);
+  g_object_set (cell, "text", size_str, NULL);
+}
+
 static void
 sysprof_memprof_page_tag_data_func (GtkTreeViewColumn *column,
-                                   GtkCellRenderer   *cell,
-                                   GtkTreeModel      *model,
-                                   GtkTreeIter       *iter,
-                                   gpointer           data)
+                                    GtkCellRenderer   *cell,
+                                    GtkTreeModel      *model,
+                                    GtkTreeIter       *iter,
+                                    gpointer           data)
 {
   SysprofMemprofPage *self = data;
   SysprofMemprofPagePrivate *priv = sysprof_memprof_page_get_instance_private (self);
@@ -923,6 +941,8 @@ sysprof_memprof_page_class_init (SysprofMemprofPageClass *klass)
                                                "/org/gnome/sysprof/ui/sysprof-memprof-page.ui");
 
   gtk_widget_class_bind_template_child_private (widget_class, SysprofMemprofPage, callers_view);
+  gtk_widget_class_bind_template_child_private (widget_class, SysprofMemprofPage, function_size_cell);
+  gtk_widget_class_bind_template_child_private (widget_class, SysprofMemprofPage, function_size_column);
   gtk_widget_class_bind_template_child_private (widget_class, SysprofMemprofPage, functions_view);
   gtk_widget_class_bind_template_child_private (widget_class, SysprofMemprofPage, descendants_view);
   gtk_widget_class_bind_template_child_private (widget_class, SysprofMemprofPage, descendants_name_column);
@@ -990,6 +1010,11 @@ sysprof_memprof_page_init (SysprofMemprofPage *self)
                                            sysprof_memprof_page_tag_data_func,
                                            self, NULL);
 
+  gtk_tree_view_column_set_cell_data_func (priv->function_size_column,
+                                           GTK_CELL_RENDERER (priv->function_size_cell),
+                                           sysprof_memprof_page_size_data_func,
+                                           self, NULL);
+
   gtk_tree_selection_set_mode (gtk_tree_view_get_selection (priv->descendants_view),
                                GTK_SELECTION_MULTIPLE);
 
@@ -1125,7 +1150,7 @@ append_to_tree_and_free (SysprofMemprofPage *self,
                       COLUMN_SELF, item->self * 100.0 / (gdouble)profile_size,
                       COLUMN_TOTAL, item->cumulative * 100.0 / (gdouble)profile_size,
                       COLUMN_POINTER, node,
-                      COLUMN_HITS, (guint)item->cumulative,
+                      COLUMN_SIZE, item->cumulative,
                       -1);
 
   if (item->siblings != NULL)
@@ -1154,7 +1179,7 @@ sysprof_memprof_page_update_descendants (SysprofMemprofPage *self,
                               G_TYPE_DOUBLE,
                               G_TYPE_DOUBLE,
                               G_TYPE_POINTER,
-                              G_TYPE_UINT);
+                              G_TYPE_UINT64);
 
   if (priv->profile != NULL)
   {
diff --git a/src/libsysprof-ui/sysprof-memprof-page.ui b/src/libsysprof-ui/sysprof-memprof-page.ui
index 751b262..66899bb 100644
--- a/src/libsysprof-ui/sysprof-memprof-page.ui
+++ b/src/libsysprof-ui/sysprof-memprof-page.ui
@@ -184,17 +184,14 @@
                       </object>
                     </child>
                     <child>
-                      <object class="GtkTreeViewColumn" id="function_hits_column">
+                      <object class="GtkTreeViewColumn" id="function_size_column">
                         <property name="expand">false</property>
                         <property name="sizing">fixed</property>
-                        <property name="title" translatable="yes">Hits</property>
+                        <property name="title" translatable="yes">Size</property>
                         <child>
-                          <object class="GtkCellRendererText">
+                          <object class="GtkCellRendererText" id="function_size_cell">
                             <property name="xalign">1.0</property>
                           </object>
-                          <attributes>
-                            <attribute name="text">4</attribute>
-                          </attributes>
                         </child>
                       </object>
                     </child>
diff --git a/src/libsysprof/sysprof-memprof-profile.c b/src/libsysprof/sysprof-memprof-profile.c
index 08566ee..0255d23 100644
--- a/src/libsysprof/sysprof-memprof-profile.c
+++ b/src/libsysprof/sysprof-memprof-profile.c
@@ -41,6 +41,7 @@ typedef struct
   GStringChunk         *symbols;
   GHashTable           *tags;
   StackStash           *stash;
+  StackStash           *building;
   rax                  *rax;
   GArray               *resolved;
 } Generate;
@@ -72,6 +73,7 @@ generate_free (Generate *g)
   g_clear_pointer (&g->reader, sysprof_capture_reader_unref);
   g_clear_pointer (&g->rax, raxFree);
   g_clear_pointer (&g->stash, stack_stash_unref);
+  g_clear_pointer (&g->building, stack_stash_unref);
   g_clear_pointer (&g->resolvers, g_ptr_array_unref);
   g_clear_pointer (&g->symbols, g_string_chunk_free);
   g_clear_pointer (&g->tags, g_hash_table_unref);
@@ -238,7 +240,7 @@ cursor_foreach_cb (const SysprofCaptureFrame *frame,
       const SysprofCaptureMemoryAlloc *ev = (const SysprofCaptureMemoryAlloc *)frame;
       SysprofAddressContext last_context = SYSPROF_ADDRESS_CONTEXT_NONE;
       StackNode *node;
-      guint len = 5;
+      guint len = 0;
 
       raxInsert (g->rax,
                  (guint8 *)&ev->alloc_addr,
@@ -246,7 +248,7 @@ cursor_foreach_cb (const SysprofCaptureFrame *frame,
                  (gpointer)ev->alloc_size,
                  NULL);
 
-      node = stack_stash_add_trace (g->stash, ev->addrs, ev->n_addrs, ev->alloc_size);
+      node = stack_stash_add_trace (g->building, ev->addrs, ev->n_addrs, ev->alloc_size);
 
       for (const StackNode *iter = node; iter != NULL; iter = iter->parent)
         len++;
@@ -302,6 +304,11 @@ cursor_foreach_cb (const SysprofCaptureFrame *frame,
           if (symbol != NULL)
             g_array_index (g->resolved, SysprofAddress, len++) = POINTER_TO_U64 (symbol);
         }
+
+      stack_stash_add_trace (g->stash,
+                             (gpointer)g->resolved->data,
+                             len,
+                             ev->alloc_size);
     }
 
   return TRUE;
@@ -340,6 +347,7 @@ sysprof_memprof_profile_generate_worker (GTask        *task,
   g_clear_pointer (&g->resolved, g_array_unref);
   g_clear_pointer (&g->resolvers, g_ptr_array_unref);
   g_clear_pointer (&g->reader, sysprof_capture_reader_unref);
+  g_clear_pointer (&g->building, stack_stash_unref);
   g_clear_object (&g->selection);
 
   g_task_return_boolean (task, TRUE);
@@ -375,6 +383,7 @@ sysprof_memprof_profile_generate (SysprofProfile      *profile,
   g->selection = sysprof_selection_copy (self->selection);
   g->rax = raxNew ();
   g->stash = stack_stash_new (NULL);
+  g->building = stack_stash_new (NULL);
   g->resolvers = g_ptr_array_new_with_free_func (g_object_unref);
   g->symbols = g_string_chunk_new (4096*4);
   g->tags = g_hash_table_new (g_str_hash, g_str_equal);


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