From 6ab28ff6413698ad1a30773de883facde10f3a3f Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Tue, 13 Jun 2023 10:31:42 -0700 Subject: [PATCH] libsysprof-analyze: make summary augmentation optional That way the descendant graphs can generate the self values but ignore the summary augmentation (as that would mess up the generated values). This fixes it so that showing the descendants tree keeps proper Total and Self values. --- src/libsysprof-analyze/sysprof-callgraph.c | 1 + src/libsysprof-analyze/sysprof-callgraph.h | 7 ++++++- .../sysprof-descendants-model.c | 3 +-- src/libsysprof-analyze/tests/test-callgraph.c | 1 + .../sysprof-callgraph-view-private.h | 5 +---- .../sysprof-weighted-callgraph-view.c | 17 ++++++++++++----- 6 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/libsysprof-analyze/sysprof-callgraph.c b/src/libsysprof-analyze/sysprof-callgraph.c index db46db92..caf0f08f 100644 --- a/src/libsysprof-analyze/sysprof-callgraph.c +++ b/src/libsysprof-analyze/sysprof-callgraph.c @@ -329,6 +329,7 @@ sysprof_callgraph_add_traceable (SysprofCallgraph *self, self->augment_func (self, node, SYSPROF_DOCUMENT_FRAME (traceable), + TRUE, self->augment_func_data); } diff --git a/src/libsysprof-analyze/sysprof-callgraph.h b/src/libsysprof-analyze/sysprof-callgraph.h index 5e5e0cb0..e5057687 100644 --- a/src/libsysprof-analyze/sysprof-callgraph.h +++ b/src/libsysprof-analyze/sysprof-callgraph.h @@ -42,6 +42,7 @@ typedef struct _SysprofCallgraphNode SysprofCallgraphNode; * @callgraph: the callgraph being augmented * @node: the node within the callgraph * @frame: the frame used to generate this node + * @summarize: if summaries should be generated * @user_data: closure data for augmentation func * * This function is called for the bottom most node in a trace as it is added @@ -50,11 +51,15 @@ typedef struct _SysprofCallgraphNode SysprofCallgraphNode; * The augmentation func should augment the node in whatever way it sees fit * and generally will want to walk up the node tree to the root to augment the * parents as it goes. Your augmentation function is not called for each node, - * only the last node. + * only the deepest node. + * + * If @summarize is %TRUE, then you should also generate summary augmentation + * using sysprof_callgraph_get_summary_augment() or similar. */ typedef void (*SysprofAugmentationFunc) (SysprofCallgraph *callgraph, SysprofCallgraphNode *node, SysprofDocumentFrame *frame, + gboolean summarize, gpointer user_data); SYSPROF_AVAILABLE_IN_ALL diff --git a/src/libsysprof-analyze/sysprof-descendants-model.c b/src/libsysprof-analyze/sysprof-descendants-model.c index ac99cdc3..025a2ed3 100644 --- a/src/libsysprof-analyze/sysprof-descendants-model.c +++ b/src/libsysprof-analyze/sysprof-descendants-model.c @@ -192,12 +192,11 @@ sysprof_descendants_model_add_traceable (SysprofDescendantsModel *self, node = sysprof_descendants_model_add_trace (self, symbols, n_symbols); - /* TODO: This will fuck up summaries */ - if (node && self->callgraph->augment_func) self->callgraph->augment_func (self->callgraph, node, SYSPROF_DOCUMENT_FRAME (traceable), + FALSE, self->callgraph->augment_func_data); } } diff --git a/src/libsysprof-analyze/tests/test-callgraph.c b/src/libsysprof-analyze/tests/test-callgraph.c index 03479b2c..49ca0bea 100644 --- a/src/libsysprof-analyze/tests/test-callgraph.c +++ b/src/libsysprof-analyze/tests/test-callgraph.c @@ -91,6 +91,7 @@ static void augment_cb (SysprofCallgraph *callgraph, SysprofCallgraphNode *node, SysprofDocumentFrame *frame, + gboolean summarize, gpointer user_data) { Augment *aug; diff --git a/src/libsysprof-gtk/sysprof-callgraph-view-private.h b/src/libsysprof-gtk/sysprof-callgraph-view-private.h index 934cea32..f574bd74 100644 --- a/src/libsysprof-gtk/sysprof-callgraph-view-private.h +++ b/src/libsysprof-gtk/sysprof-callgraph-view-private.h @@ -54,10 +54,7 @@ struct _SysprofCallgraphViewClass GtkWidgetClass parent_class; gsize augment_size; - void (*augment_func) (SysprofCallgraph *callgraph, - SysprofCallgraphNode *node, - SysprofDocumentFrame *frame, - gpointer user_data); + SysprofAugmentationFunc augment_func; void (*load) (SysprofCallgraphView *self, SysprofCallgraph *callgraph); diff --git a/src/libsysprof-gtk/sysprof-weighted-callgraph-view.c b/src/libsysprof-gtk/sysprof-weighted-callgraph-view.c index e1cfa7e6..f1ac08da 100644 --- a/src/libsysprof-gtk/sysprof-weighted-callgraph-view.c +++ b/src/libsysprof-gtk/sysprof-weighted-callgraph-view.c @@ -61,6 +61,7 @@ static void augment_weight (SysprofCallgraph *callgraph, SysprofCallgraphNode *node, SysprofDocumentFrame *frame, + gboolean summarize, gpointer user_data) { AugmentWeight *cur; @@ -75,9 +76,12 @@ augment_weight (SysprofCallgraph *callgraph, cur->size += 1; cur->total += 1; - sum = sysprof_callgraph_get_summary_augment (callgraph, node); - sum->size += 1; - sum->total += 1; + if (summarize) + { + sum = sysprof_callgraph_get_summary_augment (callgraph, node); + sum->size += 1; + sum->total += 1; + } for (node = sysprof_callgraph_node_parent (node); node != NULL; @@ -86,8 +90,11 @@ augment_weight (SysprofCallgraph *callgraph, cur = sysprof_callgraph_get_augment (callgraph, node); cur->total += 1; - sum = sysprof_callgraph_get_summary_augment (callgraph, node); - sum->total += 1; + if (summarize) + { + sum = sysprof_callgraph_get_summary_augment (callgraph, node); + sum->total += 1; + } } }