aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJin Yao <yao.jin@linux.intel.com>2017-12-21 04:26:10 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2017-12-27 10:15:59 -0500
commit74cd5815d9af6e6c4f3bcecfbc8e439f2fd7e6b1 (patch)
tree63164895ffe17135e53dec6017da12e86c8a6c70
parentf1031c8d33a8c40d4cac26e58c37d9fba0e31a8a (diff)
perf tool: Improve bash command line auto-complete for multiple events with comma
perf has perf-completion.sh to define command line auto-completion in bash/zsh. For record/stat -e it works for single events, but isn't working when specifying multiple events with comma. It would be very useful if it could be fixed to make it easier by supporting multiple events, comma separated. With this patch, the result can be like this: 1. Support the events returned from 'perf list --raw-dump' root@skl:/tmp# perf stat -e cpu/cache<TAB> cpu/cache-misses/ cpu/cache-references/ root@skl:/tmp# perf stat -e cpu/cache-misses/,cpu/branch-<TAB> cpu/branch-instructions/ cpu/branch-misses/ root@skl:/tmp# perf stat -e cpu/cache-misses/,cpu/branch-i<TAB> root@skl:/tmp# perf stat -e cpu/cache-misses/,cpu/branch-instructions/ 2. Support the events listed in /sys/bus/event_source/devices/cpu/events root@skl:/tmp# perf stat -e cycle<TAB> cycle_activity.cycles_l1d_miss cycle_activity.stalls_l3_miss cycle_activity.cycles_l2_miss cycle_activity.stalls_mem_any cycle_activity.cycles_l3_miss cycle_activity.stalls_total cycle_activity.cycles_mem_any cycles-ct cycle_activity.stalls_l1d_miss cycles-t cycle_activity.stalls_l2_miss root@skl:/tmp# perf stat -e cycles-<TAB> cycles-ct cycles-t root@skl:/tmp# perf stat -e cycles-t,cpu/c<TAB> cpu/cache-misses/ cpu/cpu-cycles/ cpu/cycles-t/ cpu/cache-references/ cpu/cycles-ct/ root@skl:/tmp# perf stat -e cycles-t,cpu/cache-<TAB> cpu/cache-misses/ cpu/cache-references/ root@skl:/tmp# perf stat -e cycles-t,cpu/cache-misses/ 3. Support the uppercase event which is with prefix "cpu/" root@skl:/tmp# perf stat -e cpu/c<TAB> cpu/cache-misses/ cpu/cpu-cycles/ cpu/cycles-t/ cpu/cache-references/ cpu/cycles-ct/ root@skl:/tmp# perf stat -e cpu/cache-misses/,cpu/C<TAB> cpu/CACHE-MISSES/ cpu/CPU-CYCLES/ cpu/CYCLES-T/ cpu/CACHE-REFERENCES/ cpu/CYCLES-CT/ root@skl:/tmp# perf stat -e cpu/cache-misses/,cpu/CACHE-REFERENCES/ Note that: a) This patch only supports bash. b) It doesn't support the cases like {},{} or {...,...}. Signed-off-by: Jin Yao <yao.jin@linux.intel.com> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Kan Liang <kan.liang@intel.com> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/1513848370-8098-1-git-send-email-yao.jin@linux.intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/perf-completion.sh38
1 files changed, 34 insertions, 4 deletions
diff --git a/tools/perf/perf-completion.sh b/tools/perf/perf-completion.sh
index 345f5d6e9ed5..d8310830a18b 100644
--- a/tools/perf/perf-completion.sh
+++ b/tools/perf/perf-completion.sh
@@ -162,8 +162,33 @@ __perf_main ()
162 # List possible events for -e option 162 # List possible events for -e option
163 elif [[ $prev == @("-e"|"--event") && 163 elif [[ $prev == @("-e"|"--event") &&
164 $prev_skip_opts == @(record|stat|top) ]]; then 164 $prev_skip_opts == @(record|stat|top) ]]; then
165 evts=$($cmd list --raw-dump) 165
166 __perfcomp_colon "$evts" "$cur" 166 local cur1=${COMP_WORDS[COMP_CWORD]}
167 local raw_evts=$($cmd list --raw-dump)
168 local arr s tmp result
169
170 if [[ "$cur1" == */* && ${cur1#*/} =~ ^[A-Z] ]]; then
171 OLD_IFS="$IFS"
172 IFS=" "
173 arr=($raw_evts)
174 IFS="$OLD_IFS"
175
176 for s in ${arr[@]}
177 do
178 if [[ "$s" == *cpu/* ]]; then
179 tmp=${s#*cpu/}
180 result=$result" ""cpu/"${tmp^^}
181 else
182 result=$result" "$s
183 fi
184 done
185
186 evts=${result}+$(ls /sys/bus/event_source/devices/cpu/events)
187 else
188 evts=${raw_evts}+$(ls /sys/bus/event_source/devices/cpu/events)
189 fi
190
191 __perfcomp_colon "$evts" "$cur1"
167 else 192 else
168 # List subcommands for perf commands 193 # List subcommands for perf commands
169 if [[ $prev_skip_opts == @(kvm|kmem|mem|lock|sched| 194 if [[ $prev_skip_opts == @(kvm|kmem|mem|lock|sched|
@@ -246,11 +271,16 @@ fi
246type perf &>/dev/null && 271type perf &>/dev/null &&
247_perf() 272_perf()
248{ 273{
274 if [[ "$COMP_WORDBREAKS" != *,* ]]; then
275 COMP_WORDBREAKS="${COMP_WORDBREAKS},"
276 export COMP_WORDBREAKS
277 fi
278
249 local cur words cword prev 279 local cur words cword prev
250 if [ $preload_get_comp_words_by_ref = "true" ]; then 280 if [ $preload_get_comp_words_by_ref = "true" ]; then
251 _get_comp_words_by_ref -n =: cur words cword prev 281 _get_comp_words_by_ref -n =:, cur words cword prev
252 else 282 else
253 __perf_get_comp_words_by_ref -n =: cur words cword prev 283 __perf_get_comp_words_by_ref -n =:, cur words cword prev
254 fi 284 fi
255 __perf_main 285 __perf_main
256} && 286} &&