perf tools: Expose opt-in --hybrid-merge

Add --hybrid-merge to perf report and perf top. It merges the events a
wildcard expanded to across the core PMUs, and their histograms, so
that a symbol which ran on more than one kind of core is reported once
with the total rather than once per PMU.

evlist__merge_hybrid() links the events and evlist__merge_hists_hybrid()
links the histograms. There is nothing to merge on a machine with a
single core PMU, or when the events didn't come from a wildcard, so
warn in that case rather than quietly producing an unmerged report.

Merging collapses the per-PMU entries into one set, which doesn't
combine with the per-level breakdown of --hierarchy, so asking for both
is an error.

Signed-off-by: Ian Rogers <irogers@google.com>
Assisted-by: Antigravity:gemini-3.1-pro
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Ian Rogers 2026-09-16 22:07:02 -07:00 committed by Arnaldo Carvalho de Melo
parent bcb89e6320
commit 6fa291f805
5 changed files with 47 additions and 0 deletions

View File

@ -578,6 +578,11 @@ include::itrace.txt[]
--raw-trace::
When displaying traceevent output, do not use print fmt or plugins.
--hybrid-merge::
Merge matching events from all hybrid core PMUs into one
display. For example, if a wildcard expands to run on both p-cores and
e-cores, this aggregates them into a single view.
-H::
--hierarchy::
Enable hierarchical output. In the hierarchy mode, each sort key groups

View File

@ -49,6 +49,11 @@ Default is to monitor all CPUS.
encoding with the layout of the event control registers as described
by entries in /sys/bus/event_source/devices/cpu/format/*.
--hybrid-merge::
Merge matching events from all hybrid core PMUs into one
display. For example, if a wildcard expands to run on both p-cores and
e-cores, this aggregates them into a single view.
--filter=<filter>::
Event filter. This option should follow an event selector (-e). For
syntax see linkperf:perf-record[1].

View File

@ -1114,6 +1114,17 @@ static int __cmd_report(struct report *rep)
evlist__for_each_entry(session->evlist, pos)
rep->nr_entries += evsel__hists(pos)->nr_entries;
if (symbol_conf.hybrid_merge) {
struct perf_env *env = perf_session__env(session);
if (evlist__can_merge_hybrid(session->evlist, env)) {
evlist__merge_hybrid(session->evlist, env);
evlist__merge_hists_hybrid(session->evlist, false);
} else {
ui__warning("--hybrid-merge: no events to merge across core PMUs\n");
}
}
if (use_browser == 0) {
if (verbose > 3)
perf_session__fprintf(session, stdout);
@ -1449,6 +1460,8 @@ int cmd_report(int argc, const char **argv)
parse_branch_mode),
OPT_BOOLEAN(0, "branch-history", &branch_call_mode,
"add last branch records to call history"),
OPT_BOOLEAN(0, "hybrid-merge", &symbol_conf.hybrid_merge,
"merge the same event across hybrid core PMUs"),
OPT_STRING(0, "objdump", &objdump_path, "path",
"objdump binary to use for disassembly and annotations"),
OPT_STRING(0, "addr2line", &addr2line_path, "path",
@ -1548,6 +1561,12 @@ int cmd_report(int argc, const char **argv)
report.symbol_filter_str = argv[0];
}
if (symbol_conf.report_hierarchy && symbol_conf.hybrid_merge) {
pr_err("Error: --hierarchy and --hybrid-merge are mutually exclusive.\n");
ret = -EINVAL;
goto exit;
}
if (disassembler_style) {
annotate_opts.disassembler_style = strdup(disassembler_style);
if (!annotate_opts.disassembler_style)

View File

@ -1336,6 +1336,15 @@ static int __cmd_top(struct perf_top *top)
if (!target__none(&opts->target))
evlist__enable(top->evlist);
if (symbol_conf.hybrid_merge) {
if (evlist__can_merge_hybrid(top->evlist, /*env=*/NULL)) {
evlist__merge_hybrid(top->evlist, /*env=*/NULL);
evlist__merge_hists_hybrid(top->evlist, false);
} else {
ui__warning("--hybrid-merge: no events to merge across core PMUs\n");
}
}
ret = -1;
if (pthread_create(&thread_process, NULL, process_thread, top)) {
ui__error("Could not create process thread.\n");
@ -1491,6 +1500,8 @@ int cmd_top(int argc, const char **argv)
OPT_CALLBACK('e', "event", &parse_events_option_args, "event",
"event selector. use 'perf list' to list available events",
parse_events_option),
OPT_BOOLEAN(0, "hybrid-merge", &symbol_conf.hybrid_merge,
"merge the same event across hybrid core PMUs"),
OPT_CALLBACK(0, "filter", &top.evlist, "filter",
"event filter", parse_filter),
OPT_U64('c', "count", &opts->user_interval, "event period to sample"),
@ -1679,6 +1690,12 @@ int cmd_top(int argc, const char **argv)
if (argc)
usage_with_options(top_usage, options);
if (symbol_conf.report_hierarchy && symbol_conf.hybrid_merge) {
pr_err("Error: --hierarchy and --hybrid-merge are mutually exclusive.\n");
status = -EINVAL;
goto out_put_evlist;
}
if (disassembler_style) {
annotate_opts.disassembler_style = strdup(disassembler_style);
if (!annotate_opts.disassembler_style) {

View File

@ -73,6 +73,7 @@ struct symbol_conf symbol_conf = {
.symfs = "",
.symfs_layout_flat = false,
.event_group = true,
.hybrid_merge = false,
.inline_name = true,
.res_sample = 0,
.addr2line_timeout_ms = 5 * 1000,