diff options
| author | Ian Rogers <[email protected]> | 2023-08-25 13:52:37 +0000 |
|---|---|---|
| committer | Arnaldo Carvalho de Melo <[email protected]> | 2023-08-29 17:16:14 +0000 |
| commit | cd4e1efbbc4037c440b84f6be5aff8938c204c9c (patch) | |
| tree | 83d07cc0b15adca10403a4264af89a8103e8630d /tools/perf/util/pmu.c | |
| parent | perf pmus: Sort pmus by name then suffix (diff) | |
| download | kernel-cd4e1efbbc4037c440b84f6be5aff8938c204c9c.tar.gz kernel-cd4e1efbbc4037c440b84f6be5aff8938c204c9c.zip | |
perf pmus: Skip duplicate PMUs and don't print list suffix by default
Add a PMUs scan that ignores duplicates. When there are multiple PMUs
that differ only by suffix, by default just list the first one and
skip all others. The scan routine checks that the PMU names match but
doesn't enforce that the numbers are consecutive as for some PMUs
there are gaps. If "-v" is passed to "perf list" then list all PMUs.
With the previous change duplicate PMUs are no longer printed but the
suffix of the first is printed. When duplicate PMUs are being skipped
avoid printing the suffix.
Before:
$ perf list
...
uncore_imc_free_running_0/data_read/ [Kernel PMU event]
uncore_imc_free_running_0/data_total/ [Kernel PMU event]
uncore_imc_free_running_0/data_write/ [Kernel PMU event]
uncore_imc_free_running_1/data_read/ [Kernel PMU event]
uncore_imc_free_running_1/data_total/ [Kernel PMU event]
uncore_imc_free_running_1/data_write/ [Kernel PMU event]
After:
$ perf list
...
uncore_imc_free_running/data_read/ [Kernel PMU event]
uncore_imc_free_running/data_total/ [Kernel PMU event]
uncore_imc_free_running/data_write/ [Kernel PMU event]
...
$ perf list -v
uncore_imc_free_running_0/data_read/ [Kernel PMU event]
uncore_imc_free_running_0/data_total/ [Kernel PMU event]
uncore_imc_free_running_0/data_write/ [Kernel PMU event]
uncore_imc_free_running_1/data_read/ [Kernel PMU event]
uncore_imc_free_running_1/data_total/ [Kernel PMU event]
uncore_imc_free_running_1/data_write/ [Kernel PMU event]
...
Reviewed-by: Kan Liang <[email protected]>
Signed-off-by: Ian Rogers <[email protected]>
Cc: Adrian Hunter <[email protected]>
Cc: Alexander Shishkin <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: John Garry <[email protected]>
Cc: Kajol Jain <[email protected]>
Cc: Mark Rutland <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Ravi Bangoria <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
Diffstat (limited to 'tools/perf/util/pmu.c')
| -rw-r--r-- | tools/perf/util/pmu.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index b92dc7237f3b..502fd58c3ea7 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -1578,7 +1578,9 @@ int perf_pmu__find_event(struct perf_pmu *pmu, const char *event, void *state, p .cb = cb, }; - return perf_pmu__for_each_event(pmu, &args, find_event_callback); + /* Sub-optimal, but function is only used by tests. */ + return perf_pmu__for_each_event(pmu, /*skip_duplicate_pmus=*/ false, + &args, find_event_callback); } static void perf_pmu__del_formats(struct list_head *formats) @@ -1652,10 +1654,13 @@ static int sub_non_neg(int a, int b) } static char *format_alias(char *buf, int len, const struct perf_pmu *pmu, - const struct perf_pmu_alias *alias) + const struct perf_pmu_alias *alias, bool skip_duplicate_pmus) { struct parse_events_term *term; - int used = snprintf(buf, len, "%s/%s", pmu->name, alias->name); + int pmu_name_len = skip_duplicate_pmus + ? pmu_name_len_no_suffix(pmu->name, /*num=*/NULL) + : (int)strlen(pmu->name); + int used = snprintf(buf, len, "%.*s/%s", pmu_name_len, pmu->name, alias->name); list_for_each_entry(term, &alias->terms, list) { if (term->type_val == PARSE_EVENTS__TERM_TYPE_STR) @@ -1677,7 +1682,8 @@ static char *format_alias(char *buf, int len, const struct perf_pmu *pmu, return buf; } -int perf_pmu__for_each_event(struct perf_pmu *pmu, void *state, pmu_event_callback cb) +int perf_pmu__for_each_event(struct perf_pmu *pmu, bool skip_duplicate_pmus, + void *state, pmu_event_callback cb) { char buf[1024]; struct perf_pmu_alias *event; @@ -1696,7 +1702,8 @@ int perf_pmu__for_each_event(struct perf_pmu *pmu, void *state, pmu_event_callba info.name = event->name; buf_used = 0; } else { - info.name = format_alias(buf, sizeof(buf), pmu, event); + info.name = format_alias(buf, sizeof(buf), pmu, event, + skip_duplicate_pmus); if (pmu->is_core) { info.alias = info.name; info.name = event->name; |
