]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
perf list: Skip ABI PMUs when printing pmu values
authorIan Rogers <irogers@google.com>
Fri, 25 Jul 2025 18:51:53 +0000 (11:51 -0700)
committerNamhyung Kim <namhyung@kernel.org>
Sat, 26 Jul 2025 23:31:43 +0000 (16:31 -0700)
Avoid printing tracepoint, legacy and software events when listing for
the pmu option. Add the PMU type to the print_event callbacks to ease
detection.

Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Link: https://lore.kernel.org/r/20250725185202.68671-8-irogers@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
tools/perf/builtin-list.c
tools/perf/util/pfm.c
tools/perf/util/pmus.c
tools/perf/util/print-events.c
tools/perf/util/print-events.h

index 3a4061d02f6cfcf7afb37535ac80b273ac424d9d..caf42276bd0f5e20c1d8a31faeeb8b01309ccdbb 100644 (file)
@@ -58,6 +58,8 @@ struct print_state {
        bool metrics;
        /** @metricgroups: Controls printing of metric and metric groups. */
        bool metricgroups;
+       /** @exclude_abi: Exclude PMUs with types less than PERF_TYPE_MAX except PERF_TYPE_RAW. */
+       bool exclude_abi;
        /** @last_topic: The last printed event topic. */
        char *last_topic;
        /** @last_metricgroups: The last printed metric group. */
@@ -113,7 +115,8 @@ static void wordwrap(FILE *fp, const char *s, int start, int max, int corr)
        }
 }
 
