perf tools: Basic bash completion support v2
cover perf tools: Basic bash completion support v2
Changes since v1:
- Reuse the perf binary of the user to send the "perf --list-cmds" and "perf list --raw-dump" instead of the default one. (suggested by David Ahern)
- Install in DESTDIR_SQ (suggested by David Ahern)
- Protect $cur under quotes on compgen cmdline (suggested by Alan Cox)
Frederic Weisbecker (2):
perf tools: Initial bash completion support
perf tools: Support for events bash completion
tools/perf/Makefile | 1 + tools/perf/bash_completion | 26 +++++++++++++++ tools/perf/builtin-list.c | 14 ++++--- tools/perf/perf.c | 69 ++++++++++++++++++++++----------------- tools/perf/util/parse-events.c | 70 +++++++++++++++++++++++++--------------- tools/perf/util/parse-events.h | 7 ++-- 6 files changed, 122 insertions(+), 65 deletions(-) create mode 100644 tools/perf/bash_completion
Signature · 1 line
1.7.5.4
PATCH 1/2 perf tools: Initial bash completion support
This implements bash completion for perf subcommands such as record, report, script, probe, etc...
--- tools/perf/Makefile | 1 + tools/perf/bash_completion | 22 ++++++++++++++ tools/perf/perf.c | 69 +++++++++++++++++++++++++------------------- 3 files changed, 62 insertions(+), 30 deletions(-) create mode 100644 tools/perf/bash_completion
tools/perf/Makefile +1 -0
@@ -951,6 +951,7 @@ install: all $(INSTALL) scripts/python/Perf-Trace-Util/lib/Perf/Trace/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/Perf-Trace-Util/lib/Perf/Trace' $(INSTALL) scripts/python/*.py -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python' $(INSTALL) scripts/python/bin/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/bin' + $(INSTALL) -m 755 bash_completion $(DESTDIR_SQ)/etc/bash_completion.d/perf install-python_ext: $(PYTHON_WORD) util/setup.py --quiet install --root='/$(DESTDIR_SQ)'
tools/perf/bash_completion new file +22 -0
@@ -0,0 +1,22 @@ +# perf completion + +have perf && +_perf() +{ + local cur cmd + + COMPREPLY=() + _get_comp_words_by_ref cur + + cmd=${COMP_WORDS[0]} + + # List perf subcommands + if [ $COMP_CWORD -eq 1 ]; then + cmds=$($cmd --list-cmds) + COMPREPLY=( $( compgen -W '$cmds' -- "$cur" ) ) + # Fall down to list regular files + else + _filedir + fi +} && +complete -F _perf perf
tools/perf/perf.c +39 -30
93 lines not on this page · raw message
Signature · 1 line
1.7.5.4
PATCH 2/2 perf tools: Support for events bash completion
In reply to Frederic WeisbeckerAdd basic bash completion for the -e option in record, top and stat subcommands. Only hardware, software and tracepoint events are supported.
Breakpoints, raw events and events grouping completion need more thinking.
--- tools/perf/bash_completion | 6 +++- tools/perf/builtin-list.c | 14 ++++--- tools/perf/util/parse-events.c | 70 +++++++++++++++++++++++++--------------- tools/perf/util/parse-events.h | 7 ++-- 4 files changed, 61 insertions(+), 36 deletions(-)
tools/perf/bash_completion +5 -1
@@ -6,7 +6,7 @@ _perf() local cur cmd COMPREPLY=() - _get_comp_words_by_ref cur + _get_comp_words_by_ref cur prev cmd=${COMP_WORDS[0]}
@@ -14,6 +14,10 @@ _perf() if [ $COMP_CWORD -eq 1 ]; then cmds=$($cmd --list-cmds) COMPREPLY=( $( compgen -W '$cmds' -- "$cur" ) ) + # List possible events for -e option + elif [[ $prev == "-e" && "${COMP_WORDS[1]}" == @(record|stat|top) ]]; then + cmds=$($cmd list --raw-dump) + COMPREPLY=( $( compgen -W '$cmds' -- "$cur" ) ) # Fall down to list regular files else _filedir
tools/perf/builtin-list.c +8 -6
@@ -19,15 +19,15 @@ int cmd_list(int argc, const char **argv, const char *prefix __used)setup_pager ();if (argc ==1 ) -print_events (NULL ); +print_events (NULL , false);else {int i;for (i =1 ; i < argc; ++i) { -if (i >1 ) +if (i >2 )putchar ('\n' );if (strncmp (argv[i],"tracepoint" ,10 ) ==0 ) -print_tracepoint_events (NULL ,NULL ); +print_tracepoint_events (NULL ,NULL , false);else if (strcmp (argv[i],"hw" ) ==0 ||strcmp (argv[i],"hardware" ) ==0 )print_events_type (PERF_TYPE_HARDWARE );
@@ -36,13 +36,15 @@ int cmd_list(int argc, const char **argv, const char *prefix __used)print_events_type (PERF_TYPE_SOFTWARE ); else if (strcmp(argv[i], "cache") == 0 || strcmp(argv[i], "hwcache") == 0) - print_hwcache_events(NULL); + print_hwcache_events(NULL, false); + else if (strcmp(argv[i], "--raw-dump") == 0) + print_events(NULL, true); else { char *sep = strchr(argv[i], ':'), *s; int sep_idx; if (sep == NULL) { - print_events(argv[i]); + print_events(argv[i], false); continue; } sep_idx = sep - argv[i];
@@ -51,7 +53,7 @@ int cmd_list(int argc, const char **argv, const char *prefix __used)return -1 ; s[sep_idx] ='\0' ; -print_tracepoint_events (s, s + sep_idx +1 ); +print_tracepoint_events (s, s + sep_idx +1 , false);free (s); } }
tools/perf/util/parse-events.c +44 -26
124 lines not on this page · raw message
tools/perf/util/parse-events.h +4 -3
@@ -96,10 +96,11 @@ void parse_events_update_lists(struct list_head *list_event,void parse_events_error (void *data,void *scanner,char const *msg);int parse_events__test (void ); -void print_events (const char *event_glob); +void print_events (const char *event_glob,bool name_only);void print_events_type (u8 type); -void print_tracepoint_events (const char *subsys_glob,const char *event_glob); -int print_hwcache_events (const char *event_glob); +void print_tracepoint_events (const char *subsys_glob,const char *event_glob, +bool name_only); +int print_hwcache_events (const char *event_glob,bool name_only);extern int is_valid_tracepoint (const char *event_string);extern int valid_debugfs_mount (const char *debugfs);
Signature · 1 line
1.7.5.4
Re: [PATCH 1/2] perf tools: Initial bash completion support
In reply to Frederic Weisbeckertools/perf/Makefile install: all · line 954
Quoted 9 lines · Frederic Weisbecker
tools/perf/Makefile +1
-0@@ -951,6 +951,7 @@ install: all $(INSTALL) scripts/python/Perf-Trace-Util/lib/Perf/Trace/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/Perf-Trace-Util/lib/Perf/Trace' $(INSTALL) scripts/python/*.py -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python' $(INSTALL) scripts/python/bin/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/bin' + $(INSTALL) -m 755 bash_completion $(DESTDIR_SQ)/etc/bash_completion.d/perf
still getting an error here:
$ make DESTDIR=/tmp/junk-perf O=/tmp/pbuild -C tools/perf/ install ... install -m 755 bash_completion /tmp/junk-perf/etc/bash_completion.d/perf install: cannot create regular file `/tmp/junk-perf/etc/bash_completion.d/perf': No such file or directory make: *** [install] Error 1 make: Leaving directory `/opt/sw/ahern/perf.git/tools/perf'
Namhyung Kim
maintainerRe: [PATCH 1/2] perf tools: Initial bash completion support
Quoted 13 lines · David Ahern
tools/perf/Makefile install: all · line 954
Quoted 9 lines · Frederic Weisbecker
tools/perf/Makefile +1
-0@@ -951,6 +951,7 @@ install: all $(INSTALL) scripts/python/Perf-Trace-Util/lib/Perf/Trace/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/Perf-Trace-Util/lib/Perf/Trace' $(INSTALL) scripts/python/*.py -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python' $(INSTALL) scripts/python/bin/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/bin' + $(INSTALL) -m 755 bash_completion $(DESTDIR_SQ)/etc/bash_completion.d/perfstill getting an error here:
Quoted 7 lines
$ make DESTDIR=/tmp/junk-perf O=/tmp/pbuild -C tools/perf/ install ... install -m 755 bash_completion /tmp/junk-perf/etc/bash_completion.d/perf install: cannot create regular file /tmp/junk-perf/etc/bash_completion.d/perf': No such file or directory make: *** [install] Error 1 make: Leaving directory `/opt/sw/ahern/perf.git/tools/perf'
Does patch below fix it?
tools/perf/Makefile +3 -1
@@ -696,6 +696,7 @@ perfexecdir_SQ = $(subst ','\'',$(perfexecdir)) template_dir_SQ = $(subst ','\'',$(template_dir)) htmldir_SQ = $(subst ','\'',$(htmldir)) prefix_SQ = $(subst ','\'',$(prefix)) +sysconfdir_SQ = $(subst ','\'',$(sysconfdir)) SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
@@ -947,7 +948,8 @@ install: all $(INSTALL) scripts/python/Perf-Trace-Util/lib/Perf/Trace/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/Perf-Trace-Util/lib/Perf/Trace' $(INSTALL) scripts/python/*.py -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python' $(INSTALL) scripts/python/bin/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/bin' - $(INSTALL) -m 755 bash_completion $(DESTDIR_SQ)/etc/bash_completion.d/perf + $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(sysconfdir_SQ)/bash_completion.d' + $(INSTALL) bash_completion '$(DESTDIR_SQ)$(sysconfdir_SQ)/bash_completion.d/perf' install-python_ext: $(PYTHON_WORD) util/setup.py --quiet install --root='/$(DESTDIR_SQ)'
Re: [PATCH 1/2] perf tools: Initial bash completion support
Quoted 22 lines · Namhyung Kim
Quoted 13 lines · David Ahern
tools/perf/Makefile install: all · line 954
Quoted 9 lines · Frederic Weisbecker
tools/perf/Makefile +1
-0@@ -951,6 +951,7 @@ install: all $(INSTALL) scripts/python/Perf-Trace-Util/lib/Perf/Trace/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/Perf-Trace-Util/lib/Perf/Trace' $(INSTALL) scripts/python/*.py -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python' $(INSTALL) scripts/python/bin/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/bin' + $(INSTALL) -m 755 bash_completion $(DESTDIR_SQ)/etc/bash_completion.d/perfstill getting an error here:
Quoted 7 lines
$ make DESTDIR=/tmp/junk-perf O=/tmp/pbuild -C tools/perf/ install ... install -m 755 bash_completion /tmp/junk-perf/etc/bash_completion.d/perf install: cannot create regular file /tmp/junk-perf/etc/bash_completion.d/perf': No such file or directory make: *** [install] Error 1 make: Leaving directory `/opt/sw/ahern/perf.git/tools/perf'
Quoted 1 line
Does patch below fix it?
Of course. I was too lazy to do that; one liner for Frederic to add - though the sysconfdir integration is nice.
David
Re: [PATCH 1/2] perf tools: Initial bash completion support
In reply to Namhyung KimQuoted 22 lines · Namhyung Kim
Quoted 13 lines · David Ahern
tools/perf/Makefile install: all · line 954
Quoted 9 lines · Frederic Weisbecker
tools/perf/Makefile +1
-0@@ -951,6 +951,7 @@ install: all $(INSTALL) scripts/python/Perf-Trace-Util/lib/Perf/Trace/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/Perf-Trace-Util/lib/Perf/Trace' $(INSTALL) scripts/python/*.py -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python' $(INSTALL) scripts/python/bin/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/bin' + $(INSTALL) -m 755 bash_completion $(DESTDIR_SQ)/etc/bash_completion.d/perfstill getting an error here:
Quoted 7 lines
$ make DESTDIR=/tmp/junk-perf O=/tmp/pbuild -C tools/perf/ install ... install -m 755 bash_completion /tmp/junk-perf/etc/bash_completion.d/perf install: cannot create regular file /tmp/junk-perf/etc/bash_completion.d/perf': No such file or directory make: *** [install] Error 1 make: Leaving directory `/opt/sw/ahern/perf.git/tools/perf'
Quoted 1 line
Does patch below fix it?
Thanks Namhyung.
Can I have your signed-off-by to add this patch on my series?
Thanks.
Quoted 24 lines
tools/perf/Makefile +3
-1@@ -696,6 +696,7 @@ perfexecdir_SQ = $(subst ','\'',$(perfexecdir)) template_dir_SQ = $(subst ','\'',$(template_dir)) htmldir_SQ = $(subst ','\'',$(htmldir)) prefix_SQ = $(subst ','\'',$(prefix)) +sysconfdir_SQ = $(subst ','\'',$(sysconfdir)) SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))@@ -947,7 +948,8 @@ install: all $(INSTALL) scripts/python/Perf-Trace-Util/lib/Perf/Trace/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/Perf-Trace-Util/lib/Perf/Trace' $(INSTALL) scripts/python/*.py -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python' $(INSTALL) scripts/python/bin/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/bin' - $(INSTALL) -m 755 bash_completion $(DESTDIR_SQ)/etc/bash_completion.d/perf + $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(sysconfdir_SQ)/bash_completion.d' + $(INSTALL) bash_completion '$(DESTDIR_SQ)$(sysconfdir_SQ)/bash_completion.d/perf' install-python_ext: $(PYTHON_WORD) util/setup.py --quiet install --root='/$(DESTDIR_SQ)'
Namhyung Kim
maintainerRe: [PATCH 1/2] perf tools: Initial bash completion support
Hi, Frederic
Quoted 23 lines · Frederic Weisbecker
Quoted 22 lines · Namhyung Kim
Quoted 20 lines · David Ahern
tools/perf/Makefile install: all · line 954
Quoted 9 lines · Frederic Weisbecker
tools/perf/Makefile +1
-0@@ -951,6 +951,7 @@ install: all $(INSTALL) scripts/python/Perf-Trace-Util/lib/Perf/Trace/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/Perf-Trace-Util/lib/Perf/Trace' $(INSTALL) scripts/python/*.py -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python' $(INSTALL) scripts/python/bin/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/bin' + $(INSTALL) -m 755 bash_completion $(DESTDIR_SQ)/etc/bash_completion.d/perfstill getting an error here:
$ make DESTDIR=/tmp/junk-perf O=/tmp/pbuild -C tools/perf/ install ... install -m 755 bash_completion /tmp/junk-perf/etc/bash_completion.d/perf install: cannot create regular file /tmp/junk-perf/etc/bash_completion.d/perf': No such file or directory make: *** [install] Error 1 make: Leaving directory `/opt/sw/ahern/perf.git/tools/perf'
Quoted 6 lines
Quoted 1 line
Does patch below fix it?
Thanks Namhyung.
Can I have your signed-off-by to add this patch on my series?
Sure thing.
Thanks,
Namhyung
Quoted 25 lines
Quoted 25 lines
tools/perf/Makefile +3
-1@@ -696,6 +696,7 @@ perfexecdir_SQ = $(subst ','\'',$(perfexecdir)) template_dir_SQ = $(subst ','\'',$(template_dir)) htmldir_SQ = $(subst ','\'',$(htmldir)) prefix_SQ = $(subst ','\'',$(prefix)) +sysconfdir_SQ = $(subst ','\'',$(sysconfdir)) SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))@@ -947,7 +948,8 @@ install: all $(INSTALL) scripts/python/Perf-Trace-Util/lib/Perf/Trace/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/Perf-Trace-Util/lib/Perf/Trace' $(INSTALL) scripts/python/*.py -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python' $(INSTALL) scripts/python/bin/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/bin' - $(INSTALL) -m 755 bash_completion $(DESTDIR_SQ)/etc/bash_completion.d/perf + $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(sysconfdir_SQ)/bash_completion.d' + $(INSTALL) bash_completion '$(DESTDIR_SQ)$(sysconfdir_SQ)/bash_completion.d/perf' install-python_ext: $(PYTHON_WORD) util/setup.py --quiet install --root='/$(DESTDIR_SQ)'