sysprof: add unload hooks for callgraph view

We want to ensure that the sorters can clear their private state before
the callgraph itself is released.

Related: #131
This commit is contained in:
Christian Hergert
2024-11-26 09:21:50 -08:00
parent 673ab1b944
commit 67c1d858dc
3 changed files with 34 additions and 5 deletions

View File

@ -69,8 +69,9 @@ struct _SysprofCallgraphViewClass
gsize augment_size;
SysprofAugmentationFunc augment_func;
void (*load) (SysprofCallgraphView *self,
SysprofCallgraph *callgraph);
void (*load) (SysprofCallgraphView *self,
SysprofCallgraph *callgraph);
void (*unload) (SysprofCallgraphView *self);
};
G_END_DECLS

View File

@ -339,6 +339,14 @@ sysprof_callgraph_view_dispose (GObject *object)
{
SysprofCallgraphView *self = (SysprofCallgraphView *)object;
if (self->callgraph != NULL)
{
if (SYSPROF_CALLGRAPH_VIEW_GET_CLASS (self)->unload)
SYSPROF_CALLGRAPH_VIEW_GET_CLASS (self)->unload (self);
g_clear_object (&self->callgraph);
}
if (self->functions_column_view)
gtk_column_view_set_model (self->functions_column_view, NULL);
@ -363,7 +371,6 @@ sysprof_callgraph_view_dispose (GObject *object)
g_cancellable_cancel (self->cancellable);
g_clear_object (&self->cancellable);
g_clear_object (&self->callgraph);
g_clear_object (&self->document);
g_clear_object (&self->traceables);
g_clear_object (&self->utility_summary);
@ -668,6 +675,9 @@ sysprof_callgraph_view_reload_cb (GObject *object,
return;
}
if (SYSPROF_CALLGRAPH_VIEW_GET_CLASS (self)->unload)
SYSPROF_CALLGRAPH_VIEW_GET_CLASS (self)->unload (self);
g_set_object (&self->callgraph, callgraph);
sysprof_callgraph_view_set_descendants (self, G_LIST_MODEL (callgraph));
@ -698,7 +708,7 @@ sysprof_callgraph_view_reload_cb (GObject *object,
functions_name_compare, NULL, NULL);
if (SYSPROF_CALLGRAPH_VIEW_GET_CLASS (self)->load)
SYSPROF_CALLGRAPH_VIEW_GET_CLASS (self)->load (self, callgraph);
SYSPROF_CALLGRAPH_VIEW_GET_CLASS (self)->load (self, callgraph);
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_CALLGRAPH]);
}

View File

@ -282,7 +282,7 @@ functions_sort_by_total (gconstpointer a,
static void
sysprof_memory_callgraph_view_load (SysprofCallgraphView *view,
SysprofCallgraph *callgraph)
SysprofCallgraph *callgraph)
{
SysprofMemoryCallgraphView *self = (SysprofMemoryCallgraphView *)view;
AugmentMemory *root;
@ -318,6 +318,23 @@ sysprof_memory_callgraph_view_load (SysprofCallgraphView *view,
GTK_SORT_DESCENDING);
}
static void
sysprof_memory_callgraph_view_unload (SysprofCallgraphView *view)
{
SysprofMemoryCallgraphView *self = (SysprofMemoryCallgraphView *)view;
g_assert (SYSPROF_IS_MEMORY_CALLGRAPH_VIEW (self));
gtk_custom_sorter_set_sort_func (self->descendants_self_sorter, NULL, NULL, NULL);
gtk_custom_sorter_set_sort_func (self->descendants_total_sorter, NULL, NULL, NULL);
gtk_custom_sorter_set_sort_func (self->functions_self_sorter, NULL, NULL, NULL);
gtk_custom_sorter_set_sort_func (self->functions_total_sorter, NULL, NULL, NULL);
gtk_custom_sorter_set_sort_func (self->callers_self_sorter, NULL, NULL, NULL);
gtk_custom_sorter_set_sort_func (self->callers_total_sorter, NULL, NULL, NULL);
}
static char *
get_total_size (GObject *item)
{
@ -346,6 +363,7 @@ sysprof_memory_callgraph_view_class_init (SysprofMemoryCallgraphViewClass *klass
callgraph_view_class->augment_size = sizeof (AugmentMemory);
callgraph_view_class->augment_func = augment_memory;
callgraph_view_class->load = sysprof_memory_callgraph_view_load;
callgraph_view_class->unload = sysprof_memory_callgraph_view_unload;
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/sysprof/sysprof-memory-callgraph-view.ui");