perf evsel: Add pmu_name helper
authorIan Rogers <irogers@google.com>
Thu, 9 Jan 2025 22:21:06 +0000 (14:21 -0800)
committerNamhyung Kim <namhyung@kernel.org>
Wed, 29 Jan 2025 22:05:57 +0000 (14:05 -0800)
Add helper to get the name of the evsel's PMU. This handles the case
where there's no sysfs PMU via parse_events event_type helper.

Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: James Clark <james.clark@linaro.org>
Tested-by: Leo Yan <leo.yan@arm.com>
Tested-by: Atish Patra <atishp@rivosinc.com>
Link: https://lore.kernel.org/r/20250109222109.567031-2-irogers@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
tools/perf/util/evsel.c
tools/perf/util/evsel.h

index bc144388f89298f1ce752ea90005127654a2f308..026cf9a9893c3af8e673cf87c5f032173befb8c2 100644 (file)
@@ -237,6 +237,16 @@ set_methods:
        return 0;
 }
 
+const char *evsel__pmu_name(const struct evsel *evsel)
+{
+       struct perf_pmu *pmu = evsel__find_pmu(evsel);
+
+       if (pmu)
+               return pmu->name;
+
+       return event_type(evsel->core.attr.type);
+}
+
 #define FD(e, x, y) (*(int *)xyarray__entry(e->core.fd, x, y))
 
 int __evsel__sample_size(u64 sample_type)
index 5e789fa80590b6f43db702b5aba905fec7f29675..2dd108a14b894334852ff4a962c7bd4a4a38d2e5 100644 (file)
@@ -236,6 +236,7 @@ int evsel__object_config(size_t object_size,
                         void (*fini)(struct evsel *evsel));
 
 struct perf_pmu *evsel__find_pmu(const struct evsel *evsel);
+const char *evsel__pmu_name(const struct evsel *evsel);
 bool evsel__is_aux_event(const struct evsel *evsel);
 
 struct evsel *evsel__new_idx(struct perf_event_attr *attr, int idx);