From: Ian Rogers Date: Thu, 10 Jul 2025 23:51:20 +0000 (-0700) Subject: perf expr: Accumulate rather than replace in the context counts X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=3787cdaf387cdc14a9a000624742b4ee0a509244;p=users%2Fjedix%2Flinux-maple.git perf expr: Accumulate rather than replace in the context counts Metrics will fill in the context to have mappings from an event to a count. When counts are added they replace existing mappings which generally shouldn't exist with aggregation. Switch to accumulating to better support cases where perf stat's aggregation isn't used and we may see a counter more than once. Signed-off-by: Ian Rogers Link: https://lore.kernel.org/r/20250710235126.1086011-8-irogers@google.com Signed-off-by: Namhyung Kim --- diff --git a/tools/perf/util/expr.c b/tools/perf/util/expr.c index 6413537442aa8..ca70a14c7cdfd 100644 --- a/tools/perf/util/expr.c +++ b/tools/perf/util/expr.c @@ -166,8 +166,12 @@ int expr__add_id_val_source_count(struct expr_parse_ctx *ctx, const char *id, data_ptr->kind = EXPR_ID_DATA__VALUE; ret = hashmap__set(ctx->ids, id, data_ptr, &old_key, &old_data); - if (ret) + if (ret) { free(data_ptr); + } else if (old_data) { + data_ptr->val.val += old_data->val.val; + data_ptr->val.source_count += old_data->val.source_count; + } free(old_key); free(old_data); return ret;