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.
This commit is contained in:
Christian Hergert
2023-07-21 10:51:41 -07:00
parent ff5c0e4927
commit a99a89782a
4 changed files with 16 additions and 15 deletions

View File

@ -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;
}
}
}

View File

@ -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
{

View File

@ -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;

View File

@ -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)
{