diff options
author | Frederic Weisbecker <fweisbec@gmail.com> | 2012-08-09 10:31:51 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-08-09 14:58:51 -0400 |
commit | 98a4179c9aa1e99adf5103e6e0d05f563d902de1 (patch) | |
tree | 7dc88426528560f39e48b51df305677879e2385a | |
parent | d25dcba8541c1cc31621d5cefce0304dafb9ae4f (diff) |
perf tools: Initial bash completion support
This implements bash completion for perf subcommands such as record,
report, script, probe, etc...
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1344522713-27951-2-git-send-email-fweisbec@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/Makefile | 1 | ||||
-rw-r--r-- | tools/perf/bash_completion | 22 | ||||
-rw-r--r-- | tools/perf/perf.c | 69 |
3 files changed, 62 insertions, 30 deletions
diff --git a/tools/perf/Makefile b/tools/perf/Makefile index 2d4bf6ef1c5a..84b422786949 100644 --- a/tools/perf/Makefile +++ b/tools/perf/Makefile | |||
@@ -951,6 +951,7 @@ install: all | |||
951 | $(INSTALL) scripts/python/Perf-Trace-Util/lib/Perf/Trace/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/Perf-Trace-Util/lib/Perf/Trace' | 951 | $(INSTALL) scripts/python/Perf-Trace-Util/lib/Perf/Trace/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/Perf-Trace-Util/lib/Perf/Trace' |
952 | $(INSTALL) scripts/python/*.py -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python' | 952 | $(INSTALL) scripts/python/*.py -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python' |
953 | $(INSTALL) scripts/python/bin/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/bin' | 953 | $(INSTALL) scripts/python/bin/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/bin' |
954 | $(INSTALL) -m 755 bash_completion $(DESTDIR_SQ)/etc/bash_completion.d/perf | ||
954 | 955 | ||
955 | install-python_ext: | 956 | install-python_ext: |
956 | $(PYTHON_WORD) util/setup.py --quiet install --root='/$(DESTDIR_SQ)' | 957 | $(PYTHON_WORD) util/setup.py --quiet install --root='/$(DESTDIR_SQ)' |
diff --git a/tools/perf/bash_completion b/tools/perf/bash_completion new file mode 100644 index 000000000000..9a31fa5ed2a9 --- /dev/null +++ b/tools/perf/bash_completion | |||
@@ -0,0 +1,22 @@ | |||
1 | # perf completion | ||
2 | |||
3 | have perf && | ||
4 | _perf() | ||
5 | { | ||
6 | local cur cmd | ||
7 | |||
8 | COMPREPLY=() | ||
9 | _get_comp_words_by_ref cur | ||
10 | |||
11 | cmd=${COMP_WORDS[0]} | ||
12 | |||
13 | # List perf subcommands | ||
14 | if [ $COMP_CWORD -eq 1 ]; then | ||
15 | cmds=$($cmd --list-cmds) | ||
16 | COMPREPLY=( $( compgen -W '$cmds' -- "$cur" ) ) | ||
17 | # Fall down to list regular files | ||
18 | else | ||
19 | _filedir | ||
20 | fi | ||
21 | } && | ||
22 | complete -F _perf perf | ||
diff --git a/tools/perf/perf.c b/tools/perf/perf.c index 2b2e225a4d4c..db37ee3f29b8 100644 --- a/tools/perf/perf.c +++ b/tools/perf/perf.c | |||
@@ -24,6 +24,37 @@ const char perf_more_info_string[] = | |||
24 | int use_browser = -1; | 24 | int use_browser = -1; |
25 | static int use_pager = -1; | 25 | static int use_pager = -1; |
26 | 26 | ||
27 | struct cmd_struct { | ||
28 | const char *cmd; | ||
29 | int (*fn)(int, const char **, const char *); | ||
30 | int option; | ||
31 | }; | ||
32 | |||
33 | static struct cmd_struct commands[] = { | ||
34 | { "buildid-cache", cmd_buildid_cache, 0 }, | ||
35 | { "buildid-list", cmd_buildid_list, 0 }, | ||
36 | { "diff", cmd_diff, 0 }, | ||
37 | { "evlist", cmd_evlist, 0 }, | ||
38 | { "help", cmd_help, 0 }, | ||
39 | { "list", cmd_list, 0 }, | ||
40 | { "record", cmd_record, 0 }, | ||
41 | { "report", cmd_report, 0 }, | ||
42 | { "bench", cmd_bench, 0 }, | ||
43 | { "stat", cmd_stat, 0 }, | ||
44 | { "timechart", cmd_timechart, 0 }, | ||
45 | { "top", cmd_top, 0 }, | ||
46 | { "annotate", cmd_annotate, 0 }, | ||
47 | { "version", cmd_version, 0 }, | ||
48 | { "script", cmd_script, 0 }, | ||
49 | { "sched", cmd_sched, 0 }, | ||
50 | { "probe", cmd_probe, 0 }, | ||
51 | { "kmem", cmd_kmem, 0 }, | ||
52 | { "lock", cmd_lock, 0 }, | ||
53 | { "kvm", cmd_kvm, 0 }, | ||
54 | { "test", cmd_test, 0 }, | ||
55 | { "inject", cmd_inject, 0 }, | ||
56 | }; | ||
57 | |||
27 | struct pager_config { | 58 | struct pager_config { |
28 | const char *cmd; | 59 | const char *cmd; |
29 | int val; | 60 | int val; |
@@ -160,6 +191,14 @@ static int handle_options(const char ***argv, int *argc, int *envchanged) | |||
160 | fprintf(stderr, "dir: %s\n", debugfs_mountpoint); | 191 | fprintf(stderr, "dir: %s\n", debugfs_mountpoint); |
161 | if (envchanged) | 192 | if (envchanged) |
162 | *envchanged = 1; | 193 | *envchanged = 1; |
194 | } else if (!strcmp(cmd, "--list-cmds")) { | ||
195 | unsigned int i; | ||
196 | |||
197 | for (i = 0; i < ARRAY_SIZE(commands); i++) { | ||
198 | struct cmd_struct *p = commands+i; | ||
199 | printf("%s ", p->cmd); | ||
200 | } | ||
201 | exit(0); | ||
163 | } else { | 202 | } else { |
164 | fprintf(stderr, "Unknown option: %s\n", cmd); | 203 | fprintf(stderr, "Unknown option: %s\n", cmd); |
165 | usage(perf_usage_string); | 204 | usage(perf_usage_string); |
@@ -245,12 +284,6 @@ const char perf_version_string[] = PERF_VERSION; | |||
245 | */ | 284 | */ |
246 | #define NEED_WORK_TREE (1<<2) | 285 | #define NEED_WORK_TREE (1<<2) |
247 | 286 | ||
248 | struct cmd_struct { | ||
249 | const char *cmd; | ||
250 | int (*fn)(int, const char **, const char *); | ||
251 | int option; | ||
252 | }; | ||
253 | |||
254 | static int run_builtin(struct cmd_struct *p, int argc, const char **argv) | 287 | static int run_builtin(struct cmd_struct *p, int argc, const char **argv) |
255 | { | 288 | { |
256 | int status; | 289 | int status; |
@@ -296,30 +329,6 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv) | |||
296 | static void handle_internal_command(int argc, const char **argv) | 329 | static void handle_internal_command(int argc, const char **argv) |
297 | { | 330 | { |
298 | const char *cmd = argv[0]; | 331 | const char *cmd = argv[0]; |
299 | static struct cmd_struct commands[] = { | ||
300 | { "buildid-cache", cmd_buildid_cache, 0 }, | ||
301 | { "buildid-list", cmd_buildid_list, 0 }, | ||
302 | { "diff", cmd_diff, 0 }, | ||
303 | { "evlist", cmd_evlist, 0 }, | ||
304 | { "help", cmd_help, 0 }, | ||
305 | { "list", cmd_list, 0 }, | ||
306 | { "record", cmd_record, 0 }, | ||
307 | { "report", cmd_report, 0 }, | ||
308 | { "bench", cmd_bench, 0 }, | ||
309 | { "stat", cmd_stat, 0 }, | ||
310 | { "timechart", cmd_timechart, 0 }, | ||
311 | { "top", cmd_top, 0 }, | ||
312 | { "annotate", cmd_annotate, 0 }, | ||
313 | { "version", cmd_version, 0 }, | ||
314 | { "script", cmd_script, 0 }, | ||
315 | { "sched", cmd_sched, 0 }, | ||
316 | { "probe", cmd_probe, 0 }, | ||
317 | { "kmem", cmd_kmem, 0 }, | ||
318 | { "lock", cmd_lock, 0 }, | ||
319 | { "kvm", cmd_kvm, 0 }, | ||
320 | { "test", cmd_test, 0 }, | ||
321 | { "inject", cmd_inject, 0 }, | ||
322 | }; | ||
323 | unsigned int i; | 332 | unsigned int i; |
324 | static const char ext[] = STRIP_EXTENSION; | 333 | static const char ext[] = STRIP_EXTENSION; |
325 | 334 | ||