diff options
author | Yunlong Song <yunlong.song@huawei.com> | 2015-02-27 05:21:31 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2015-02-27 13:52:28 -0500 |
commit | 7335399a6a4bead9ef8b59ce7d811fc4e99ca98c (patch) | |
tree | 7c42d2c153742b6ef7568015f11b3f44e656b546 | |
parent | 5ef803ee02d67ad0b49f357cb7feb7d5e6b0015d (diff) |
perf tools: Fix the bash completion problem of 'perf --*'
The perf-completion.sh uses a predefined string '--help --version
--exec-path --html-path --paginate --no-pager --perf-dir --work-tree
--debugfs-dir' for the bash completion of 'perf --*', which has two
problems:
Problem 1: If the options of perf are changed (see handle_options() in
perf.c), the perf-completion.sh has to be changed at the same time. If
not, the bash completion of 'perf --*' and the options which perf
really supports will be inconsistent.
Problem 2: When typing another single character after 'perf --', e.g.
'h', and hit TAB key to get the bash completion of 'perf --h', the
character 'h' disappears at once. This is not what we want, we wish the
bash completion can return '--help --html-path' and then we can
continue to choose one.
To solve this problem, we add '--list-opts' to perf, which now supports
'perf --list-opts' directly, and its result can be used in bash
completion now.
Example:
Before this patch:
$ perf --h <-- hit TAB key after character 'h'
$ perf -- <-- 'h' disappears and no required result
After this patch:
$ perf --h <-- hit TAB key after character 'h'
--help --html-path <-- the required result
Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/r/1425032491-20224-8-git-send-email-yunlong.song@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/perf-completion.sh | 6 | ||||
-rw-r--r-- | tools/perf/perf.c | 27 |
2 files changed, 29 insertions, 4 deletions
diff --git a/tools/perf/perf-completion.sh b/tools/perf/perf-completion.sh index 33569847fdcc..c2595e9bd69b 100644 --- a/tools/perf/perf-completion.sh +++ b/tools/perf/perf-completion.sh | |||
@@ -110,13 +110,11 @@ __perf_main () | |||
110 | # List perf subcommands or long options | 110 | # List perf subcommands or long options |
111 | if [ $cword -eq 1 ]; then | 111 | if [ $cword -eq 1 ]; then |
112 | if [[ $cur == --* ]]; then | 112 | if [[ $cur == --* ]]; then |
113 | __perfcomp '--help --version \ | 113 | cmds=$($cmd --list-opts) |
114 | --exec-path --html-path --paginate --no-pager \ | ||
115 | --perf-dir --work-tree --debugfs-dir' -- "$cur" | ||
116 | else | 114 | else |
117 | cmds=$($cmd --list-cmds) | 115 | cmds=$($cmd --list-cmds) |
118 | __perfcomp "$cmds" "$cur" | ||
119 | fi | 116 | fi |
117 | __perfcomp "$cmds" "$cur" | ||
120 | # List possible events for -e option | 118 | # List possible events for -e option |
121 | elif [[ $prev == "-e" && "${words[1]}" == @(record|stat|top) ]]; then | 119 | elif [[ $prev == "-e" && "${words[1]}" == @(record|stat|top) ]]; then |
122 | evts=$($cmd list --raw-dump) | 120 | evts=$($cmd list --raw-dump) |
diff --git a/tools/perf/perf.c b/tools/perf/perf.c index 3df2665022be..b857fcbd00cf 100644 --- a/tools/perf/perf.c +++ b/tools/perf/perf.c | |||
@@ -13,6 +13,7 @@ | |||
13 | #include "util/quote.h" | 13 | #include "util/quote.h" |
14 | #include "util/run-command.h" | 14 | #include "util/run-command.h" |
15 | #include "util/parse-events.h" | 15 | #include "util/parse-events.h" |
16 | #include "util/parse-options.h" | ||
16 | #include "util/debug.h" | 17 | #include "util/debug.h" |
17 | #include <api/fs/debugfs.h> | 18 | #include <api/fs/debugfs.h> |
18 | #include <pthread.h> | 19 | #include <pthread.h> |
@@ -125,6 +126,23 @@ static void commit_pager_choice(void) | |||
125 | } | 126 | } |
126 | } | 127 | } |
127 | 128 | ||
129 | struct option options[] = { | ||
130 | OPT_ARGUMENT("help", "help"), | ||
131 | OPT_ARGUMENT("version", "version"), | ||
132 | OPT_ARGUMENT("exec-path", "exec-path"), | ||
133 | OPT_ARGUMENT("html-path", "html-path"), | ||
134 | OPT_ARGUMENT("paginate", "paginate"), | ||
135 | OPT_ARGUMENT("no-pager", "no-pager"), | ||
136 | OPT_ARGUMENT("perf-dir", "perf-dir"), | ||
137 | OPT_ARGUMENT("work-tree", "work-tree"), | ||
138 | OPT_ARGUMENT("debugfs-dir", "debugfs-dir"), | ||
139 | OPT_ARGUMENT("buildid-dir", "buildid-dir"), | ||
140 | OPT_ARGUMENT("list-cmds", "list-cmds"), | ||
141 | OPT_ARGUMENT("list-opts", "list-opts"), | ||
142 | OPT_ARGUMENT("debug", "debug"), | ||
143 | OPT_END() | ||
144 | }; | ||
145 | |||
128 | static int handle_options(const char ***argv, int *argc, int *envchanged) | 146 | static int handle_options(const char ***argv, int *argc, int *envchanged) |
129 | { | 147 | { |
130 | int handled = 0; | 148 | int handled = 0; |
@@ -225,6 +243,15 @@ static int handle_options(const char ***argv, int *argc, int *envchanged) | |||
225 | } | 243 | } |
226 | putchar('\n'); | 244 | putchar('\n'); |
227 | exit(0); | 245 | exit(0); |
246 | } else if (!strcmp(cmd, "--list-opts")) { | ||
247 | unsigned int i; | ||
248 | |||
249 | for (i = 0; i < ARRAY_SIZE(options)-1; i++) { | ||
250 | struct option *p = options+i; | ||
251 | printf("--%s ", p->long_name); | ||
252 | } | ||
253 | putchar('\n'); | ||
254 | exit(0); | ||
228 | } else if (!strcmp(cmd, "--debug")) { | 255 | } else if (!strcmp(cmd, "--debug")) { |
229 | if (*argc < 2) { | 256 | if (*argc < 2) { |
230 | fprintf(stderr, "No variable specified for --debug.\n"); | 257 | fprintf(stderr, "No variable specified for --debug.\n"); |