callgraph: use bump allocator for callgraph nodes

This commit is contained in:
Christian Hergert
2024-09-12 10:52:41 -07:00
parent f446178796
commit 15844df5b9
3 changed files with 16 additions and 25 deletions

View File

@ -22,6 +22,7 @@
#include <gio/gio.h> #include <gio/gio.h>
#include "sysprof-allocator-private.h"
#include "sysprof-callgraph.h" #include "sysprof-callgraph.h"
#include "sysprof-document.h" #include "sysprof-document.h"
@ -57,6 +58,8 @@ struct _SysprofCallgraph
{ {
GObject parent_instance; GObject parent_instance;
SysprofAllocator *allocator;
SysprofDocument *document; SysprofDocument *document;
GListModel *traceables; GListModel *traceables;

View File

@ -113,22 +113,6 @@ sysprof_callgraph_get_summary (SysprofCallgraph *self,
return summary; return summary;
} }
void
_sysprof_callgraph_node_free (SysprofCallgraphNode *node,
gboolean free_self)
{
SysprofCallgraphNode *iter = node->children;
while (iter)
{
SysprofCallgraphNode *to_free = iter;
iter = iter->next;
_sysprof_callgraph_node_free (to_free, TRUE);
}
if (free_self)
g_free (node);
}
static void static void
sysprof_callgraph_dispose (GObject *object) sysprof_callgraph_dispose (GObject *object)
@ -159,7 +143,7 @@ sysprof_callgraph_finalize (GObject *object)
g_clear_object (&self->document); g_clear_object (&self->document);
g_clear_object (&self->traceables); g_clear_object (&self->traceables);
_sysprof_callgraph_node_free (&self->root, FALSE); g_clear_pointer (&self->allocator, sysprof_allocator_unref);
G_OBJECT_CLASS (sysprof_callgraph_parent_class)->finalize (object); G_OBJECT_CLASS (sysprof_callgraph_parent_class)->finalize (object);
} }
@ -183,6 +167,7 @@ sysprof_callgraph_class_init (SysprofCallgraphClass *klass)
static void static void
sysprof_callgraph_init (SysprofCallgraph *self) sysprof_callgraph_init (SysprofCallgraph *self)
{ {
self->allocator = sysprof_allocator_new ();
} }
static void static void
@ -256,7 +241,7 @@ sysprof_callgraph_add_trace (SysprofCallgraph *self,
} }
/* Otherwise create a new node */ /* Otherwise create a new node */
node = g_new0 (SysprofCallgraphNode, 1); node = sysprof_allocator_new0 (self->allocator, SysprofCallgraphNode);
node->summary = sysprof_callgraph_get_summary (self, symbol); node->summary = sysprof_callgraph_get_summary (self, symbol);
node->parent = parent; node->parent = parent;
node->next = parent->children; node->next = parent->children;

View File

@ -20,6 +20,7 @@
#include "config.h" #include "config.h"
#include "sysprof-allocator-private.h"
#include "sysprof-callgraph-private.h" #include "sysprof-callgraph-private.h"
#include "sysprof-callgraph-frame-private.h" #include "sysprof-callgraph-frame-private.h"
#include "sysprof-descendants-model-private.h" #include "sysprof-descendants-model-private.h"
@ -30,10 +31,11 @@
struct _SysprofDescendantsModel struct _SysprofDescendantsModel
{ {
GObject parent_instance; GObject parent_instance;
SysprofCallgraph *callgraph; SysprofAllocator *allocator;
SysprofSymbol *symbol; SysprofCallgraph *callgraph;
SysprofCallgraphNode root; SysprofSymbol *symbol;
SysprofCallgraphNode root;
}; };
static GType static GType
@ -76,11 +78,11 @@ sysprof_descendants_model_finalize (GObject *object)
{ {
SysprofDescendantsModel *self = (SysprofDescendantsModel *)object; SysprofDescendantsModel *self = (SysprofDescendantsModel *)object;
_sysprof_callgraph_node_free (&self->root, FALSE);
g_clear_object (&self->callgraph); g_clear_object (&self->callgraph);
g_clear_object (&self->symbol); g_clear_object (&self->symbol);
g_clear_pointer (&self->allocator, sysprof_allocator_unref);
G_OBJECT_CLASS (sysprof_descendants_model_parent_class)->finalize (object); G_OBJECT_CLASS (sysprof_descendants_model_parent_class)->finalize (object);
} }
@ -95,6 +97,7 @@ sysprof_descendants_model_class_init (SysprofDescendantsModelClass *klass)
static void static void
sysprof_descendants_model_init (SysprofDescendantsModel *self) sysprof_descendants_model_init (SysprofDescendantsModel *self)
{ {
self->allocator = sysprof_allocator_new ();
} }
static SysprofCallgraphNode * static SysprofCallgraphNode *
@ -141,7 +144,7 @@ sysprof_descendants_model_add_trace (SysprofDescendantsModel *self,
} }
/* Otherwise create a new node */ /* Otherwise create a new node */
node = g_new0 (SysprofCallgraphNode, 1); node = sysprof_allocator_new0 (self->allocator, SysprofCallgraphNode);
node->summary = summary; node->summary = summary;
node->parent = parent; node->parent = parent;
node->next = parent->children; node->next = parent->children;