Linux Perf Users
 help / color / mirror / Atom feed
* [PATCH] perf annotate-data: Show event name in the data-type title
@ 2026-10-29  7:15 Tengda Wu
  2026-10-29  7:21 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Tengda Wu @ 2026-10-29  7:15 UTC (permalink / raw)
  To: Namhyung Kim, Arnaldo Carvalho de Melo
  Cc: james.clark, xueshuai, Peter Zijlstra, leo.yan, Li Huafei,
	Ian Rogers, Kim Phillips, Mark Rutland, Ingo Molnar,
	Bill Wendling, Nick Desaulniers, Alexander Shishkin,
	Adrian Hunter, Zecheng Li, linux-perf-users, linux-kernel, llvm,
	Tengda Wu

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@huaweicloud.com>
---
 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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-10-29  7:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-29  7:15 [PATCH] perf annotate-data: Show event name in the data-type title Tengda Wu
2026-10-29  7:21 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox