From 12690401a4393238c391b7a6a861a28d26374013 Mon Sep 17 00:00:00 2001 From: Ian Rogers Date: Sun, 5 Oct 2025 11:14:21 -0700 Subject: [PATCH] perf stat: Additional verbose details for events If an event shows as "" in perf stat output, in verbose mode add the strerror output to help diagnose the issue. Consider: ``` $ perf stat -e cycles,data_read,instructions true Performance counter stats for 'true': 357,457 cycles:u MiB data_read:u 156,182 instructions:u # 0.44 insn per cycle 0.001250315 seconds time elapsed 0.001283000 seconds user 0.000000000 seconds sys ``` To understand why the data_read uncore event failed you can run it again with -v option. This change adds detailed message about the error and suggestion how to fix it potentially. Warning: data_read:u event is not supported by the kernel. Invalid event (data_read:u) in per-thread mode, enable system wide with '-a'. Signed-off-by: Ian Rogers [ simplified the commit message ] Signed-off-by: Namhyung Kim --- tools/perf/builtin-stat.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 7006f848f87a6..84e06ec09cc27 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -624,8 +624,9 @@ static enum counter_recovery stat_handle_error(struct evsel *counter, int err) */ if (err == EINVAL || err == ENOSYS || err == ENOENT || err == ENXIO) { if (verbose > 0) { - ui__warning("%s event is not supported by the kernel.\n", - evsel__name(counter)); + evsel__open_strerror(counter, &target, err, msg, sizeof(msg)); + ui__warning("%s event is not supported by the kernel.\n%s\n", + evsel__name(counter), msg); } return COUNTER_SKIP; } @@ -649,10 +650,11 @@ static enum counter_recovery stat_handle_error(struct evsel *counter, int err) } } if (verbose > 0) { + evsel__open_strerror(counter, &target, err, msg, sizeof(msg)); ui__warning(err == EOPNOTSUPP - ? "%s event is not supported by the kernel.\n" - : "skipping event %s that kernel failed to open.\n", - evsel__name(counter)); + ? "%s event is not supported by the kernel.\n%s\n" + : "skipping event %s that kernel failed to open.\n%s\n", + evsel__name(counter), msg); } return COUNTER_SKIP; } -- 2.47.3