Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1496098 > unrolled thread

[PATCH] perf, tools: Handle completion of upper case events

Started byAndi Kleen <andi@firstfloor.org>
First post2016-10-06 00:30 +0200
Last post2016-10-06 00:50 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] perf, tools: Handle completion of upper case events Andi Kleen <andi@firstfloor.org> - 2016-10-06 00:30 +0200
    Re: [PATCH] perf, tools: Handle completion of upper case events Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-10-06 00:50 +0200

#1496098 — [PATCH] perf, tools: Handle completion of upper case events

FromAndi Kleen <andi@firstfloor.org>
Date2016-10-06 00:30 +0200
Subject[PATCH] perf, tools: Handle completion of upper case events
Message-ID<sp2Rj-8d2-3@gated-at.bofh.it>
From: Andi Kleen <ak@linux.intel.com>

Vendor events are often specified in upper case. perf list outputs them
in lower case. Handle this case in perf-completion.sh so that
completion on the upper case events still works.

v2: Use locale aware check for upper case
Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
 tools/perf/perf-completion.sh | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/tools/perf/perf-completion.sh b/tools/perf/perf-completion.sh
index 3ba80b2359cc..3cb5a800b646 100644
--- a/tools/perf/perf-completion.sh
+++ b/tools/perf/perf-completion.sh
@@ -161,7 +161,11 @@ __perf_main ()
 	# List possible events for -e option
 	elif [[ $prev == @("-e"|"--event") &&
 		$prev_skip_opts == @(record|stat|top) ]]; then
-		evts=$($cmd list --raw-dump)
+		# handle upper case events
+		case "$cur" in
+			[[:upper:]]*) evts=$($cmd list --raw-dump | tr a-z A-Z) ;;
+			*) evts=$($cmd list --raw-dump) ;;
+		esac
 		__perfcomp_colon "$evts" "$cur"
 	else
 		# List subcommands for perf commands
-- 
2.5.5

[toc] | [next] | [standalone]


#1496107

FromArnaldo Carvalho de Melo <acme@kernel.org>
Date2016-10-06 00:50 +0200
Message-ID<sp3aF-8kc-1@gated-at.bofh.it>
In reply to#1496098
Em Wed, Oct 05, 2016 at 03:19:48PM -0700, Andi Kleen escreveu:
> From: Andi Kleen <ak@linux.intel.com>
> 
> Vendor events are often specified in upper case. perf list outputs them
> in lower case. Handle this case in perf-completion.sh so that
> completion on the upper case events still works.
> 
> v2: Use locale aware check for upper case
> Signed-off-by: Andi Kleen <ak@linux.intel.com>

Ok, this makes it work, but then:

[root@jouet ~]# perf stat -e CPU-<TAB>
CPU-CLOCK       CPU-CYCLES      CPU-MIGRATIONS  
[root@jouet ~]# perf stat -e CPU-CLOCK usleep 1
event syntax error: 'CPU-CLOCK'
                        \___ parser error
Run 'perf list' for a list of valid events

 Usage: perf stat [<options>] [<command>]

    -e, --event <event>   event selector. use 'perf list' to list available events
[root@jouet ~]# 

It now allows for non-JSON events to be tab completed only to then to
fail when passing it to perf.

We need to uppercase autocomplete only JSON events, that then gets
accepted by perf's event parser, i.e. you need something like:

		[[:upper:]]*) evts=$($cmd list --raw-dump JSON | tr a-z A-Z) ;;

Just like we have for other event types, for instance, for
PERF_TYPE_HARDWARE:

[acme@jouet linux]$ perf list --raw hw
branch-instructions branch-misses bus-cycles cache-misses cache-references cpu-cycles instructions ref-cycles

or software:

[acme@jouet linux]$ perf list --raw sw
alignment-faults bpf-output context-switches cpu-clock cpu-migrations dummy emulation-faults major-faults minor-faults page-faults task-clock 
[acme@jouet linux]$ 

That would be a nice fit as all events so far are lowercase, just these vendor
names are upper case.

- Arnaldo

> ---
>  tools/perf/perf-completion.sh | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/perf/perf-completion.sh b/tools/perf/perf-completion.sh
> index 3ba80b2359cc..3cb5a800b646 100644
> --- a/tools/perf/perf-completion.sh
> +++ b/tools/perf/perf-completion.sh
> @@ -161,7 +161,11 @@ __perf_main ()
>  	# List possible events for -e option
>  	elif [[ $prev == @("-e"|"--event") &&
>  		$prev_skip_opts == @(record|stat|top) ]]; then
> -		evts=$($cmd list --raw-dump)
> +		# handle upper case events
> +		case "$cur" in
> +			[[:upper:]]*) evts=$($cmd list --raw-dump | tr a-z A-Z) ;;
> +			*) evts=$($cmd list --raw-dump) ;;
> +		esac
>  		__perfcomp_colon "$evts" "$cur"
>  	else
>  		# List subcommands for perf commands
> -- 
> 2.5.5

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web