[1/4] perf bpf_counter: Add more error messages for bperf

Message ID 20230104064402.1551516-2-namhyung@kernel.org
State New
Headers
Series perf bpf_counter: A set of random fixes (v1) |

Commit Message

Namhyung Kim Jan. 4, 2023, 6:43 a.m. UTC
  I found perf stat silently exits when it failed in bperf__load().
Let's add some error messages to notify users.

  $ sudo ./perf stat -a --bpf-counters -ddd sleep 1
  bpf_map_update_elem failed: err=-7

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/util/bpf_counter.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
  

Patch

diff --git a/tools/perf/util/bpf_counter.c b/tools/perf/util/bpf_counter.c
index eeee899fcf34..7f5cc1aa4903 100644
--- a/tools/perf/util/bpf_counter.c
+++ b/tools/perf/util/bpf_counter.c
@@ -471,8 +471,10 @@  static int bperf__load(struct evsel *evsel, struct target *target)
 
 	if (!all_cpu_map) {
 		all_cpu_map = perf_cpu_map__new(NULL);
-		if (!all_cpu_map)
+		if (!all_cpu_map) {
+			pr_err("failed to create all cpu map\n");
 			return -1;
+		}
 	}
 
 	evsel->bperf_leader_prog_fd = -1;
@@ -493,13 +495,16 @@  static int bperf__load(struct evsel *evsel, struct target *target)
 	err = bpf_map_lookup_elem(attr_map_fd, &evsel->core.attr, &entry);
 	if (err) {
 		err = bpf_map_update_elem(attr_map_fd, &evsel->core.attr, &entry, BPF_ANY);
-		if (err)
+		if (err) {
+			pr_err("updating perf_event_attr map failed: err=%d\n", err);
 			goto out;
+		}
 	}
 
 	evsel->bperf_leader_link_fd = bpf_link_get_fd_by_id(entry.link_id);
 	if (evsel->bperf_leader_link_fd < 0 &&
 	    bperf_reload_leader_program(evsel, attr_map_fd, &entry)) {
+		pr_err("reload leader program failed\n");
 		err = -1;
 		goto out;
 	}