From a99a89782a949342bf48adbfdbc7350349c54812 Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Fri, 21 Jul 2023 10:51:41 -0700 Subject: [PATCH] libsysprof: fix category inheritance Move the bit lower so we can use bitfields properly, and add an unmask helper to avoid all the 0xFF crap. --- src/libsysprof/sysprof-callgraph-frame.c | 18 +++++++++++------- src/libsysprof/sysprof-callgraph-private.h | 3 ++- src/libsysprof/sysprof-callgraph.c | 6 ------ src/libsysprof/sysprof-categories.c | 4 +++- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/libsysprof/sysprof-callgraph-frame.c b/src/libsysprof/sysprof-callgraph-frame.c index 38c5c504..e3d3cd45 100644 --- a/src/libsysprof/sysprof-callgraph-frame.c +++ b/src/libsysprof/sysprof-callgraph-frame.c @@ -519,24 +519,28 @@ static void summarize_node (const SysprofCallgraphNode *node, Summary *summaries) { + guint category = SYSPROF_CALLGRAPH_CATEGORY_UNMASK(node->category); + if (node->is_toplevel && - node->category != 0 && - node->category != SYSPROF_CALLGRAPH_CATEGORY_PRESENTATION) + category != 0 && + category != SYSPROF_CALLGRAPH_CATEGORY_PRESENTATION) { gboolean seen[SYSPROF_CALLGRAPH_CATEGORY_LAST] = {0}; /* Track total count in 0 */ summaries[0].count += node->count; - seen[node->category & 0xFF] = TRUE; - summaries[node->category & 0xFF].count += node->count; + seen[category] = TRUE; + summaries[category].count += node->count; for (const SysprofCallgraphNode *parent = node->parent; parent; parent = parent->parent) { - if (!seen[parent->category & 0xFF] && (parent->category & SYSPROF_CALLGRAPH_CATEGORY_INHERIT) != 0) + guint parent_category = SYSPROF_CALLGRAPH_CATEGORY_UNMASK (parent->category); + + if (!seen[parent_category] && (parent->category & SYSPROF_CALLGRAPH_CATEGORY_INHERIT) != 0) { - seen[parent->category & 0xFF] = TRUE; - summaries[parent->category & 0xFF].count += node->count; + seen[parent_category] = TRUE; + summaries[parent_category].count += node->count; } } } diff --git a/src/libsysprof/sysprof-callgraph-private.h b/src/libsysprof/sysprof-callgraph-private.h index 88cd00f6..5e588be9 100644 --- a/src/libsysprof/sysprof-callgraph-private.h +++ b/src/libsysprof/sysprof-callgraph-private.h @@ -29,7 +29,8 @@ G_BEGIN_DECLS -#define SYSPROF_CALLGRAPH_CATEGORY_INHERIT (1<<30) +#define SYSPROF_CALLGRAPH_CATEGORY_INHERIT (1 << 6) +#define SYSPROF_CALLGRAPH_CATEGORY_UNMASK(c) (c & ~(SYSPROF_CALLGRAPH_CATEGORY_INHERIT)) typedef struct _SysprofCallgraphSummary { diff --git a/src/libsysprof/sysprof-callgraph.c b/src/libsysprof/sysprof-callgraph.c index 1f26d4e2..20b020ea 100644 --- a/src/libsysprof/sysprof-callgraph.c +++ b/src/libsysprof/sysprof-callgraph.c @@ -327,12 +327,6 @@ _sysprof_callgraph_categorize (SysprofCallgraph *self, while (parent != NULL) { - /* If we reach an uncategorized, then nothing above - * is doing inheritance. - */ - if (parent->category == SYSPROF_CALLGRAPH_CATEGORY_UNCATEGORIZED) - break; - if (parent->category & SYSPROF_CALLGRAPH_CATEGORY_INHERIT) { node->category = parent->category; diff --git a/src/libsysprof/sysprof-categories.c b/src/libsysprof/sysprof-categories.c index 8bc121f1..5a96d3ee 100644 --- a/src/libsysprof/sysprof-categories.c +++ b/src/libsysprof/sysprof-categories.c @@ -260,7 +260,7 @@ sysprof_categories_lookup (SysprofCategories *categories, for (guint i = 0; i < rules->len; i++) { const Rule *rule = &g_array_index (rules, Rule, i); - gboolean ret = FALSE; + gboolean ret; if (rule->kind == MATCH_EXACT) ret = strcmp (rule->match, symbol) == 0; @@ -268,6 +268,8 @@ sysprof_categories_lookup (SysprofCategories *categories, ret = g_str_has_prefix (symbol, rule->match); else if (rule->kind == MATCH_SUFFIX) ret = g_str_has_suffix (symbol, rule->match); + else + ret = FALSE; if (ret) {