[PATCH 1/1] perf evlist: Move event attributes to after the / when uniquefying using the PMU name

From: Arnaldo Carvalho de Melo
Date: Fri Dec 15 2023 - 13:23:30 EST


When turning an event with attributes to the format including the PMU we
need to move the "event:attributes" format to "event/attributes/" so
that we can copy the event displayed and use it in the command line,
i.e. in 'perf top' we had:

1K cpu_atom/cycles:P/
11K cpu_core/cycles:P/

If I try to use that on the command line:

# perf top -e cpu_atom/cycles:P/
event syntax error: 'cpu_atom/cycles:P/'
\___ Bad event or PMU

Unable to find PMU or event on a PMU of 'cpu_atom'

Initial error:
event syntax error: 'cpu_atom/cycles:P/'
\___ unknown term 'cycles:P' for pmu
'cpu_atom'

valid terms:

event,pc,edge,offcore_rsp,ldlat,inv,umask,cmask,config,config1,config2,config3,name,period,freq,branch_type,time,call-graph,stack-size,no-inherit,inherit,max-stack,nr,no-overwrite,overwrite ,driver-config,percore,aux-output,aux-sample-size,metric-id,raw,legacy-cache,hardware
Run
'perf list' for a list of valid events

Usage: perf top [<options>]

-e, --event <event> event selector. use 'perf list' to list available events
#

Cc: Hector Martin <marcan@xxxxxxxxx>
Cc: Ian Rogers <irogers@xxxxxxxxxx>
Cc: Kan Liang <kan.liang@xxxxxxxxxxxxxxx>
Cc: Marc Zyngier <maz@xxxxxxxxxx>
Cc: Mark Rutland <mark.rutland@xxxxxxx>
Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
Link: https://lore.kernel.org/lkml/ZXxyanyZgWBTOnoK@xxxxxxxxxx
Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
---
tools/perf/util/evlist.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 6f0892803c2249af..95f25e9fb994ab2a 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -2521,9 +2521,8 @@ void evlist__warn_user_requested_cpus(struct evlist *evlist, const char *cpu_lis

void evlist__uniquify_name(struct evlist *evlist)
{
+ char *new_name, empty_attributes[2] = ":", *attributes;
struct evsel *pos;
- char *new_name;
- int ret;

if (perf_pmus__num_core_pmus() == 1)
return;
@@ -2535,11 +2534,17 @@ void evlist__uniquify_name(struct evlist *evlist)
if (strchr(pos->name, '/'))
continue;

- ret = asprintf(&new_name, "%s/%s/",
- pos->pmu_name, pos->name);
- if (ret) {
+ attributes = strchr(pos->name, ':');
+ if (attributes)
+ *attributes = '\0';
+ else
+ attributes = empty_attributes;
+
+ if (asprintf(&new_name, "%s/%s/%s", pos->pmu_name, pos->name, attributes + 1)) {
free(pos->name);
pos->name = new_name;
+ } else {
+ *attributes = ':';
}
}
}
--
2.43.0