[PATCH] perf annotate-data: Show event name in the data-type title
From: Tengda Wu
Date: Thu Oct 29 2026 - 03:20:26 EST
The same data type can be annotated for multiple sampling events, in
which case the data-type header is printed once per event. But the
header only shows the type name and the sample count, so several
identical-looking headers are emitted and the user cannot tell which
event each of them corresponds to. E.g.
$ perf annotate --data-type=page --stdio --itrace=f
Annotate type: 'struct page' in [kernel.kallsyms] (59208 samples):
============================================================================
Percent offset size field
100.00 0 0x40 struct page {
9.95 0 0x8 long unsigned int flags;
Annotate type: 'struct page' in [kernel.kallsyms] (59480 samples):
============================================================================
Percent offset size field
100.00 0 0x40 struct page {
10.15 0 0x8 long unsigned int flags;
Add the event name to the data-type title in both the TUI browser and
the stdio output, so each header can be attributed to its event. For
group events, use evsel__group_desc() to print the group description
instead of the leader's name, so the whole group is identified.
While at it, size the underline in the stdio output dynamically based
on the length of the header line instead of using a fixed-width string,
so it keeps matching the header as the text grows.
Result:
$ perf annotate --data-type=page --stdio --itrace=f
Annotate type: 'struct page' in [kernel.kallsyms] for l1d-miss (59208 samples):
===============================================================================
Percent offset size field
100.00 0 0x40 struct page {
9.95 0 0x8 long unsigned int flags;
Annotate type: 'struct page' in [kernel.kallsyms] for l1d-access (59480 samples):
=================================================================================
Percent offset size field
100.00 0 0x40 struct page {
10.15 0 0x8 long unsigned int flags;
Signed-off-by: Tengda Wu <wutengda@xxxxxxxxxxxxxxx>
---
tools/perf/ui/browsers/annotate-data.c | 14 +++++++++++---
tools/perf/util/annotate-data.c | 15 ++++++++++++---
2 files changed, 23 insertions(+), 6 deletions(-)
diff --git a/tools/perf/ui/browsers/annotate-data.c b/tools/perf/ui/browsers/annotate-data.c
index a15608f6ee53..0f778788df4a 100644
--- a/tools/perf/ui/browsers/annotate-data.c
+++ b/tools/perf/ui/browsers/annotate-data.c
@@ -340,11 +340,19 @@ static int browser__show(struct ui_browser *uib)
struct hist_entry *he = uib->priv;
struct annotated_data_type *adt = he->mem_type;
struct annotated_data_browser *browser = get_browser(uib);
+ struct evsel *evsel = hists_to_evsel(he->hists);
const char *help = "Press 'h' for help on key bindings";
- char title[256];
+ const char *evsel_name = evsel__name(evsel);
+ char buf[512];
+ char title[sizeof(buf) + 256];
+
+ if (evsel__is_group_event(evsel)) {
+ evsel__group_desc(evsel, buf, sizeof(buf));
+ evsel_name = buf;
+ }
- snprintf(title, sizeof(title), "Annotate type: '%s' (%d samples)",
- adt->self.type_name, he->stat.nr_events);
+ snprintf(title, sizeof(title), "Annotate type: '%s' for %s (%d samples)",
+ adt->self.type_name, evsel_name, he->stat.nr_events);
if (ui_browser__show(uib, title, help) < 0)
return -1;
diff --git a/tools/perf/util/annotate-data.c b/tools/perf/util/annotate-data.c
index b3de1ca688a2..25e3169ea8ad 100644
--- a/tools/perf/util/annotate-data.c
+++ b/tools/perf/util/annotate-data.c
@@ -2149,16 +2149,23 @@ static void print_annotated_data_header(struct hist_entry *he, struct evsel *evs
int nr_samples = he->stat.nr_events;
int width = 7;
const char *val_hdr = "Percent";
+ const char *evsel_name = evsel__name(evsel);
+ char buf[512];
+ int len;
if (evsel__is_group_event(evsel)) {
struct hist_entry *pair;
list_for_each_entry(pair, &he->pairs.head, pairs.node)
nr_samples += pair->stat.nr_events;
+
+ evsel__group_desc(evsel, buf, sizeof(buf));
+ evsel_name = buf;
}
- printf("Annotate type: '%s' in %s (%d samples):\n",
- he->mem_type->self.type_name, dso__name(dso), nr_samples);
+ len = printf("Annotate type: '%s' in %s for %s (%d samples):\n",
+ he->mem_type->self.type_name, dso__name(dso), evsel_name,
+ nr_samples);
if (evsel__is_group_event(evsel)) {
struct evsel *pos;
@@ -2183,7 +2190,9 @@ static void print_annotated_data_header(struct hist_entry *he, struct evsel *evs
val_hdr = "Samples";
}
- printf("============================================================================\n");
+ while (len-- > 1)
+ putchar('=');
+ putchar('\n');
printf("%*s %10s %10s %s\n", (width + 1) * nr_members, val_hdr,
"offset", "size", "field");
}
base-commit: 151a134a4e6ec66f69db8750c66006f5207f7a9d
--
2.34.1