perf tools: Add the bash completion for listing subsubcommands of perf trace
authorYunlong Song <yunlong.song@huawei.com>
Wed, 18 Mar 2015 13:35:57 +0000 (21:35 +0800)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 19 Mar 2015 16:53:26 +0000 (13:53 -0300)
The bash completion does not support listing subsubcommands for 'perf
trace <TAB>', so fix it.

Example:

Before this patch:

 $ perf trace <TAB>
 $

As shown above, the subsubcommands of perf trace does not come out.

After this patch:

 $ perf trace <TAB>
 record

As shown above, the subsubcommands of perf trace can come out now.

Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
Tested-by: Arnaldo Carvalho de Melo <acme@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/1426685758-25488-13-git-send-email-yunlong.song@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-trace.c
tools/perf/perf-completion.sh

index 6969ba98ff2fd94e3724d1d540b9c788b37a2667..0b3b4e4984b9aaf5569520fbacbb02f26d6b10b8 100644 (file)
@@ -2609,7 +2609,7 @@ static void evlist__set_evsel_handler(struct perf_evlist *evlist, void *handler)
 
 int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused)
 {
-       const char * const trace_usage[] = {
+       const char *trace_usage[] = {
                "perf trace [<options>] [<command>]",
                "perf trace [<options>] -- <command> [<options>]",
                "perf trace record [<options>] [<command>]",
@@ -2684,6 +2684,7 @@ int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused)
        OPT_BOOLEAN(0, "syscalls", &trace.trace_syscalls, "Trace syscalls"),
        OPT_END()
        };
+       const char * const trace_subcommands[] = { "record", NULL };
        int err;
        char bf[BUFSIZ];
 
@@ -2699,8 +2700,8 @@ int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused)
                goto out;
        }
 
-       argc = parse_options(argc, argv, trace_options, trace_usage,
-                            PARSE_OPT_STOP_AT_NON_OPTION);
+       argc = parse_options_subcommand(argc, argv, trace_options, trace_subcommands,
+                                trace_usage, PARSE_OPT_STOP_AT_NON_OPTION);
 
        if (trace.trace_pgfaults) {
                trace.opts.sample_address = true;
index a33d2ef53ae4ddb03cb5caebd9337dcaf2c2e4da..bdd40350870ae1b190f6b84eed1fc1dfd7f01a3f 100644 (file)
@@ -120,6 +120,7 @@ __perf_prev_skip_opts ()
                ((i--))
        done
 }
+
 __perf_main ()
 {
        local cmd
@@ -137,13 +138,15 @@ __perf_main ()
                        cmds=$($cmd --list-cmds)
                fi
                __perfcomp "$cmds" "$cur"
-       # List possible events for -e and --event option
-       elif [[ $prev == @("-e"|"--event") && $prev_skip_opts == @(record|stat|top) ]]; then
+       # List possible events for -e option
+       elif [[ $prev == @("-e"|"--event") &&
+               $prev_skip_opts == @(record|stat|top) ]]; then
                evts=$($cmd list --raw-dump)
                __perfcomp_colon "$evts" "$cur"
        else
                # List subcommands for perf commands
-               if [[ $prev_skip_opts == @(kvm|kmem|mem|lock|sched|data|help|script|test|timechart) ]]; then
+               if [[ $prev_skip_opts == @(kvm|kmem|mem|lock|sched|
+                       |data|help|script|test|timechart|trace) ]]; then
                        subcmds=$($cmd $prev_skip_opts --list-cmds)
                        __perfcomp_colon "$subcmds" "$cur"
                fi