From: Ian Rogers <irogers@google.com>
To: andi@firstfloor.org
Cc: acme@kernel.org, ak@kernel.org, ak@linux.intel.com,
linux-perf-users@vger.kernel.org, namhyung@kernel.org,
Ian Rogers <irogers@google.com>
Subject: [PATCH v1 2/7] perf ui hist: Add support for aggregated total_period and merging entries cleanly
Date: Sun, 23 Aug 2026 23:37:39 -0700 [thread overview]
Message-ID: <20260824063744.1533837-3-irogers@google.com> (raw)
In-Reply-To: <20260824063744.1533837-1-irogers@google.com>
Implement cross-PMU histogram sorting logic and properly scale the
global total_period for symmetric percentage ceilings across differing
core types, resolving issues with --percent-limit.
Signed-off-by: Ian Rogers <irogers@google.com>
Assisted-by: Antigravity:gemini-3.1-pro
---
tools/perf/ui/hist.c | 49 ++++++++++++++++++++++++++++++++++++++++++
tools/perf/util/hist.h | 5 +++++
2 files changed, 54 insertions(+)
diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c
index e58327595d37..09f0baa808e0 100644
--- a/tools/perf/ui/hist.c
+++ b/tools/perf/ui/hist.c
@@ -287,6 +287,24 @@ static int __hpp__sort(struct hist_entry *a, struct hist_entry *b,
return __hpp__group_sort_idx(a, b, get_field,
symbol_conf.group_sort_idx);
}
+ /*
+ * Relies on merge_entries being only enabled if there are
+ * only matching events. If that is ever relaxed will need
+ * more logic here.
+ */
+ if (a->hists->merge_entries && b->hists->merge_entries) {
+ u64 val_a = get_field(a), val_b = get_field(b);
+ struct hist_entry *pair;
+
+ list_for_each_entry(pair, &a->pairs.head, pairs.node)
+ val_a += get_field(pair);
+ list_for_each_entry(pair, &b->pairs.head, pairs.node)
+ val_b += get_field(pair);
+
+ ret = field_cmp(val_a, val_b);
+ if (ret)
+ return ret;
+ }
ret = field_cmp(get_field(a), get_field(b));
if (ret || !symbol_conf.event_group)
@@ -1271,3 +1289,34 @@ int perf_hpp__alloc_mem_stats(struct perf_hpp_list *list, struct evlist *evlist)
}
return 0;
}
+
+float hist_entry__get_percent_limit_merged(struct hist_entry *he)
+{
+ struct hist_entry *pair;
+ u64 period = he->stat.period;
+ u64 total_period = hists__total_period(he->hists);
+ struct evsel *evsel = hists_to_evsel(he->hists);
+ struct evsel *pos;
+
+ /* Accumulate global total_period across all merged hists */
+ for_each_group_member(pos, evsel) {
+ total_period += hists__total_period(evsel__hists(pos));
+ }
+
+ /* Accumulate symbol specific period across pairs */
+ list_for_each_entry(pair, &he->pairs.head, pairs.node) {
+ period += pair->stat.period;
+ }
+
+ if (unlikely(total_period == 0))
+ return 0;
+
+ if (symbol_conf.cumulate_callchain) {
+ period = he->stat_acc->period;
+ list_for_each_entry(pair, &he->pairs.head, pairs.node) {
+ period += pair->stat_acc->period;
+ }
+ }
+
+ return period * 100.0 / total_period;
+}
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h
index ea79628bbc6b..6cb7059e8405 100644
--- a/tools/perf/util/hist.h
+++ b/tools/perf/util/hist.h
@@ -434,6 +434,8 @@ void hists__match(struct hists *leader, struct hists *other);
int hists__link(struct hists *leader, struct hists *other);
int hists__unlink(struct hists *hists);
+float hist_entry__get_percent_limit_merged(struct hist_entry *he);
+
static inline float hist_entry__get_percent_limit(struct hist_entry *he)
{
u64 period = he->stat.period;
@@ -445,6 +447,9 @@ static inline float hist_entry__get_percent_limit(struct hist_entry *he)
if (symbol_conf.cumulate_callchain)
period = he->stat_acc->period;
+ if (he->hists->merge_entries)
+ return hist_entry__get_percent_limit_merged(he);
+
return period * 100.0 / total_period;
}
--
2.55.0.766.g2966f0265a-goog
next prev parent reply other threads:[~2026-08-24 6:38 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-13 13:25 [PATCH v1] perf top: Merge hybrid common events Andi Kleen
2026-08-13 13:57 ` sashiko-bot
2026-08-17 19:40 ` Ian Rogers
2026-08-18 17:29 ` Andi Kleen
2026-08-19 2:58 ` Ian Rogers
2026-08-19 3:34 ` Andi Kleen
2026-08-19 4:16 ` Ian Rogers
2026-08-19 16:11 ` Andi Kleen
2026-08-19 17:58 ` Ian Rogers
2026-08-19 18:25 ` Andi Kleen
2026-08-19 22:18 ` Ian Rogers
2026-08-24 6:37 ` [PATCH v1 0/7] perf ui: Implement hybrid event merging for heterogeneous systems Ian Rogers
2026-08-24 6:37 ` [PATCH v1 1/7] perf evlist: Implement evlist__can_merge_hybrid using first_wildcard_match Ian Rogers
2026-08-24 6:53 ` sashiko-bot
2026-08-24 22:49 ` Andi Kleen
2026-08-25 4:01 ` Ian Rogers
2026-08-24 6:37 ` Ian Rogers [this message]
2026-08-24 6:53 ` [PATCH v1 2/7] perf ui hist: Add support for aggregated total_period and merging entries cleanly sashiko-bot
2026-08-24 6:37 ` [PATCH v1 3/7] perf ui browsers: Implement interactive 'M' keystroke to toggle hybrid event merging Ian Rogers
2026-08-24 6:49 ` sashiko-bot
2026-08-24 6:37 ` [PATCH v1 4/7] perf tools: Expose opt-in --hybrid-merge Ian Rogers
2026-08-24 6:52 ` sashiko-bot
2026-08-24 22:40 ` Andi Kleen
2026-08-25 3:33 ` Ian Rogers
2026-08-25 22:19 ` Arnaldo Carvalho de Melo
2026-08-24 6:37 ` [PATCH v1 5/7] perf Documentation: Add tip for hybrid event merging Ian Rogers
2026-08-24 6:40 ` sashiko-bot
2026-08-24 6:37 ` [PATCH v1 6/7] perf ui hist: Format group headers iteratively based on proportional visual allocations Ian Rogers
2026-08-24 6:53 ` sashiko-bot
2026-08-24 6:37 ` [PATCH v1 7/7] perf test: Expand top tests for --hybrid-merge Ian Rogers
2026-08-24 6:55 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260824063744.1533837-3-irogers@google.com \
--to=irogers@google.com \
--cc=acme@kernel.org \
--cc=ak@kernel.org \
--cc=ak@linux.intel.com \
--cc=andi@firstfloor.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=namhyung@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.