From 67c1d858dc859c6261a461541b9a0b6acefcb8a4 Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Tue, 26 Nov 2024 09:21:50 -0800 Subject: [PATCH] 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 --- src/sysprof/sysprof-callgraph-view-private.h | 5 +++-- src/sysprof/sysprof-callgraph-view.c | 14 ++++++++++++-- src/sysprof/sysprof-memory-callgraph-view.c | 20 +++++++++++++++++++- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/sysprof/sysprof-callgraph-view-private.h b/src/sysprof/sysprof-callgraph-view-private.h index c88df22f..8cc04054 100644 --- a/src/sysprof/sysprof-callgraph-view-private.h +++ b/src/sysprof/sysprof-callgraph-view-private.h @@ -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 diff --git a/src/sysprof/sysprof-callgraph-view.c b/src/sysprof/sysprof-callgraph-view.c index f8f10aab..f83bf9c5 100644 --- a/src/sysprof/sysprof-callgraph-view.c +++ b/src/sysprof/sysprof-callgraph-view.c @@ -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]); } diff --git a/src/sysprof/sysprof-memory-callgraph-view.c b/src/sysprof/sysprof-memory-callgraph-view.c index 14972509..13ad8ad3 100644 --- a/src/sysprof/sysprof-memory-callgraph-view.c +++ b/src/sysprof/sysprof-memory-callgraph-view.c @@ -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");