Skip to contentSkip to conversation

perf evlist: Move the modifier after the slash when rename a hybrid event

PATCH New [email protected] 1 participant 1 message Dec 15, 2023 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf evlist: Move the modifier after the slash when rename a hybrid event

From: Kan Liang <[email protected]>

The event name shown in the perf top is wrong on a hybrid machine.
$perf top
1K cpu_atom/cycles:P/
11K cpu_core/cycles:P/

If using it on the command line:

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

The evlist__uniquify_name() changes a hybrid event name to "//" style. When using the "//" style, the event modifiers must be appended after the last "/".

Split the old name into event and modifier. Apply the correct format for the "//" style.

The patch fixes the same issue on the perf record as well.

---
 tools/perf/util/evlist.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
tools/perf/util/evlist.c +8 -3
index 6f0892803c22..83f4e3ec62d0 100644
@@ -2521,8 +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, *old_name, *modifier, *tmp;
 	struct evsel *pos;
-	char *new_name;
 	int ret;
 
 	if (perf_pmus__num_core_pmus() == 1)
@@ -2535,8 +2535,13 @@ void evlist__uniquify_name(struct evlist *evlist)
 		if (strchr(pos->name, '/'))
 			continue;
 
-		ret = asprintf(&new_name, "%s/%s/",
-			       pos->pmu_name, pos->name);
+		/* The event modifiers must be appended after "/" */
+		old_name = strtok_r(pos->name, ":", &tmp);
+		if (!old_name)
+			continue;
+		modifier = strtok_r(NULL, ":", &tmp);
+		ret = asprintf(&new_name, "%s/%s/%s",
+			       pos->pmu_name, old_name, !modifier ? "" : modifier);
 		if (ret) {
 			free(pos->name);
 			pos->name = new_name;
Signature · 1 line
2.35.1