Skip to contentSkip to conversation

perf, tools, list: Print aliases with --raw-dump

PATCH In review Andi Kleen 3 participants 4 messages Sep 18, 2016 – Sep 19, 2016 perf events

lore
Share & tools
lore

Andi Kleen

author
#0 lore raw

PATCH 1/2 perf, tools, list: Print aliases with --raw-dump

From: Andi Kleen <[email protected]>

Print aliases like 'cycles' with perf list --raw-dump, so that they can be completed by perf-completion.sh

---
 tools/perf/util/parse-events.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
tools/perf/util/parse-events.c +9 -1
index 94846271cb1c..9716c2bc6869 100644
@@ -2191,13 +2191,21 @@ restart:
 
 		if (!evt_num_known) {
 			evt_num++;
+			if (strlen(syms->alias))
+				evt_num++;
 			continue;
 		}
 
 		if (!name_only && strlen(syms->alias))
 			snprintf(name, MAX_NAME_LEN, "%s OR %s", syms->symbol, syms->alias);
-		else
+		else {
+			if (strlen(syms->alias)) {
+				evt_list[evt_i++] = strdup(syms->alias);
+				if (evt_list[evt_i - 1]  == NULL)
+					goto out_enomem;
+			}
 			strncpy(name, syms->symbol, MAX_NAME_LEN);
+		}
 
 		evt_list[evt_i] = strdup(name);
 		if (evt_list[evt_i] == NULL)
Signature · 1 line
2.5.5
author
#1 lore raw

PATCH 2/2 perf, tools: Fix completion script to handle comma list

From: Andi Kleen <[email protected]>

The perf event completion script only handled a single event per -e option. So for "perf stat -e cycles,branches" branches could not be completed.

Fix that issue by always only using the last suffix.

For some reason it only works in bash currently, but zsh is the same as before.

---
 tools/perf/perf-completion.sh | 4 ++++
 1 file changed, 4 insertions(+)
tools/perf/perf-completion.sh +4 -0
index 3ba80b2359cc..14c2be73b6fd 100644
@@ -162,7 +162,11 @@ __perf_main ()
 	elif [[ $prev == @("-e"|"--event") &&
 		$prev_skip_opts == @(record|stat|top) ]]; then
 		evts=$($cmd list --raw-dump)
+		old="$cur"
+		cur="${cur/*[,{]/}"
+		prefix=${old%$cur}
 		__perfcomp_colon "$evts" "$cur"
+		COMPREPLY=("${prefix}${COMPREPLY[0]}")
 	else
 		# List subcommands for perf commands
 		if [[ $prev_skip_opts == @(kvm|kmem|mem|lock|sched|
Signature · 1 line
2.5.5
#2 lore raw
In reply to Andi Kleen
Quoted 19 lines · Andi Kleen

From: Andi Kleen <[email protected]>

Print aliases like 'cycles' with perf list --raw-dump, so that they can be completed by perf-completion.sh

---
 tools/perf/util/parse-events.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
tools/perf/util/parse-events.c +1 -0
index 94846271cb1c..9716c2bc6869 100644
@@ -2191,13 +2191,21 @@ restart:
 
 		if (!evt_num_known) {
 			evt_num++;
+			if (strlen(syms->alias))

tools/perf/util/parse-events.c restart: · line 2203

Quoted 10 lines
tools/perf/util/parse-events.c +4 -1
+				evt_num++;
 			continue;
 		}
 
 		if (!name_only && strlen(syms->alias))
 			snprintf(name, MAX_NAME_LEN, "%s OR %s", syms->symbol, syms->alias);
-		else
+		else {
+			if (strlen(syms->alias)) {
+				evt_list[evt_i++] = strdup(syms->alias);

why don't you copy syms->alias into name and let the code below do the queue?

thanks,
jirka

Quoted 11 lines
tools/perf/util/parse-events.c +4 -0
+				if (evt_list[evt_i - 1]  == NULL)
+					goto out_enomem;
+			}
 			strncpy(name, syms->symbol, MAX_NAME_LEN);
+		}
 
 		evt_list[evt_i] = strdup(name);
 		if (evt_list[evt_i] == NULL)
Signature · 1 line
2.5.5
#3 lore raw
Quoted 1 line

why don't you copy syms->alias into name and let the code below do the queue?

Because it needs to queue two entries, not just a single one.

-Andi