-static void default_print_event(void *ps, const char *topic, const char *pmu_name,
+static void default_print_event(void *ps, const char *topic,
+                               const char *pmu_name, u32 pmu_type,
                                const char *event_name, const char *event_alias,
                                const char *scale_unit __maybe_unused,
                                bool deprecated, const char *event_type_desc,
@@ -130,6 +133,9 @@ static void default_print_event(void *ps, const char *topic, const char *pmu_nam
        if (print_state->pmu_glob && pmu_name && !strglobmatch(pmu_name, print_state->pmu_glob))
                return;
 
+       if (print_state->exclude_abi && pmu_type < PERF_TYPE_MAX && pmu_type != PERF_TYPE_RAW)
+               return;
+
        if (print_state->event_glob &&
            (!event_name || !strglobmatch(event_name, print_state->event_glob)) &&
            (!event_alias || !strglobmatch(event_alias, print_state->event_glob)) &&
@@ -354,7 +360,8 @@ static void fix_escape_fprintf(FILE *fp, struct strbuf *buf, const char *fmt, ..
        fputs(buf->buf, fp);
 }
 
-static void json_print_event(void *ps, const char *topic, const char *pmu_name,
+static void json_print_event(void *ps, const char *topic,
+                            const char *pmu_name, u32 pmu_type __maybe_unused,
                             const char *event_name, const char *event_alias,
                             const char *scale_unit,
                             bool deprecated, const char *event_type_desc,
@@ -647,9 +654,11 @@ int cmd_list(int argc, const char **argv)
                } else if (strcmp(argv[i], "cache") == 0 ||
                         strcmp(argv[i], "hwcache") == 0)
                        print_hwcache_events(&print_cb, ps);
-               else if (strcmp(argv[i], "pmu") == 0)
+               else if (strcmp(argv[i], "pmu") == 0) {
+                       default_ps.exclude_abi = true;
                        perf_pmus__print_pmu_events(&print_cb, ps);
-               else if (strcmp(argv[i], "sdt") == 0)
+                       default_ps.exclude_abi = false;
+               } else if (strcmp(argv[i], "sdt") == 0)
                        print_sdt_events(&print_cb, ps);
                else if (strcmp(argv[i], "metric") == 0 || strcmp(argv[i], "metrics") == 0) {
                        default_ps.metricgroups = false;
index e89395814e88be92066012fa08f4939376533d66..e5b3a2a5ddef5b6ded7daf91d6597b74192469b0 100644 (file)
@@ -230,6 +230,7 @@ print_libpfm_event(const struct print_callbacks *print_cb, void *print_state,
 
        if (is_libpfm_event_supported(name, cpus, threads)) {
                print_cb->print_event(print_state, topic, pinfo->name,
+                                     /*pmu_type=*/PERF_TYPE_RAW,
                                      name, info->equiv,
                                      /*scale_unit=*/NULL,
                                      /*deprecated=*/NULL, "PFM event",
@@ -265,6 +266,7 @@ print_libpfm_event(const struct print_callbacks *print_cb, void *print_state,
                        print_cb->print_event(print_state,
                                        topic,
                                        pinfo->name,
+                                       /*pmu_type=*/PERF_TYPE_RAW,
                                        name, /*alias=*/NULL,
                                        /*scale_unit=*/NULL,
                                        /*deprecated=*/NULL, "PFM event",
index 9137bb9036ed8a0ac01f051b0c7db41420338d3b..98be2eb8f1f03923d36ad4f022bb8f28a6eb6072 100644 (file)
@@ -645,6 +645,7 @@ void perf_pmus__print_pmu_events(const struct print_callbacks *print_cb, void *p
                print_cb->print_event(print_state,
                                aliases[j].topic,
                                aliases[j].pmu_name,
+                               aliases[j].pmu->type,
                                aliases[j].name,
                                aliases[j].alias,
                                aliases[j].scale_unit,
@@ -749,6 +750,7 @@ void perf_pmus__print_raw_pmu_events(const struct print_callbacks *print_cb, voi
                print_cb->print_event(print_state,
                                /*topic=*/NULL,
                                /*pmu_name=*/NULL,
+                               pmu->type,
                                format_args.short_string.buf,
                                /*event_alias=*/NULL,
                                /*scale_unit=*/NULL,
index 3a5e5e7bae134ca7c94ca9aa1ad8ab3de0f24e8e..4153124a9948ee678789aae6fa64b8ecdb36e1ef 100644 (file)
@@ -121,6 +121,7 @@ void print_sdt_events(const struct print_callbacks *print_cb, void *print_state)
                print_cb->print_event(print_state,
                                /*topic=*/NULL,
                                /*pmu_name=*/NULL,
+                               PERF_TYPE_TRACEPOINT,
                                evt_name ?: sdt_name->s,
                                /*event_alias=*/NULL,
                                /*deprecated=*/false,
@@ -222,6 +223,7 @@ int print_hwcache_events(const struct print_callbacks *print_cb, void *print_sta
                                        print_cb->print_event(print_state,
                                                        "cache",
                                                        pmu->name,
+                                                       pmu->type,
                                                        name,
                                                        alias_name,
                                                        /*scale_unit=*/NULL,
@@ -278,6 +280,7 @@ void print_symbol_events(const struct print_callbacks *print_cb, void *print_sta
                print_cb->print_event(print_state,
                                /*topic=*/NULL,
                                /*pmu_name=*/NULL,
+                               type,
                                nd->s,
                                alias,
                                /*scale_unit=*/NULL,
@@ -438,6 +441,7 @@ void print_events(const struct print_callbacks *print_cb, void *print_state)
        print_cb->print_event(print_state,
                        /*topic=*/NULL,
                        /*pmu_name=*/NULL,
+                       PERF_TYPE_RAW,
                        "rNNN",
                        /*event_alias=*/NULL,
                        /*scale_unit=*/NULL,
@@ -452,6 +456,7 @@ void print_events(const struct print_callbacks *print_cb, void *print_state)
        print_cb->print_event(print_state,
                        /*topic=*/NULL,
                        /*pmu_name=*/NULL,
+                       PERF_TYPE_BREAKPOINT,
                        "mem:<addr>[/len][:access]",
                        /*scale_unit=*/NULL,
                        /*event_alias=*/NULL,
index 4d95b8257e23e772b72bfb806008e87f6a43b068..d6ba384f0c66594f87f9d63c30fc2c7c6f2e9c3c 100644 (file)
@@ -12,7 +12,7 @@ struct print_callbacks {
        void (*print_start)(void *print_state);
        void (*print_end)(void *print_state);
        void (*print_event)(void *print_state, const char *topic,
-                       const char *pmu_name,
+                       const char *pmu_name, u32 pmu_type,
                        const char *event_name, const char *event_alias,
                        const char *scale_unit,
                        bool deprecated, const char *event_type_desc,