linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/13] perf tools: Make some improvements and fixes
@ 2015-03-18 13:35 Yunlong Song
  2015-03-18 13:35 ` [PATCH 01/13] perf tools: Fix the bash completion for listing options of perf subcommand Yunlong Song
                   ` (12 more replies)
  0 siblings, 13 replies; 27+ messages in thread
From: Yunlong Song @ 2015-03-18 13:35 UTC (permalink / raw)
  To: a.p.zijlstra, paulus, mingo, acme; +Cc: linux-kernel, wangnan0

Hi,
  Found some functions to improve and bugs to fix in perf bash
  completion.

Yunlong Song (13):
  perf tools: Fix the bash completion for listing options of perf    
    subcommand
  perf tools: Fix the bash completion for listing subsubcommands of perf
        subcommand
  perf tools: Provide the right bash completion for listing options of  
      perf subcommand subsubcommand
  perf tools: Fix the bash completion for listing events of perf
    subcommand     record|stat|top -e
  perf tools: Fix the bash completion to support listing events for    
    --event
  perf tools: Fix the bash completion for listing subcommands of perf
  perf tools: Add the bash completion for listing subsubcommands of perf
        data
  perf tools: Add the bash completion for listing subsubcommands of perf
        help
  perf tools: Add the bash completion for listing subsubcommands of perf
        script
  perf tools: Add the bash completion for listing subsubcommands of perf
        test
  perf tools: Add the bash completion for listing subsubcommands of perf
        timechart
  perf tools: Add the bash completion for listing subsubcommands of perf
        trace
  perf tools: Avoid confusion with preloaded bash function for perf    
    bash completion

 tools/perf/builtin-data.c       |  6 ++-
 tools/perf/builtin-help.c       | 17 ++++++--
 tools/perf/builtin-script.c     |  5 ++-
 tools/perf/builtin-timechart.c  |  7 ++--
 tools/perf/builtin-trace.c      |  7 ++--
 tools/perf/perf-completion.sh   | 88 +++++++++++++++++++++++++++++++++--------
 tools/perf/tests/builtin-test.c |  5 ++-
 7 files changed, 103 insertions(+), 32 deletions(-)

-- 
1.8.5.2


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 01/13] perf tools: Fix the bash completion for listing options of perf subcommand
  2015-03-18 13:35 [PATCH 00/13] perf tools: Make some improvements and fixes Yunlong Song
@ 2015-03-18 13:35 ` Yunlong Song
  2015-03-22 10:09   ` [tip:perf/core] " tip-bot for Yunlong Song
  2015-03-18 13:35 ` [PATCH 02/13] perf tools: Fix the bash completion for listing subsubcommands " Yunlong Song
                   ` (11 subsequent siblings)
  12 siblings, 1 reply; 27+ messages in thread
From: Yunlong Song @ 2015-03-18 13:35 UTC (permalink / raw)
  To: a.p.zijlstra, paulus, mingo, acme; +Cc: linux-kernel, wangnan0

The bash completion does not support listing options for 'perf
kvm|kmem|mem|lock|sched --<TAB>', where 'kvm|kmem|mem|lock|sched' are
all subcommands of perf.

Example:

Before this patch:

 $ perf kvm --<TAB>
 $

As shown above, the options of perf kvm does not come out.

After this patch:

 $ perf kvm --<TAB>
 --alloc    --caller   --input    --line     --raw-ip   --sort
 --verbose

As shown above, the options of perf kvm can come out now.

Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
---
 tools/perf/perf-completion.sh | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/tools/perf/perf-completion.sh b/tools/perf/perf-completion.sh
index c2595e9..4822ed3 100644
--- a/tools/perf/perf-completion.sh
+++ b/tools/perf/perf-completion.sh
@@ -119,15 +119,18 @@ __perf_main ()
 	elif [[ $prev == "-e" && "${words[1]}" == @(record|stat|top) ]]; then
 		evts=$($cmd list --raw-dump)
 		__perfcomp_colon "$evts" "$cur"
-	# List subcommands for perf commands
-	elif [[ $prev == @(kvm|kmem|mem|lock|sched) ]]; then
-		subcmds=$($cmd $prev --list-cmds)
-		__perfcomp_colon "$subcmds" "$cur"
-	# List long option names
-	elif [[ $cur == --* ]];  then
-		subcmd=${words[1]}
-		opts=$($cmd $subcmd --list-opts)
-		__perfcomp "$opts" "$cur"
+	else
+		# List subcommands for perf commands
+		if [[ $prev == @(kvm|kmem|mem|lock|sched) ]]; then
+			subcmds=$($cmd $prev --list-cmds)
+			__perfcomp_colon "$subcmds" "$cur"
+		fi
+		# List long option names
+		if [[ $cur == --* ]];  then
+			subcmd=${words[1]}
+			opts=$($cmd $subcmd --list-opts)
+			__perfcomp "$opts" "$cur"
+		fi
 	fi
 }
 
-- 
1.8.5.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 02/13] perf tools: Fix the bash completion for listing subsubcommands of perf subcommand
  2015-03-18 13:35 [PATCH 00/13] perf tools: Make some improvements and fixes Yunlong Song
  2015-03-18 13:35 ` [PATCH 01/13] perf tools: Fix the bash completion for listing options of perf subcommand Yunlong Song
@ 2015-03-18 13:35 ` Yunlong Song
  2015-03-22 10:09   ` [tip:perf/core] " tip-bot for Yunlong Song
  2015-03-18 13:35 ` [PATCH 03/13] perf tools: Provide the right bash completion for listing options of perf subcommand subsubcommand Yunlong Song
                   ` (10 subsequent siblings)
  12 siblings, 1 reply; 27+ messages in thread
From: Yunlong Song @ 2015-03-18 13:35 UTC (permalink / raw)
  To: a.p.zijlstra, paulus, mingo, acme; +Cc: linux-kernel, wangnan0

The bash completion does not support listing subsubcommands for 'perf
kvm|kmem|mem|lock|sched --<long option> <TAB>', where 'kvm|kmem|mem|
lock|sched' are all subcommands of perf.

Example:

Before this patch:

 $ perf kvm --verbose <TAB>
 $

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

After this patch:

 $ perf kvm --verbose <TAB>
 buildid-list  diff          record        report        stat
 top

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

Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
---
 tools/perf/perf-completion.sh | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/tools/perf/perf-completion.sh b/tools/perf/perf-completion.sh
index 4822ed3..bbb61d0 100644
--- a/tools/perf/perf-completion.sh
+++ b/tools/perf/perf-completion.sh
@@ -100,6 +100,23 @@ __perfcomp_colon ()
 	__ltrim_colon_completions $cur
 }
 
+__perf_prev_skip_opts ()
+{
+	local i cmd_ cmds_
+
+	let i=cword-1
+	cmds_=$($cmd --list-cmds)
+	prev_skip_opts=()
+	while [ $i -ge 0 ]; do
+		for cmd_ in $cmds_; do
+			if [[ ${words[i]} == $cmd_ ]]; then
+				prev_skip_opts=${words[i]}
+				return
+			fi
+		done
+		((i--))
+	done
+}
 __perf_main ()
 {
 	local cmd
@@ -107,6 +124,8 @@ __perf_main ()
 	cmd=${words[0]}
 	COMPREPLY=()
 
+	# Skip options backward and find the last perf command
+	__perf_prev_skip_opts
 	# List perf subcommands or long options
 	if [ $cword -eq 1 ]; then
 		if [[ $cur == --* ]]; then
@@ -121,8 +140,8 @@ __perf_main ()
 		__perfcomp_colon "$evts" "$cur"
 	else
 		# List subcommands for perf commands
-		if [[ $prev == @(kvm|kmem|mem|lock|sched) ]]; then
-			subcmds=$($cmd $prev --list-cmds)
+		if [[ $prev_skip_opts == @(kvm|kmem|mem|lock|sched) ]]; then
+			subcmds=$($cmd $prev_skip_opts --list-cmds)
 			__perfcomp_colon "$subcmds" "$cur"
 		fi
 		# List long option names
-- 
1.8.5.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 03/13] perf tools: Provide the right bash completion for listing options of perf subcommand subsubcommand
  2015-03-18 13:35 [PATCH 00/13] perf tools: Make some improvements and fixes Yunlong Song
  2015-03-18 13:35 ` [PATCH 01/13] perf tools: Fix the bash completion for listing options of perf subcommand Yunlong Song
  2015-03-18 13:35 ` [PATCH 02/13] perf tools: Fix the bash completion for listing subsubcommands " Yunlong Song
@ 2015-03-18 13:35 ` Yunlong Song
  2015-03-22 10:09   ` [tip:perf/core] " tip-bot for Yunlong Song
  2015-03-18 13:35 ` [PATCH 04/13] perf tools: Fix the bash completion for listing events of perf subcommand record|stat|top -e Yunlong Song
                   ` (9 subsequent siblings)
  12 siblings, 1 reply; 27+ messages in thread
From: Yunlong Song @ 2015-03-18 13:35 UTC (permalink / raw)
  To: a.p.zijlstra, paulus, mingo, acme; +Cc: linux-kernel, wangnan0

The bash completion gives wrong options for 'perf kvm|kmem|mem|lock|
sched subsubcommand --<TAB>', where 'kvm|kmem|mem|lock|sched' are all
subcommands of perf and 'subsubcommand' is a subcommand of 'kvm|kmem|mem
|lock|sched'. In fact, the result incorrectly lists the bash completion
of 'perf subcommand' rather than 'perf subcommand subsubcommand'.

Example:

Before this patch:

 $ perf kvm record --<TAB>
 --guest          --guestkallsyms  --guestmodules   --guestmount
 --guestvmlinux   --host           --input          --output
 --verbose

As shown above, the result is the options of kvm rather than record.

After this patch:

 $ perf kvm record --<TAB>
 --all-cpus          --cgroup            --delay             --group
 --no-buildid        --output            --quiet             --stat
 --uid
 --branch-any        --count             --event             --intr-regs
 --no-buildid-cache  --period            --raw-samples       --tid
 --verbose
 --branch-filter     --cpu               --filter            --mmap-pages
 --no-inherit        --per-thread        --realtime          --timestamp
 --weight
 --call-graph        --data              --freq
 --no-buffering      --no-samples        --pid
 --running-time      --transaction

As shown above, the result is exactly the options of record as we wished.

Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
---
 tools/perf/perf-completion.sh | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/tools/perf/perf-completion.sh b/tools/perf/perf-completion.sh
index bbb61d0..01ce841 100644
--- a/tools/perf/perf-completion.sh
+++ b/tools/perf/perf-completion.sh
@@ -105,9 +105,12 @@ __perf_prev_skip_opts ()
 	local i cmd_ cmds_
 
 	let i=cword-1
-	cmds_=$($cmd --list-cmds)
+	cmds_=$($cmd $1 --list-cmds)
 	prev_skip_opts=()
 	while [ $i -ge 0 ]; do
+		if [[ ${words[i]} == $1 ]]; then
+			return
+		fi
 		for cmd_ in $cmds_; do
 			if [[ ${words[i]} == $cmd_ ]]; then
 				prev_skip_opts=${words[i]}
@@ -146,7 +149,9 @@ __perf_main ()
 		fi
 		# List long option names
 		if [[ $cur == --* ]];  then
-			subcmd=${words[1]}
+			subcmd=$prev_skip_opts
+			__perf_prev_skip_opts $subcmd
+			subcmd=$subcmd" "$prev_skip_opts
 			opts=$($cmd $subcmd --list-opts)
 			__perfcomp "$opts" "$cur"
 		fi
-- 
1.8.5.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 04/13] perf tools: Fix the bash completion for listing events of perf subcommand record|stat|top -e
  2015-03-18 13:35 [PATCH 00/13] perf tools: Make some improvements and fixes Yunlong Song
                   ` (2 preceding siblings ...)
  2015-03-18 13:35 ` [PATCH 03/13] perf tools: Provide the right bash completion for listing options of perf subcommand subsubcommand Yunlong Song
@ 2015-03-18 13:35 ` Yunlong Song
  2015-03-22 10:10   ` [tip:perf/core] " tip-bot for Yunlong Song
  2015-03-18 13:35 ` [PATCH 05/13] perf tools: Fix the bash completion to support listing events for --event Yunlong Song
                   ` (8 subsequent siblings)
  12 siblings, 1 reply; 27+ messages in thread
From: Yunlong Song @ 2015-03-18 13:35 UTC (permalink / raw)
  To: a.p.zijlstra, paulus, mingo, acme; +Cc: linux-kernel, wangnan0

The bash completion does not support listing events for 'perf kvm|kmem|
mem|lock|sched record|stat|top -e <TAB>', where 'kvm|kmem|mem|lock|sched'
are all subcommands of perf.

Example:

Before this patch:

 $ perf kvm record -e <TAB>
 $

As shown above, the events of record does not come out.

After this patch:

 $ perf kvm record -e <TAB>
 alignment-faults                   cpu/instructions/
 L1-dcache-prefetch-misses          node-prefetches
 uncore_rbox_0/qpi0_idle_filt/
 branch-instructions                cpu/mem-loads/
 L1-dcache-store-misses             node-prefetch-misses
 uncore_rbox_0/qpi1_date_response/
 branch-load-misses                 cpu-migrations
 L1-dcache-stores                   node-store-misses
 uncore_rbox_0/qpi1_filt_send/
 branch-loads                       dTLB-load-misses
 L1-icache-load-misses              node-stores
 uncore_rbox_0/qpi1_idle_filt/
 ...

As shown above, the events of record can come out now.

Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
---
 tools/perf/perf-completion.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/perf-completion.sh b/tools/perf/perf-completion.sh
index 01ce841..4b58ac2 100644
--- a/tools/perf/perf-completion.sh
+++ b/tools/perf/perf-completion.sh
@@ -138,7 +138,7 @@ __perf_main ()
 		fi
 		__perfcomp "$cmds" "$cur"
 	# List possible events for -e option
-	elif [[ $prev == "-e" && "${words[1]}" == @(record|stat|top) ]]; then
+	elif [[ $prev == "-e" && $prev_skip_opts == @(record|stat|top) ]]; then
 		evts=$($cmd list --raw-dump)
 		__perfcomp_colon "$evts" "$cur"
 	else
-- 
1.8.5.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 05/13] perf tools: Fix the bash completion to support listing events for --event
  2015-03-18 13:35 [PATCH 00/13] perf tools: Make some improvements and fixes Yunlong Song
                   ` (3 preceding siblings ...)
  2015-03-18 13:35 ` [PATCH 04/13] perf tools: Fix the bash completion for listing events of perf subcommand record|stat|top -e Yunlong Song
@ 2015-03-18 13:35 ` Yunlong Song
  2015-03-22 10:10   ` [tip:perf/core] " tip-bot for Yunlong Song
  2015-03-18 13:35 ` [PATCH 06/13] perf tools: Fix the bash completion for listing subcommands of perf Yunlong Song
                   ` (7 subsequent siblings)
  12 siblings, 1 reply; 27+ messages in thread
From: Yunlong Song @ 2015-03-18 13:35 UTC (permalink / raw)
  To: a.p.zijlstra, paulus, mingo, acme; +Cc: linux-kernel, wangnan0

The bash completion only supports -e rather than --event, so fix it.

Example:

Before this patch:

 $ perf record --event <TAB>
 $

As shown above, the events of record does not come out.

After this patch:

 $ perf record --event <TAB>
 lignment-faults                   cpu/instructions/
 L1-dcache-prefetch-misses          node-prefetches
 uncore_rbox_0/qpi0_idle_filt/
 branch-instructions                cpu/mem-loads/
 L1-dcache-store-misses             node-prefetch-misses
 uncore_rbox_0/qpi1_date_response/
 branch-load-misses                 cpu-migrations
 L1-dcache-stores                   node-store-misses
 uncore_rbox_0/qpi1_filt_send/
 branch-loads                       dTLB-load-misses
 L1-icache-load-misses              node-stores
 uncore_rbox_0/qpi1_idle_filt/
 ...

As shown above, the events of record can come out now.

Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
---
 tools/perf/perf-completion.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/perf-completion.sh b/tools/perf/perf-completion.sh
index 4b58ac2..3e25d3e 100644
--- a/tools/perf/perf-completion.sh
+++ b/tools/perf/perf-completion.sh
@@ -137,8 +137,8 @@ __perf_main ()
 			cmds=$($cmd --list-cmds)
 		fi
 		__perfcomp "$cmds" "$cur"
-	# List possible events for -e option
-	elif [[ $prev == "-e" && $prev_skip_opts == @(record|stat|top) ]]; then
+	# List possible events for -e and --event option
+	elif [[ $prev == @("-e"|"--event") && $prev_skip_opts == @(record|stat|top) ]]; then
 		evts=$($cmd list --raw-dump)
 		__perfcomp_colon "$evts" "$cur"
 	else
-- 
1.8.5.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 06/13] perf tools: Fix the bash completion for listing subcommands of perf
  2015-03-18 13:35 [PATCH 00/13] perf tools: Make some improvements and fixes Yunlong Song
                   ` (4 preceding siblings ...)
  2015-03-18 13:35 ` [PATCH 05/13] perf tools: Fix the bash completion to support listing events for --event Yunlong Song
@ 2015-03-18 13:35 ` Yunlong Song
  2015-03-22 10:10   ` [tip:perf/core] " tip-bot for Yunlong Song
  2015-03-18 13:35 ` [PATCH 07/13] perf tools: Add the bash completion for listing subsubcommands of perf data Yunlong Song
                   ` (6 subsequent siblings)
  12 siblings, 1 reply; 27+ messages in thread
From: Yunlong Song @ 2015-03-18 13:35 UTC (permalink / raw)
  To: a.p.zijlstra, paulus, mingo, acme; +Cc: linux-kernel, wangnan0

The bash completion does not support listing subcommands for 'perf
--<long option> <TAB>'.

Example:

Before this patch:

 $ perf --debug <TAB>
 $

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

After this patch:

 $ perf --debug <TAB>
 annotate       buildid-cache  data           evlist         inject
 kvm            lock           probe          report         script
 test           top            version
 bench          buildid-list   diff           help           kmem
 list           mem            record         sched          stat
 timechart      trace

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

Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
---
 tools/perf/perf-completion.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/perf-completion.sh b/tools/perf/perf-completion.sh
index 3e25d3e..7b98ae4 100644
--- a/tools/perf/perf-completion.sh
+++ b/tools/perf/perf-completion.sh
@@ -130,7 +130,7 @@ __perf_main ()
 	# Skip options backward and find the last perf command
 	__perf_prev_skip_opts
 	# List perf subcommands or long options
-	if [ $cword -eq 1 ]; then
+	if [ -z $prev_skip_opts ]; then
 		if [[ $cur == --* ]]; then
 			cmds=$($cmd --list-opts)
 		else
-- 
1.8.5.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 07/13] perf tools: Add the bash completion for listing subsubcommands of perf data
  2015-03-18 13:35 [PATCH 00/13] perf tools: Make some improvements and fixes Yunlong Song
                   ` (5 preceding siblings ...)
  2015-03-18 13:35 ` [PATCH 06/13] perf tools: Fix the bash completion for listing subcommands of perf Yunlong Song
@ 2015-03-18 13:35 ` Yunlong Song
  2015-03-22 10:11   ` [tip:perf/core] " tip-bot for Yunlong Song
  2015-03-18 13:35 ` [PATCH 08/13] perf tools: Add the bash completion for listing subsubcommands of perf help Yunlong Song
                   ` (5 subsequent siblings)
  12 siblings, 1 reply; 27+ messages in thread
From: Yunlong Song @ 2015-03-18 13:35 UTC (permalink / raw)
  To: a.p.zijlstra, paulus, mingo, acme; +Cc: linux-kernel, wangnan0

The bash completion does not support listing subsubcommands for 'perf
data <TAB>', so fix it.

Example:

Before this patch:

 $ perf data <TAB>
 $

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

After this patch:

 $ perf data <TAB>
 convert

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

Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
---
 tools/perf/builtin-data.c     | 6 ++++--
 tools/perf/perf-completion.sh | 2 +-
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/tools/perf/builtin-data.c b/tools/perf/builtin-data.c
index 155cf75..709152a 100644
--- a/tools/perf/builtin-data.c
+++ b/tools/perf/builtin-data.c
@@ -22,7 +22,9 @@ static const struct option data_options[] = {
 	OPT_END()
 };
 
-static const char * const data_usage[] = {
+static const char * const data_subcommands[] = { "convert", NULL };
+
+static const char *data_usage[] = {
 	"perf data [<common options>] <command> [<options>]",
 	NULL
 };
@@ -98,7 +100,7 @@ int cmd_data(int argc, const char **argv, const char *prefix)
 	if (argc < 2)
 		goto usage;
 
-	argc = parse_options(argc, argv, data_options, data_usage,
+	argc = parse_options_subcommand(argc, argv, data_options, data_subcommands, data_usage,
 			     PARSE_OPT_STOP_AT_NON_OPTION);
 	if (argc < 1)
 		goto usage;
diff --git a/tools/perf/perf-completion.sh b/tools/perf/perf-completion.sh
index 7b98ae4..535ff72 100644
--- a/tools/perf/perf-completion.sh
+++ b/tools/perf/perf-completion.sh
@@ -143,7 +143,7 @@ __perf_main ()
 		__perfcomp_colon "$evts" "$cur"
 	else
 		# List subcommands for perf commands
-		if [[ $prev_skip_opts == @(kvm|kmem|mem|lock|sched) ]]; then
+		if [[ $prev_skip_opts == @(kvm|kmem|mem|lock|sched|data) ]]; then
 			subcmds=$($cmd $prev_skip_opts --list-cmds)
 			__perfcomp_colon "$subcmds" "$cur"
 		fi
-- 
1.8.5.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 08/13] perf tools: Add the bash completion for listing subsubcommands of perf help
  2015-03-18 13:35 [PATCH 00/13] perf tools: Make some improvements and fixes Yunlong Song
                   ` (6 preceding siblings ...)
  2015-03-18 13:35 ` [PATCH 07/13] perf tools: Add the bash completion for listing subsubcommands of perf data Yunlong Song
@ 2015-03-18 13:35 ` Yunlong Song
  2015-03-22 10:11   ` [tip:perf/core] " tip-bot for Yunlong Song
  2015-03-18 13:35 ` [PATCH 09/13] perf tools: Add the bash completion for listing subsubcommands of perf script Yunlong Song
                   ` (4 subsequent siblings)
  12 siblings, 1 reply; 27+ messages in thread
From: Yunlong Song @ 2015-03-18 13:35 UTC (permalink / raw)
  To: a.p.zijlstra, paulus, mingo, acme; +Cc: linux-kernel, wangnan0

The bash completion does not support listing subsubcommands for 'perf
help <TAB>', so fix it.

Example:

Before this patch:

 $ perf help <TAB>
 $

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

After this patch:

 $ perf help <TAB>
 annotate       buildid-cache  data           evlist         inject
 kvm            lock           probe          report         script
 test           top
 bench          buildid-list   diff           help           kmem
 list           mem            record         sched          stat
 timechart      trace

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

Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
---
 tools/perf/builtin-help.c     | 17 ++++++++++++++---
 tools/perf/perf-completion.sh |  2 +-
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/tools/perf/builtin-help.c b/tools/perf/builtin-help.c
index 25d2062..36486ea 100644
--- a/tools/perf/builtin-help.c
+++ b/tools/perf/builtin-help.c
@@ -437,7 +437,18 @@ int cmd_help(int argc, const char **argv, const char *prefix __maybe_unused)
 			HELP_FORMAT_INFO),
 	OPT_END(),
 	};
-	const char * const builtin_help_usage[] = {
+	const char * const builtin_help_subcommands[] = {
+		"buildid-cache", "buildid-list", "diff", "evlist", "help", "list",
+		"record", "report", "bench", "stat", "timechart", "top", "annotate",
+		"script", "sched", "kmem", "lock", "kvm", "test", "inject", "mem", "data",
+#ifdef HAVE_LIBELF_SUPPORT
+		"probe",
+#endif
+#ifdef HAVE_LIBAUDIT_SUPPORT
+		"trace",
+#endif
+	NULL };
+	const char *builtin_help_usage[] = {
 		"perf help [--all] [--man|--web|--info] [command]",
 		NULL
 	};
@@ -448,8 +459,8 @@ int cmd_help(int argc, const char **argv, const char *prefix __maybe_unused)
 
 	perf_config(perf_help_config, &help_format);
 
-	argc = parse_options(argc, argv, builtin_help_options,
-			builtin_help_usage, 0);
+	argc = parse_options_subcommand(argc, argv, builtin_help_options,
+			builtin_help_subcommands, builtin_help_usage, 0);
 
 	if (show_all) {
 		printf("\n usage: %s\n\n", perf_usage_string);
diff --git a/tools/perf/perf-completion.sh b/tools/perf/perf-completion.sh
index 535ff72..dbca6a6 100644
--- a/tools/perf/perf-completion.sh
+++ b/tools/perf/perf-completion.sh
@@ -143,7 +143,7 @@ __perf_main ()
 		__perfcomp_colon "$evts" "$cur"
 	else
 		# List subcommands for perf commands
-		if [[ $prev_skip_opts == @(kvm|kmem|mem|lock|sched|data) ]]; then
+		if [[ $prev_skip_opts == @(kvm|kmem|mem|lock|sched|data|help) ]]; then
 			subcmds=$($cmd $prev_skip_opts --list-cmds)
 			__perfcomp_colon "$subcmds" "$cur"
 		fi
-- 
1.8.5.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 09/13] perf tools: Add the bash completion for listing subsubcommands of perf script
  2015-03-18 13:35 [PATCH 00/13] perf tools: Make some improvements and fixes Yunlong Song
                   ` (7 preceding siblings ...)
  2015-03-18 13:35 ` [PATCH 08/13] perf tools: Add the bash completion for listing subsubcommands of perf help Yunlong Song
@ 2015-03-18 13:35 ` Yunlong Song
  2015-03-22 10:11   ` [tip:perf/core] " tip-bot for Yunlong Song
  2015-03-18 13:35 ` [PATCH 10/13] perf tools: Add the bash completion for listing subsubcommands of perf test Yunlong Song
                   ` (3 subsequent siblings)
  12 siblings, 1 reply; 27+ messages in thread
From: Yunlong Song @ 2015-03-18 13:35 UTC (permalink / raw)
  To: a.p.zijlstra, paulus, mingo, acme; +Cc: linux-kernel, wangnan0

The bash completion does not support listing subsubcommands for 'perf
script <TAB>', so fix it.

Example:

Before this patch:

 $ perf script <TAB>
 $

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

After this patch:

 $ perf script <TAB>
 record  report

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

Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
---
 tools/perf/builtin-script.c   | 5 +++--
 tools/perf/perf-completion.sh | 2 +-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index c7e6750..f2a348b 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -1572,7 +1572,8 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
 		    "Show the mmap events"),
 	OPT_END()
 	};
-	const char * const script_usage[] = {
+	const char * const script_subcommands[] = { "record", "report", NULL };
+	const char *script_usage[] = {
 		"perf script [<options>]",
 		"perf script [<options>] record <script> [<record-options>] <command>",
 		"perf script [<options>] report <script> [script-args]",
@@ -1586,7 +1587,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
 
 	setup_scripting();
 
-	argc = parse_options(argc, argv, options, script_usage,
+	argc = parse_options_subcommand(argc, argv, options, script_subcommands, script_usage,
 			     PARSE_OPT_STOP_AT_NON_OPTION);
 
 	file.path = input_name;
diff --git a/tools/perf/perf-completion.sh b/tools/perf/perf-completion.sh
index dbca6a6..8739a13 100644
--- a/tools/perf/perf-completion.sh
+++ b/tools/perf/perf-completion.sh
@@ -143,7 +143,7 @@ __perf_main ()
 		__perfcomp_colon "$evts" "$cur"
 	else
 		# List subcommands for perf commands
-		if [[ $prev_skip_opts == @(kvm|kmem|mem|lock|sched|data|help) ]]; then
+		if [[ $prev_skip_opts == @(kvm|kmem|mem|lock|sched|data|help|script) ]]; then
 			subcmds=$($cmd $prev_skip_opts --list-cmds)
 			__perfcomp_colon "$subcmds" "$cur"
 		fi
-- 
1.8.5.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 10/13] perf tools: Add the bash completion for listing subsubcommands of perf test
  2015-03-18 13:35 [PATCH 00/13] perf tools: Make some improvements and fixes Yunlong Song
                   ` (8 preceding siblings ...)
  2015-03-18 13:35 ` [PATCH 09/13] perf tools: Add the bash completion for listing subsubcommands of perf script Yunlong Song
@ 2015-03-18 13:35 ` Yunlong Song
  2015-03-22 10:11   ` [tip:perf/core] " tip-bot for Yunlong Song
  2015-03-18 13:35 ` [PATCH 11/13] perf tools: Add the bash completion for listing subsubcommands of perf timechart Yunlong Song
                   ` (2 subsequent siblings)
  12 siblings, 1 reply; 27+ messages in thread
From: Yunlong Song @ 2015-03-18 13:35 UTC (permalink / raw)
  To: a.p.zijlstra, paulus, mingo, acme; +Cc: linux-kernel, wangnan0

The bash completion does not support listing subsubcommands for 'perf
test <TAB>', so fix it.

Example:

Before this patch:

 $ perf test <TAB>
 $

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

After this patch:

 $ perf test <TAB>
 list

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

Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
---
 tools/perf/perf-completion.sh   | 2 +-
 tools/perf/tests/builtin-test.c | 5 +++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/tools/perf/perf-completion.sh b/tools/perf/perf-completion.sh
index 8739a13..35f43fd 100644
--- a/tools/perf/perf-completion.sh
+++ b/tools/perf/perf-completion.sh
@@ -143,7 +143,7 @@ __perf_main ()
 		__perfcomp_colon "$evts" "$cur"
 	else
 		# List subcommands for perf commands
-		if [[ $prev_skip_opts == @(kvm|kmem|mem|lock|sched|data|help|script) ]]; then
+		if [[ $prev_skip_opts == @(kvm|kmem|mem|lock|sched|data|help|script|test) ]]; then
 			subcmds=$($cmd $prev_skip_opts --list-cmds)
 			__perfcomp_colon "$subcmds" "$cur"
 		fi
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 4b7d9ab..ed8e05c 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -291,7 +291,7 @@ static int perf_test__list(int argc, const char **argv)
 
 int cmd_test(int argc, const char **argv, const char *prefix __maybe_unused)
 {
-	const char * const test_usage[] = {
+	const char *test_usage[] = {
 	"perf test [<options>] [{list <test-name-fragment>|[<test-name-fragments>|<test-numbers>]}]",
 	NULL,
 	};
@@ -302,13 +302,14 @@ int cmd_test(int argc, const char **argv, const char *prefix __maybe_unused)
 		    "be more verbose (show symbol address, etc)"),
 	OPT_END()
 	};
+	const char * const test_subcommands[] = { "list", NULL };
 	struct intlist *skiplist = NULL;
         int ret = hists__init();
 
         if (ret < 0)
                 return ret;
 
-	argc = parse_options(argc, argv, test_options, test_usage, 0);
+	argc = parse_options_subcommand(argc, argv, test_options, test_subcommands, test_usage, 0);
 	if (argc >= 1 && !strcmp(argv[0], "list"))
 		return perf_test__list(argc, argv);
 
-- 
1.8.5.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 11/13] perf tools: Add the bash completion for listing subsubcommands of perf timechart
  2015-03-18 13:35 [PATCH 00/13] perf tools: Make some improvements and fixes Yunlong Song
                   ` (9 preceding siblings ...)
  2015-03-18 13:35 ` [PATCH 10/13] perf tools: Add the bash completion for listing subsubcommands of perf test Yunlong Song
@ 2015-03-18 13:35 ` Yunlong Song
  2015-03-22 10:12   ` [tip:perf/core] " tip-bot for Yunlong Song
  2015-03-18 13:35 ` [PATCH 12/13] perf tools: Add the bash completion for listing subsubcommands of perf trace Yunlong Song
  2015-03-18 13:35 ` [PATCH 13/13] perf tools: Avoid confusion with preloaded bash function for perf bash completion Yunlong Song
  12 siblings, 1 reply; 27+ messages in thread
From: Yunlong Song @ 2015-03-18 13:35 UTC (permalink / raw)
  To: a.p.zijlstra, paulus, mingo, acme; +Cc: linux-kernel, wangnan0

The bash completion does not support listing subsubcommands for 'perf
timechart <TAB>', so fix it.

Example:

Before this patch:

 $ perf timechart <TAB>
 $

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

After this patch:

 $ perf timechart <TAB>
 record

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

Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
---
 tools/perf/builtin-timechart.c | 7 ++++---
 tools/perf/perf-completion.sh  | 2 +-
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c
index 51440d1..494b3bb 100644
--- a/tools/perf/builtin-timechart.c
+++ b/tools/perf/builtin-timechart.c
@@ -1958,7 +1958,8 @@ int cmd_timechart(int argc, const char **argv,
 		     parse_time),
 	OPT_END()
 	};
-	const char * const timechart_usage[] = {
+	const char * const timechart_subcommands[] = { "record", NULL };
+	const char *timechart_usage[] = {
 		"perf timechart [<options>] {record}",
 		NULL
 	};
@@ -1976,8 +1977,8 @@ int cmd_timechart(int argc, const char **argv,
 		"perf timechart record [<options>]",
 		NULL
 	};
-	argc = parse_options(argc, argv, timechart_options, timechart_usage,
-			PARSE_OPT_STOP_AT_NON_OPTION);
+	argc = parse_options_subcommand(argc, argv, timechart_options, timechart_subcommands,
+			timechart_usage, PARSE_OPT_STOP_AT_NON_OPTION);
 
 	if (tchart.power_only && tchart.tasks_only) {
 		pr_err("-P and -T options cannot be used at the same time.\n");
diff --git a/tools/perf/perf-completion.sh b/tools/perf/perf-completion.sh
index 35f43fd..a33d2ef5 100644
--- a/tools/perf/perf-completion.sh
+++ b/tools/perf/perf-completion.sh
@@ -143,7 +143,7 @@ __perf_main ()
 		__perfcomp_colon "$evts" "$cur"
 	else
 		# List subcommands for perf commands
-		if [[ $prev_skip_opts == @(kvm|kmem|mem|lock|sched|data|help|script|test) ]]; then
+		if [[ $prev_skip_opts == @(kvm|kmem|mem|lock|sched|data|help|script|test|timechart) ]]; then
 			subcmds=$($cmd $prev_skip_opts --list-cmds)
 			__perfcomp_colon "$subcmds" "$cur"
 		fi
-- 
1.8.5.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 12/13] perf tools: Add the bash completion for listing subsubcommands of perf trace
  2015-03-18 13:35 [PATCH 00/13] perf tools: Make some improvements and fixes Yunlong Song
                   ` (10 preceding siblings ...)
  2015-03-18 13:35 ` [PATCH 11/13] perf tools: Add the bash completion for listing subsubcommands of perf timechart Yunlong Song
@ 2015-03-18 13:35 ` Yunlong Song
  2015-03-22 10:12   ` [tip:perf/core] " tip-bot for Yunlong Song
  2015-03-18 13:35 ` [PATCH 13/13] perf tools: Avoid confusion with preloaded bash function for perf bash completion Yunlong Song
  12 siblings, 1 reply; 27+ messages in thread
From: Yunlong Song @ 2015-03-18 13:35 UTC (permalink / raw)
  To: a.p.zijlstra, paulus, mingo, acme; +Cc: linux-kernel, wangnan0

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>
---
 tools/perf/builtin-trace.c    | 7 ++++---
 tools/perf/perf-completion.sh | 9 ++++++---
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 6969ba9..0b3b4e4 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -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;
diff --git a/tools/perf/perf-completion.sh b/tools/perf/perf-completion.sh
index a33d2ef5..bdd4035 100644
--- a/tools/perf/perf-completion.sh
+++ b/tools/perf/perf-completion.sh
@@ -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
-- 
1.8.5.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 13/13] perf tools: Avoid confusion with preloaded bash function for perf bash completion
  2015-03-18 13:35 [PATCH 00/13] perf tools: Make some improvements and fixes Yunlong Song
                   ` (11 preceding siblings ...)
  2015-03-18 13:35 ` [PATCH 12/13] perf tools: Add the bash completion for listing subsubcommands of perf trace Yunlong Song
@ 2015-03-18 13:35 ` Yunlong Song
  2015-03-22 10:12   ` [tip:perf/core] " tip-bot for Yunlong Song
  12 siblings, 1 reply; 27+ messages in thread
From: Yunlong Song @ 2015-03-18 13:35 UTC (permalink / raw)
  To: a.p.zijlstra, paulus, mingo, acme; +Cc: linux-kernel, wangnan0

Since some functions (e.g. '_get_comp_words_by_ref()') in perf bash
completion script are originally taken from git bash completion script,
these functions may be preloaded before perf bash completion script
runs. In order to avoid repeating loading the same function twice, some
test constraints are used before these function definitions in the perf
bash completion script (e.g. 'type _get_comp_words_by_ref &>/dev/null ||').
The problem is that, if these functions in perf bash completion script
are changed for some reason, perf will still use the preloaded bash
functions rather than the customized functions of its own. As a result,
the perf bash completion will behave incorrectly. To get rid of this
problem, a flag can be defined to determine the proper situation. And to
avoid overwriting the preloaded functions, the names of these functions
in perf bash completion script should be renamed to the perf-customized
ones.

Example:

Before this patch:

 $ type _get_comp_words_by_ref
 _get_comp_words_by_ref is a function
 _get_comp_words_by_ref ()
 {
     local exclude flag i OPTIND=1;
     local cur cword words=();
     local upargs=() upvars=() vcur vcword vprev vwords;
     while getopts "c:i:n:p:w:" flag "$@"; do
         case $flag in
             c)
                 vcur=$OPTARG
             ;;
             i)
                 vcword=$OPTARG
             ;;
             n)
                 exclude=$OPTARG
             ;;
             p)
                 vprev=$OPTARG
             ;;
             w)
                 vwords=$OPTARG
             ;;
         esac;
     done;
     while [[ $# -ge $OPTIND ]]; do
         case ${!OPTIND} in
             cur)
                 vcur=cur
             ;;
             prev)
                 vprev=prev
             ;;
             cword)
                 vcword=cword
             ;;
             words)
                 vwords=words
             ;;
             *)
                 echo "bash: $FUNCNAME(): \`${!OPTIND}': unknown argument" 1>&2;
                 return 1
             ;;
         esac;
         let "OPTIND += 1";
     done;
     __get_cword_at_cursor_by_ref "$exclude" words cword cur;
     [[ -n $vcur ]] && {
         upvars+=("$vcur");
         upargs+=(-v $vcur "$cur")
     };
     [[ -n $vcword ]] && {
         upvars+=("$vcword");
         upargs+=(-v $vcword "$cword")
     };
     [[ -n $vprev && $cword -ge 1 ]] && {
         upvars+=("$vprev");
         upargs+=(-v $vprev "${words[cword - 1]}")
     };
     [[ -n $vwords ]] && {
         upvars+=("$vwords");
         upargs+=(-a${#words[@]} $vwords "${words[@]}")
     };
     (( ${#upvars[@]} )) && local "${upvars[@]}" && _upvars "${upargs[@]}"
 }

As shown above, the _get_comp_words_by_ref is the preloaded function in
fact, rather than the function defined in perf-completion.sh. So if we
happen to change the function for some reason, the result will behave in
a wrong state.

After this patch:

We can set preload_get_comp_words_by_ref="false" to not use the preloaded
function. Instead, it will use the function defined in perf-completion.sh,
which is renamed as __perf_get_comp_words_by_ref to avoid overwriting
the preloaded function _get_comp_words_by_ref.

 $ type __perf_get_comp_words_by_ref
 __perf_get_comp_words_by_ref is a function
 __perf_get_comp_words_by_ref ()
 {
     local exclude cur_ words_ cword_;
     if [ "$1" = "-n" ]; then
         exclude=$2;
         shift 2;
     fi;
     __my_reassemble_comp_words_by_ref "$exclude";
     cur_=${words_[cword_]};
     while [ $# -gt 0 ]; do
         case "$1" in
             cur)
                 cur=$cur_
             ;;
             prev)
                 prev=${words_[$cword_-1]}
             ;;
             words)
                 words=("${words_[@]}")
             ;;
             cword)
                 cword=$cword_
             ;;
         esac;
         shift;
     done
 }

As shown above, the function __perf_get_comp_words_by_ref is loaded and
can work this time.

Note that we do not change the original behavior when those functions are
not preloaded before perf bash completion script runs. In this case,
although the flag is set to "true", the code will still change it to
"false" to use the function defined in perf-completion.sh.

Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
---
 tools/perf/perf-completion.sh | 36 ++++++++++++++++++++++++++++++------
 1 file changed, 30 insertions(+), 6 deletions(-)

diff --git a/tools/perf/perf-completion.sh b/tools/perf/perf-completion.sh
index bdd4035..3ba80b2 100644
--- a/tools/perf/perf-completion.sh
+++ b/tools/perf/perf-completion.sh
@@ -47,8 +47,16 @@ __my_reassemble_comp_words_by_ref()
 	done
 }
 
-type _get_comp_words_by_ref &>/dev/null ||
-_get_comp_words_by_ref()
+# Define preload_get_comp_words_by_ref="false", if the function
+# __perf_get_comp_words_by_ref() is required instead.
+preload_get_comp_words_by_ref="true"
+
+if [ $preload_get_comp_words_by_ref = "true" ]; then
+	type _get_comp_words_by_ref &>/dev/null ||
+	preload_get_comp_words_by_ref="false"
+fi
+[ $preload_get_comp_words_by_ref = "true" ] ||
+__perf_get_comp_words_by_ref()
 {
 	local exclude cur_ words_ cword_
 	if [ "$1" = "-n" ]; then
@@ -76,8 +84,16 @@ _get_comp_words_by_ref()
 	done
 }
 
-type __ltrim_colon_completions &>/dev/null ||
-__ltrim_colon_completions()
+# Define preload__ltrim_colon_completions="false", if the function
+# __perf__ltrim_colon_completions() is required instead.
+preload__ltrim_colon_completions="true"
+
+if [ $preload__ltrim_colon_completions = "true" ]; then
+	type __ltrim_colon_completions &>/dev/null ||
+	preload__ltrim_colon_completions="false"
+fi
+[ $preload__ltrim_colon_completions = "true" ] ||
+__perf__ltrim_colon_completions()
 {
 	if [[ "$1" == *:* && "$COMP_WORDBREAKS" == *:* ]]; then
 		# Remove colon-word prefix from COMPREPLY items
@@ -97,7 +113,11 @@ __perfcomp ()
 __perfcomp_colon ()
 {
 	__perfcomp "$1" "$2"
-	__ltrim_colon_completions $cur
+	if [ $preload__ltrim_colon_completions = "true" ]; then
+		__ltrim_colon_completions $cur
+	else
+		__perf__ltrim_colon_completions $cur
+	fi
 }
 
 __perf_prev_skip_opts ()
@@ -226,7 +246,11 @@ type perf &>/dev/null &&
 _perf()
 {
 	local cur words cword prev
-	_get_comp_words_by_ref -n =: cur words cword prev
+	if [ $preload_get_comp_words_by_ref = "true" ]; then
+		_get_comp_words_by_ref -n =: cur words cword prev
+	else
+		__perf_get_comp_words_by_ref -n =: cur words cword prev
+	fi
 	__perf_main
 } &&
 
-- 
1.8.5.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [tip:perf/core] perf tools: Fix the bash completion for listing options of perf subcommand
  2015-03-18 13:35 ` [PATCH 01/13] perf tools: Fix the bash completion for listing options of perf subcommand Yunlong Song
@ 2015-03-22 10:09   ` tip-bot for Yunlong Song
  0 siblings, 0 replies; 27+ messages in thread
From: tip-bot for Yunlong Song @ 2015-03-22 10:09 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: yunlong.song, linux-kernel, acme, tglx, hpa, a.p.zijlstra, mingo,
	wangnan0, paulus

Commit-ID:  02fde323b9aaebb4a21e7c0e04759470b6c07594
Gitweb:     http://git.kernel.org/tip/02fde323b9aaebb4a21e7c0e04759470b6c07594
Author:     Yunlong Song <yunlong.song@huawei.com>
AuthorDate: Wed, 18 Mar 2015 21:35:46 +0800
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Thu, 19 Mar 2015 13:48:56 -0300

perf tools: Fix the bash completion for listing options of perf subcommand

The bash completion does not support listing options for 'perf
kvm|kmem|mem|lock|sched --<TAB>', where 'kvm|kmem|mem|lock|sched' are
all subcommands of perf.

Example:

Before this patch:

 $ perf kvm --<TAB>
 $

As shown above, the options of perf kvm does not come out.

After this patch:

 $ perf kvm --<TAB>
 --alloc    --caller   --input    --line     --raw-ip   --sort
 --verbose

As shown above, the options of perf kvm 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-2-git-send-email-yunlong.song@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/perf-completion.sh | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/tools/perf/perf-completion.sh b/tools/perf/perf-completion.sh
index c2595e9..4822ed3 100644
--- a/tools/perf/perf-completion.sh
+++ b/tools/perf/perf-completion.sh
@@ -119,15 +119,18 @@ __perf_main ()
 	elif [[ $prev == "-e" && "${words[1]}" == @(record|stat|top) ]]; then
 		evts=$($cmd list --raw-dump)
 		__perfcomp_colon "$evts" "$cur"
-	# List subcommands for perf commands
-	elif [[ $prev == @(kvm|kmem|mem|lock|sched) ]]; then
-		subcmds=$($cmd $prev --list-cmds)
-		__perfcomp_colon "$subcmds" "$cur"
-	# List long option names
-	elif [[ $cur == --* ]];  then
-		subcmd=${words[1]}
-		opts=$($cmd $subcmd --list-opts)
-		__perfcomp "$opts" "$cur"
+	else
+		# List subcommands for perf commands
+		if [[ $prev == @(kvm|kmem|mem|lock|sched) ]]; then
+			subcmds=$($cmd $prev --list-cmds)
+			__perfcomp_colon "$subcmds" "$cur"
+		fi
+		# List long option names
+		if [[ $cur == --* ]];  then
+			subcmd=${words[1]}
+			opts=$($cmd $subcmd --list-opts)
+			__perfcomp "$opts" "$cur"
+		fi
 	fi
 }
 

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [tip:perf/core] perf tools: Fix the bash completion for listing subsubcommands of perf subcommand
  2015-03-18 13:35 ` [PATCH 02/13] perf tools: Fix the bash completion for listing subsubcommands " Yunlong Song
@ 2015-03-22 10:09   ` tip-bot for Yunlong Song
  0 siblings, 0 replies; 27+ messages in thread
From: tip-bot for Yunlong Song @ 2015-03-22 10:09 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, wangnan0, linux-kernel, paulus, yunlong.song, tglx, mingo,
	a.p.zijlstra, hpa

Commit-ID:  67afff485b2ce742374edb2e17d21e2bc664eb1f
Gitweb:     http://git.kernel.org/tip/67afff485b2ce742374edb2e17d21e2bc664eb1f
Author:     Yunlong Song <yunlong.song@huawei.com>
AuthorDate: Wed, 18 Mar 2015 21:35:47 +0800
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Thu, 19 Mar 2015 13:49:20 -0300

perf tools: Fix the bash completion for listing subsubcommands of perf subcommand

The bash completion does not support listing subsubcommands for 'perf
kvm|kmem|mem|lock|sched --<long option> <TAB>', where 'kvm|kmem|mem|
lock|sched' are all subcommands of perf.

Example:

Before this patch:

 $ perf kvm --verbose <TAB>
 $

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

After this patch:

 $ perf kvm --verbose <TAB>
 buildid-list  diff          record        report        stat
 top

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

Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/r/1426685758-25488-3-git-send-email-yunlong.song@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/perf-completion.sh | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/tools/perf/perf-completion.sh b/tools/perf/perf-completion.sh
index 4822ed3..bbb61d0 100644
--- a/tools/perf/perf-completion.sh
+++ b/tools/perf/perf-completion.sh
@@ -100,6 +100,23 @@ __perfcomp_colon ()
 	__ltrim_colon_completions $cur
 }
 
+__perf_prev_skip_opts ()
+{
+	local i cmd_ cmds_
+
+	let i=cword-1
+	cmds_=$($cmd --list-cmds)
+	prev_skip_opts=()
+	while [ $i -ge 0 ]; do
+		for cmd_ in $cmds_; do
+			if [[ ${words[i]} == $cmd_ ]]; then
+				prev_skip_opts=${words[i]}
+				return
+			fi
+		done
+		((i--))
+	done
+}
 __perf_main ()
 {
 	local cmd
@@ -107,6 +124,8 @@ __perf_main ()
 	cmd=${words[0]}
 	COMPREPLY=()
 
+	# Skip options backward and find the last perf command
+	__perf_prev_skip_opts
 	# List perf subcommands or long options
 	if [ $cword -eq 1 ]; then
 		if [[ $cur == --* ]]; then
@@ -121,8 +140,8 @@ __perf_main ()
 		__perfcomp_colon "$evts" "$cur"
 	else
 		# List subcommands for perf commands
-		if [[ $prev == @(kvm|kmem|mem|lock|sched) ]]; then
-			subcmds=$($cmd $prev --list-cmds)
+		if [[ $prev_skip_opts == @(kvm|kmem|mem|lock|sched) ]]; then
+			subcmds=$($cmd $prev_skip_opts --list-cmds)
 			__perfcomp_colon "$subcmds" "$cur"
 		fi
 		# List long option names

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [tip:perf/core] perf tools: Provide the right bash completion for listing options of perf subcommand subsubcommand
  2015-03-18 13:35 ` [PATCH 03/13] perf tools: Provide the right bash completion for listing options of perf subcommand subsubcommand Yunlong Song
@ 2015-03-22 10:09   ` tip-bot for Yunlong Song
  0 siblings, 0 replies; 27+ messages in thread
From: tip-bot for Yunlong Song @ 2015-03-22 10:09 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: a.p.zijlstra, acme, yunlong.song, wangnan0, paulus, tglx, mingo,
	hpa, linux-kernel

Commit-ID:  eee200a6c4a9712146ba999f944ba4f2c3fc2d44
Gitweb:     http://git.kernel.org/tip/eee200a6c4a9712146ba999f944ba4f2c3fc2d44
Author:     Yunlong Song <yunlong.song@huawei.com>
AuthorDate: Wed, 18 Mar 2015 21:35:48 +0800
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Thu, 19 Mar 2015 13:49:28 -0300

perf tools: Provide the right bash completion for listing options of perf subcommand subsubcommand

The bash completion gives wrong options for 'perf kvm|kmem|mem|lock|
sched subsubcommand --<TAB>', where 'kvm|kmem|mem|lock|sched' are all
subcommands of perf and 'subsubcommand' is a subcommand of 'kvm|kmem|mem
|lock|sched'. In fact, the result incorrectly lists the bash completion
of 'perf subcommand' rather than 'perf subcommand subsubcommand'.

Example:

Before this patch:

 $ perf kvm record --<TAB>
 --guest          --guestkallsyms  --guestmodules   --guestmount
 --guestvmlinux   --host           --input          --output
 --verbose

As shown above, the result is the options of kvm rather than record.

After this patch:

 $ perf kvm record --<TAB>
 --all-cpus          --cgroup            --delay             --group
 --no-buildid        --output            --quiet             --stat
 --uid
 --branch-any        --count             --event             --intr-regs
 --no-buildid-cache  --period            --raw-samples       --tid
 --verbose
 --branch-filter     --cpu               --filter            --mmap-pages
 --no-inherit        --per-thread        --realtime          --timestamp
 --weight
 --call-graph        --data              --freq
 --no-buffering      --no-samples        --pid
 --running-time      --transaction

As shown above, the result is exactly the options of record as we wished.

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-4-git-send-email-yunlong.song@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/perf-completion.sh | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/tools/perf/perf-completion.sh b/tools/perf/perf-completion.sh
index bbb61d0..01ce841 100644
--- a/tools/perf/perf-completion.sh
+++ b/tools/perf/perf-completion.sh
@@ -105,9 +105,12 @@ __perf_prev_skip_opts ()
 	local i cmd_ cmds_
 
 	let i=cword-1
-	cmds_=$($cmd --list-cmds)
+	cmds_=$($cmd $1 --list-cmds)
 	prev_skip_opts=()
 	while [ $i -ge 0 ]; do
+		if [[ ${words[i]} == $1 ]]; then
+			return
+		fi
 		for cmd_ in $cmds_; do
 			if [[ ${words[i]} == $cmd_ ]]; then
 				prev_skip_opts=${words[i]}
@@ -146,7 +149,9 @@ __perf_main ()
 		fi
 		# List long option names
 		if [[ $cur == --* ]];  then
-			subcmd=${words[1]}
+			subcmd=$prev_skip_opts
+			__perf_prev_skip_opts $subcmd
+			subcmd=$subcmd" "$prev_skip_opts
 			opts=$($cmd $subcmd --list-opts)
 			__perfcomp "$opts" "$cur"
 		fi

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [tip:perf/core] perf tools: Fix the bash completion for listing events of perf subcommand record|stat|top -e
  2015-03-18 13:35 ` [PATCH 04/13] perf tools: Fix the bash completion for listing events of perf subcommand record|stat|top -e Yunlong Song
@ 2015-03-22 10:10   ` tip-bot for Yunlong Song
  0 siblings, 0 replies; 27+ messages in thread
From: tip-bot for Yunlong Song @ 2015-03-22 10:10 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: tglx, paulus, linux-kernel, mingo, hpa, yunlong.song, acme,
	a.p.zijlstra, wangnan0

Commit-ID:  bc81fad125dba7da33dbeac4c10d9c84614eb3ab
Gitweb:     http://git.kernel.org/tip/bc81fad125dba7da33dbeac4c10d9c84614eb3ab
Author:     Yunlong Song <yunlong.song@huawei.com>
AuthorDate: Wed, 18 Mar 2015 21:35:49 +0800
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Thu, 19 Mar 2015 13:49:37 -0300

perf tools: Fix the bash completion for listing events of perf subcommand record|stat|top -e

The bash completion does not support listing events for 'perf kvm|kmem|
mem|lock|sched record|stat|top -e <TAB>', where 'kvm|kmem|mem|lock|sched'
are all subcommands of perf.

Example:

Before this patch:

 $ perf kvm record -e <TAB>
 $

As shown above, the events of record does not come out.

After this patch:

 $ perf kvm record -e <TAB>
 alignment-faults                   cpu/instructions/
 L1-dcache-prefetch-misses          node-prefetches
 uncore_rbox_0/qpi0_idle_filt/
 branch-instructions                cpu/mem-loads/
 L1-dcache-store-misses             node-prefetch-misses
 uncore_rbox_0/qpi1_date_response/
 branch-load-misses                 cpu-migrations
 L1-dcache-stores                   node-store-misses
 uncore_rbox_0/qpi1_filt_send/
 branch-loads                       dTLB-load-misses
 L1-icache-load-misses              node-stores
 uncore_rbox_0/qpi1_idle_filt/
 ...

As shown above, the events of record 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-5-git-send-email-yunlong.song@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/perf-completion.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/perf-completion.sh b/tools/perf/perf-completion.sh
index 01ce841..4b58ac2 100644
--- a/tools/perf/perf-completion.sh
+++ b/tools/perf/perf-completion.sh
@@ -138,7 +138,7 @@ __perf_main ()
 		fi
 		__perfcomp "$cmds" "$cur"
 	# List possible events for -e option
-	elif [[ $prev == "-e" && "${words[1]}" == @(record|stat|top) ]]; then
+	elif [[ $prev == "-e" && $prev_skip_opts == @(record|stat|top) ]]; then
 		evts=$($cmd list --raw-dump)
 		__perfcomp_colon "$evts" "$cur"
 	else

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [tip:perf/core] perf tools: Fix the bash completion to support listing events for --event
  2015-03-18 13:35 ` [PATCH 05/13] perf tools: Fix the bash completion to support listing events for --event Yunlong Song
@ 2015-03-22 10:10   ` tip-bot for Yunlong Song
  0 siblings, 0 replies; 27+ messages in thread
From: tip-bot for Yunlong Song @ 2015-03-22 10:10 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: a.p.zijlstra, linux-kernel, yunlong.song, hpa, paulus, tglx,
	wangnan0, mingo, acme

Commit-ID:  3346b542f4165cb0007cfe3600866acbee67c686
Gitweb:     http://git.kernel.org/tip/3346b542f4165cb0007cfe3600866acbee67c686
Author:     Yunlong Song <yunlong.song@huawei.com>
AuthorDate: Wed, 18 Mar 2015 21:35:50 +0800
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Thu, 19 Mar 2015 13:49:37 -0300

perf tools: Fix the bash completion to support listing events for --event

The bash completion only supports -e rather than --event, so fix it.

Example:

Before this patch:

 $ perf record --event <TAB>
 $

As shown above, the events of record does not come out.

After this patch:

 $ perf record --event <TAB>
 lignment-faults                   cpu/instructions/
 L1-dcache-prefetch-misses          node-prefetches
 uncore_rbox_0/qpi0_idle_filt/
 branch-instructions                cpu/mem-loads/
 L1-dcache-store-misses             node-prefetch-misses
 uncore_rbox_0/qpi1_date_response/
 branch-load-misses                 cpu-migrations
 L1-dcache-stores                   node-store-misses
 uncore_rbox_0/qpi1_filt_send/
 branch-loads                       dTLB-load-misses
 L1-icache-load-misses              node-stores
 uncore_rbox_0/qpi1_idle_filt/
 ...

As shown above, the events of record 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-6-git-send-email-yunlong.song@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/perf-completion.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/perf-completion.sh b/tools/perf/perf-completion.sh
index 4b58ac2..3e25d3e 100644
--- a/tools/perf/perf-completion.sh
+++ b/tools/perf/perf-completion.sh
@@ -137,8 +137,8 @@ __perf_main ()
 			cmds=$($cmd --list-cmds)
 		fi
 		__perfcomp "$cmds" "$cur"
-	# List possible events for -e option
-	elif [[ $prev == "-e" && $prev_skip_opts == @(record|stat|top) ]]; then
+	# List possible events for -e and --event option
+	elif [[ $prev == @("-e"|"--event") && $prev_skip_opts == @(record|stat|top) ]]; then
 		evts=$($cmd list --raw-dump)
 		__perfcomp_colon "$evts" "$cur"
 	else

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [tip:perf/core] perf tools: Fix the bash completion for listing subcommands of perf
  2015-03-18 13:35 ` [PATCH 06/13] perf tools: Fix the bash completion for listing subcommands of perf Yunlong Song
@ 2015-03-22 10:10   ` tip-bot for Yunlong Song
  0 siblings, 0 replies; 27+ messages in thread
From: tip-bot for Yunlong Song @ 2015-03-22 10:10 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: tglx, wangnan0, mingo, paulus, hpa, a.p.zijlstra, acme,
	yunlong.song, linux-kernel

Commit-ID:  e003ce54d2ccbb8da0fd4f421e1cc9686ef25add
Gitweb:     http://git.kernel.org/tip/e003ce54d2ccbb8da0fd4f421e1cc9686ef25add
Author:     Yunlong Song <yunlong.song@huawei.com>
AuthorDate: Wed, 18 Mar 2015 21:35:51 +0800
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Thu, 19 Mar 2015 13:49:38 -0300

perf tools: Fix the bash completion for listing subcommands of perf

The bash completion does not support listing subcommands for 'perf
--<long option> <TAB>'.

Example:

Before this patch:

 $ perf --debug <TAB>
 $

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

After this patch:

 $ perf --debug <TAB>
 annotate       buildid-cache  data           evlist         inject
 kvm            lock           probe          report         script
 test           top            version
 bench          buildid-list   diff           help           kmem
 list           mem            record         sched          stat
 timechart      trace

As shown above, the subcommands of perf 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-7-git-send-email-yunlong.song@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/perf-completion.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/perf-completion.sh b/tools/perf/perf-completion.sh
index 3e25d3e..7b98ae4 100644
--- a/tools/perf/perf-completion.sh
+++ b/tools/perf/perf-completion.sh
@@ -130,7 +130,7 @@ __perf_main ()
 	# Skip options backward and find the last perf command
 	__perf_prev_skip_opts
 	# List perf subcommands or long options
-	if [ $cword -eq 1 ]; then
+	if [ -z $prev_skip_opts ]; then
 		if [[ $cur == --* ]]; then
 			cmds=$($cmd --list-opts)
 		else

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [tip:perf/core] perf tools: Add the bash completion for listing subsubcommands of perf data
  2015-03-18 13:35 ` [PATCH 07/13] perf tools: Add the bash completion for listing subsubcommands of perf data Yunlong Song
@ 2015-03-22 10:11   ` tip-bot for Yunlong Song
  0 siblings, 0 replies; 27+ messages in thread
From: tip-bot for Yunlong Song @ 2015-03-22 10:11 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: hpa, mingo, wangnan0, paulus, tglx, linux-kernel, acme,
	a.p.zijlstra, yunlong.song

Commit-ID:  01b7160bc6674912f6b7043bbf58d66e62e41054
Gitweb:     http://git.kernel.org/tip/01b7160bc6674912f6b7043bbf58d66e62e41054
Author:     Yunlong Song <yunlong.song@huawei.com>
AuthorDate: Wed, 18 Mar 2015 21:35:52 +0800
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Thu, 19 Mar 2015 13:49:38 -0300

perf tools: Add the bash completion for listing subsubcommands of perf data

The bash completion does not support listing subsubcommands for 'perf
data <TAB>', so fix it.

Example:

Before this patch:

 $ perf data <TAB>
 $

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

After this patch:

 $ perf data <TAB>
 convert

As shown above, the subsubcommands of perf data 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-8-git-send-email-yunlong.song@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-data.c     | 6 ++++--
 tools/perf/perf-completion.sh | 2 +-
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/tools/perf/builtin-data.c b/tools/perf/builtin-data.c
index 155cf75..709152a 100644
--- a/tools/perf/builtin-data.c
+++ b/tools/perf/builtin-data.c
@@ -22,7 +22,9 @@ static const struct option data_options[] = {
 	OPT_END()
 };
 
-static const char * const data_usage[] = {
+static const char * const data_subcommands[] = { "convert", NULL };
+
+static const char *data_usage[] = {
 	"perf data [<common options>] <command> [<options>]",
 	NULL
 };
@@ -98,7 +100,7 @@ int cmd_data(int argc, const char **argv, const char *prefix)
 	if (argc < 2)
 		goto usage;
 
-	argc = parse_options(argc, argv, data_options, data_usage,
+	argc = parse_options_subcommand(argc, argv, data_options, data_subcommands, data_usage,
 			     PARSE_OPT_STOP_AT_NON_OPTION);
 	if (argc < 1)
 		goto usage;
diff --git a/tools/perf/perf-completion.sh b/tools/perf/perf-completion.sh
index 7b98ae4..535ff72 100644
--- a/tools/perf/perf-completion.sh
+++ b/tools/perf/perf-completion.sh
@@ -143,7 +143,7 @@ __perf_main ()
 		__perfcomp_colon "$evts" "$cur"
 	else
 		# List subcommands for perf commands
-		if [[ $prev_skip_opts == @(kvm|kmem|mem|lock|sched) ]]; then
+		if [[ $prev_skip_opts == @(kvm|kmem|mem|lock|sched|data) ]]; then
 			subcmds=$($cmd $prev_skip_opts --list-cmds)
 			__perfcomp_colon "$subcmds" "$cur"
 		fi

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [tip:perf/core] perf tools: Add the bash completion for listing subsubcommands of perf help
  2015-03-18 13:35 ` [PATCH 08/13] perf tools: Add the bash completion for listing subsubcommands of perf help Yunlong Song
@ 2015-03-22 10:11   ` tip-bot for Yunlong Song
  0 siblings, 0 replies; 27+ messages in thread
From: tip-bot for Yunlong Song @ 2015-03-22 10:11 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: yunlong.song, acme, mingo, paulus, wangnan0, linux-kernel, tglx,
	hpa, a.p.zijlstra

Commit-ID:  e24a110882949c609c5fb7625b71d8e77264257b
Gitweb:     http://git.kernel.org/tip/e24a110882949c609c5fb7625b71d8e77264257b
Author:     Yunlong Song <yunlong.song@huawei.com>
AuthorDate: Wed, 18 Mar 2015 21:35:53 +0800
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Thu, 19 Mar 2015 13:49:39 -0300

perf tools: Add the bash completion for listing subsubcommands of perf help

The bash completion does not support listing subsubcommands for 'perf
help <TAB>', so fix it.

Example:

Before this patch:

 $ perf help <TAB>
 $

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

After this patch:

 $ perf help <TAB>
 annotate       buildid-cache  data           evlist         inject
 kvm            lock           probe          report         script
 test           top
 bench          buildid-list   diff           help           kmem
 list           mem            record         sched          stat
 timechart      trace

As shown above, the subsubcommands of perf help 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-9-git-send-email-yunlong.song@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-help.c     | 17 ++++++++++++++---
 tools/perf/perf-completion.sh |  2 +-
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/tools/perf/builtin-help.c b/tools/perf/builtin-help.c
index 25d2062..36486ea 100644
--- a/tools/perf/builtin-help.c
+++ b/tools/perf/builtin-help.c
@@ -437,7 +437,18 @@ int cmd_help(int argc, const char **argv, const char *prefix __maybe_unused)
 			HELP_FORMAT_INFO),
 	OPT_END(),
 	};
-	const char * const builtin_help_usage[] = {
+	const char * const builtin_help_subcommands[] = {
+		"buildid-cache", "buildid-list", "diff", "evlist", "help", "list",
+		"record", "report", "bench", "stat", "timechart", "top", "annotate",
+		"script", "sched", "kmem", "lock", "kvm", "test", "inject", "mem", "data",
+#ifdef HAVE_LIBELF_SUPPORT
+		"probe",
+#endif
+#ifdef HAVE_LIBAUDIT_SUPPORT
+		"trace",
+#endif
+	NULL };
+	const char *builtin_help_usage[] = {
 		"perf help [--all] [--man|--web|--info] [command]",
 		NULL
 	};
@@ -448,8 +459,8 @@ int cmd_help(int argc, const char **argv, const char *prefix __maybe_unused)
 
 	perf_config(perf_help_config, &help_format);
 
-	argc = parse_options(argc, argv, builtin_help_options,
-			builtin_help_usage, 0);
+	argc = parse_options_subcommand(argc, argv, builtin_help_options,
+			builtin_help_subcommands, builtin_help_usage, 0);
 
 	if (show_all) {
 		printf("\n usage: %s\n\n", perf_usage_string);
diff --git a/tools/perf/perf-completion.sh b/tools/perf/perf-completion.sh
index 535ff72..dbca6a6 100644
--- a/tools/perf/perf-completion.sh
+++ b/tools/perf/perf-completion.sh
@@ -143,7 +143,7 @@ __perf_main ()
 		__perfcomp_colon "$evts" "$cur"
 	else
 		# List subcommands for perf commands
-		if [[ $prev_skip_opts == @(kvm|kmem|mem|lock|sched|data) ]]; then
+		if [[ $prev_skip_opts == @(kvm|kmem|mem|lock|sched|data|help) ]]; then
 			subcmds=$($cmd $prev_skip_opts --list-cmds)
 			__perfcomp_colon "$subcmds" "$cur"
 		fi

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [tip:perf/core] perf tools: Add the bash completion for listing subsubcommands of perf script
  2015-03-18 13:35 ` [PATCH 09/13] perf tools: Add the bash completion for listing subsubcommands of perf script Yunlong Song
@ 2015-03-22 10:11   ` tip-bot for Yunlong Song
  0 siblings, 0 replies; 27+ messages in thread
From: tip-bot for Yunlong Song @ 2015-03-22 10:11 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: yunlong.song, paulus, hpa, a.p.zijlstra, wangnan0, acme, mingo,
	tglx, linux-kernel

Commit-ID:  40cae2b779f2826f3d82674027299332c2007716
Gitweb:     http://git.kernel.org/tip/40cae2b779f2826f3d82674027299332c2007716
Author:     Yunlong Song <yunlong.song@huawei.com>
AuthorDate: Wed, 18 Mar 2015 21:35:54 +0800
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Thu, 19 Mar 2015 13:49:39 -0300

perf tools: Add the bash completion for listing subsubcommands of perf script

The bash completion does not support listing subsubcommands for 'perf
script <TAB>', so fix it.

Example:

Before this patch:

 $ perf script <TAB>
 $

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

After this patch:

 $ perf script <TAB>
 record  report

As shown above, the subsubcommands of perf script 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-10-git-send-email-yunlong.song@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-script.c   | 5 +++--
 tools/perf/perf-completion.sh | 2 +-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index c7e6750..f2a348b 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -1572,7 +1572,8 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
 		    "Show the mmap events"),
 	OPT_END()
 	};
-	const char * const script_usage[] = {
+	const char * const script_subcommands[] = { "record", "report", NULL };
+	const char *script_usage[] = {
 		"perf script [<options>]",
 		"perf script [<options>] record <script> [<record-options>] <command>",
 		"perf script [<options>] report <script> [script-args]",
@@ -1586,7 +1587,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
 
 	setup_scripting();
 
-	argc = parse_options(argc, argv, options, script_usage,
+	argc = parse_options_subcommand(argc, argv, options, script_subcommands, script_usage,
 			     PARSE_OPT_STOP_AT_NON_OPTION);
 
 	file.path = input_name;
diff --git a/tools/perf/perf-completion.sh b/tools/perf/perf-completion.sh
index dbca6a6..8739a13 100644
--- a/tools/perf/perf-completion.sh
+++ b/tools/perf/perf-completion.sh
@@ -143,7 +143,7 @@ __perf_main ()
 		__perfcomp_colon "$evts" "$cur"
 	else
 		# List subcommands for perf commands
-		if [[ $prev_skip_opts == @(kvm|kmem|mem|lock|sched|data|help) ]]; then
+		if [[ $prev_skip_opts == @(kvm|kmem|mem|lock|sched|data|help|script) ]]; then
 			subcmds=$($cmd $prev_skip_opts --list-cmds)
 			__perfcomp_colon "$subcmds" "$cur"
 		fi

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [tip:perf/core] perf tools: Add the bash completion for listing subsubcommands of perf test
  2015-03-18 13:35 ` [PATCH 10/13] perf tools: Add the bash completion for listing subsubcommands of perf test Yunlong Song
@ 2015-03-22 10:11   ` tip-bot for Yunlong Song
  0 siblings, 0 replies; 27+ messages in thread
From: tip-bot for Yunlong Song @ 2015-03-22 10:11 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: hpa, linux-kernel, tglx, acme, a.p.zijlstra, mingo, yunlong.song,
	paulus, wangnan0

Commit-ID:  1f9975f14ce4f7258db1cb0eea8fba17482e331e
Gitweb:     http://git.kernel.org/tip/1f9975f14ce4f7258db1cb0eea8fba17482e331e
Author:     Yunlong Song <yunlong.song@huawei.com>
AuthorDate: Wed, 18 Mar 2015 21:35:55 +0800
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Thu, 19 Mar 2015 13:52:54 -0300

perf tools: Add the bash completion for listing subsubcommands of perf test

The bash completion does not support listing subsubcommands for 'perf
test <TAB>', so fix it.

Example:

Before this patch:

 $ perf test <TAB>
 $

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

After this patch:

 $ perf test <TAB>
 list

As shown above, the subsubcommands of perf test 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-11-git-send-email-yunlong.song@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/perf-completion.sh   | 2 +-
 tools/perf/tests/builtin-test.c | 5 +++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/tools/perf/perf-completion.sh b/tools/perf/perf-completion.sh
index 8739a13..35f43fd 100644
--- a/tools/perf/perf-completion.sh
+++ b/tools/perf/perf-completion.sh
@@ -143,7 +143,7 @@ __perf_main ()
 		__perfcomp_colon "$evts" "$cur"
 	else
 		# List subcommands for perf commands
-		if [[ $prev_skip_opts == @(kvm|kmem|mem|lock|sched|data|help|script) ]]; then
+		if [[ $prev_skip_opts == @(kvm|kmem|mem|lock|sched|data|help|script|test) ]]; then
 			subcmds=$($cmd $prev_skip_opts --list-cmds)
 			__perfcomp_colon "$subcmds" "$cur"
 		fi
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 4b7d9ab..ed8e05c 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -291,7 +291,7 @@ static int perf_test__list(int argc, const char **argv)
 
 int cmd_test(int argc, const char **argv, const char *prefix __maybe_unused)
 {
-	const char * const test_usage[] = {
+	const char *test_usage[] = {
 	"perf test [<options>] [{list <test-name-fragment>|[<test-name-fragments>|<test-numbers>]}]",
 	NULL,
 	};
@@ -302,13 +302,14 @@ int cmd_test(int argc, const char **argv, const char *prefix __maybe_unused)
 		    "be more verbose (show symbol address, etc)"),
 	OPT_END()
 	};
+	const char * const test_subcommands[] = { "list", NULL };
 	struct intlist *skiplist = NULL;
         int ret = hists__init();
 
         if (ret < 0)
                 return ret;
 
-	argc = parse_options(argc, argv, test_options, test_usage, 0);
+	argc = parse_options_subcommand(argc, argv, test_options, test_subcommands, test_usage, 0);
 	if (argc >= 1 && !strcmp(argv[0], "list"))
 		return perf_test__list(argc, argv);
 

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [tip:perf/core] perf tools: Add the bash completion for listing subsubcommands of perf timechart
  2015-03-18 13:35 ` [PATCH 11/13] perf tools: Add the bash completion for listing subsubcommands of perf timechart Yunlong Song
@ 2015-03-22 10:12   ` tip-bot for Yunlong Song
  0 siblings, 0 replies; 27+ messages in thread
From: tip-bot for Yunlong Song @ 2015-03-22 10:12 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: a.p.zijlstra, wangnan0, acme, paulus, mingo, tglx, yunlong.song,
	hpa, linux-kernel

Commit-ID:  33ec0caf6a3bce1289a915845866828e19c04afb
Gitweb:     http://git.kernel.org/tip/33ec0caf6a3bce1289a915845866828e19c04afb
Author:     Yunlong Song <yunlong.song@huawei.com>
AuthorDate: Wed, 18 Mar 2015 21:35:56 +0800
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Thu, 19 Mar 2015 13:53:25 -0300

perf tools: Add the bash completion for listing subsubcommands of perf timechart

The bash completion does not support listing subsubcommands for 'perf
timechart <TAB>', so fix it.

Example:

Before this patch:

 $ perf timechart <TAB>
 $

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

After this patch:

 $ perf timechart <TAB>
 record

As shown above, the subsubcommands of perf timechart 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-12-git-send-email-yunlong.song@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-timechart.c | 7 ++++---
 tools/perf/perf-completion.sh  | 2 +-
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c
index 51440d1..494b3bb 100644
--- a/tools/perf/builtin-timechart.c
+++ b/tools/perf/builtin-timechart.c
@@ -1958,7 +1958,8 @@ int cmd_timechart(int argc, const char **argv,
 		     parse_time),
 	OPT_END()
 	};
-	const char * const timechart_usage[] = {
+	const char * const timechart_subcommands[] = { "record", NULL };
+	const char *timechart_usage[] = {
 		"perf timechart [<options>] {record}",
 		NULL
 	};
@@ -1976,8 +1977,8 @@ int cmd_timechart(int argc, const char **argv,
 		"perf timechart record [<options>]",
 		NULL
 	};
-	argc = parse_options(argc, argv, timechart_options, timechart_usage,
-			PARSE_OPT_STOP_AT_NON_OPTION);
+	argc = parse_options_subcommand(argc, argv, timechart_options, timechart_subcommands,
+			timechart_usage, PARSE_OPT_STOP_AT_NON_OPTION);
 
 	if (tchart.power_only && tchart.tasks_only) {
 		pr_err("-P and -T options cannot be used at the same time.\n");
diff --git a/tools/perf/perf-completion.sh b/tools/perf/perf-completion.sh
index 35f43fd..a33d2ef5 100644
--- a/tools/perf/perf-completion.sh
+++ b/tools/perf/perf-completion.sh
@@ -143,7 +143,7 @@ __perf_main ()
 		__perfcomp_colon "$evts" "$cur"
 	else
 		# List subcommands for perf commands
-		if [[ $prev_skip_opts == @(kvm|kmem|mem|lock|sched|data|help|script|test) ]]; then
+		if [[ $prev_skip_opts == @(kvm|kmem|mem|lock|sched|data|help|script|test|timechart) ]]; then
 			subcmds=$($cmd $prev_skip_opts --list-cmds)
 			__perfcomp_colon "$subcmds" "$cur"
 		fi

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [tip:perf/core] perf tools: Add the bash completion for listing subsubcommands of perf trace
  2015-03-18 13:35 ` [PATCH 12/13] perf tools: Add the bash completion for listing subsubcommands of perf trace Yunlong Song
@ 2015-03-22 10:12   ` tip-bot for Yunlong Song
  0 siblings, 0 replies; 27+ messages in thread
From: tip-bot for Yunlong Song @ 2015-03-22 10:12 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, yunlong.song, hpa, paulus, linux-kernel, tglx, wangnan0,
	mingo, a.p.zijlstra

Commit-ID:  6fdd9cb700dcd84193a259bbf8f6c918c243da15
Gitweb:     http://git.kernel.org/tip/6fdd9cb700dcd84193a259bbf8f6c918c243da15
Author:     Yunlong Song <yunlong.song@huawei.com>
AuthorDate: Wed, 18 Mar 2015 21:35:57 +0800
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Thu, 19 Mar 2015 13:53:26 -0300

perf tools: Add the bash completion for listing subsubcommands of perf trace

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    | 7 ++++---
 tools/perf/perf-completion.sh | 9 ++++++---
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 6969ba9..0b3b4e4 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -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;
diff --git a/tools/perf/perf-completion.sh b/tools/perf/perf-completion.sh
index a33d2ef5..bdd4035 100644
--- a/tools/perf/perf-completion.sh
+++ b/tools/perf/perf-completion.sh
@@ -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

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [tip:perf/core] perf tools: Avoid confusion with preloaded bash function for perf bash completion
  2015-03-18 13:35 ` [PATCH 13/13] perf tools: Avoid confusion with preloaded bash function for perf bash completion Yunlong Song
@ 2015-03-22 10:12   ` tip-bot for Yunlong Song
  0 siblings, 0 replies; 27+ messages in thread
From: tip-bot for Yunlong Song @ 2015-03-22 10:12 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: mingo, a.p.zijlstra, linux-kernel, yunlong.song, wangnan0, tglx,
	acme, hpa, paulus

Commit-ID:  1312c8a8fb126b9e7c45671813c39f8a435fadcb
Gitweb:     http://git.kernel.org/tip/1312c8a8fb126b9e7c45671813c39f8a435fadcb
Author:     Yunlong Song <yunlong.song@huawei.com>
AuthorDate: Wed, 18 Mar 2015 21:35:58 +0800
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Thu, 19 Mar 2015 13:53:27 -0300

perf tools: Avoid confusion with preloaded bash function for perf bash completion

Since some functions (e.g. '_get_comp_words_by_ref()') in perf bash
completion script are originally taken from git bash completion script,
these functions may be preloaded before perf bash completion script
runs.

In order to avoid repeating loading the same function twice, some test
constraints are used before these function definitions in the perf bash
completion script (e.g. 'type _get_comp_words_by_ref &>/dev/null ||').

The problem is that, if these functions in perf bash completion script
are changed for some reason, perf will still use the preloaded bash
functions rather than the customized functions of its own.

As a result, the perf bash completion will behave incorrectly. To get
rid of this problem, a flag can be defined to determine the proper
situation.

And to avoid overwriting the preloaded functions, the names of these
functions in perf bash completion script should be renamed to the
perf-customized ones.

Example:

Before this patch:

 $ type _get_comp_words_by_ref
 _get_comp_words_by_ref is a function
 _get_comp_words_by_ref ()
 {
     local exclude flag i OPTIND=1;
     local cur cword words=();
     local upargs=() upvars=() vcur vcword vprev vwords;
     while getopts "c:i:n:p:w:" flag "$@"; do
         case $flag in
             c)
                 vcur=$OPTARG
             ;;
             i)
                 vcword=$OPTARG
             ;;
             n)
                 exclude=$OPTARG
             ;;
             p)
                 vprev=$OPTARG
             ;;
             w)
                 vwords=$OPTARG
             ;;
         esac;
     done;
     while [[ $# -ge $OPTIND ]]; do
         case ${!OPTIND} in
             cur)
                 vcur=cur
             ;;
             prev)
                 vprev=prev
             ;;
             cword)
                 vcword=cword
             ;;
             words)
                 vwords=words
             ;;
             *)
                 echo "bash: $FUNCNAME(): \`${!OPTIND}': unknown argument" 1>&2;
                 return 1
             ;;
         esac;
         let "OPTIND += 1";
     done;
     __get_cword_at_cursor_by_ref "$exclude" words cword cur;
     [[ -n $vcur ]] && {
         upvars+=("$vcur");
         upargs+=(-v $vcur "$cur")
     };
     [[ -n $vcword ]] && {
         upvars+=("$vcword");
         upargs+=(-v $vcword "$cword")
     };
     [[ -n $vprev && $cword -ge 1 ]] && {
         upvars+=("$vprev");
         upargs+=(-v $vprev "${words[cword - 1]}")
     };
     [[ -n $vwords ]] && {
         upvars+=("$vwords");
         upargs+=(-a${#words[@]} $vwords "${words[@]}")
     };
     (( ${#upvars[@]} )) && local "${upvars[@]}" && _upvars "${upargs[@]}"
 }

As shown above, the _get_comp_words_by_ref is the preloaded function in
fact, rather than the function defined in perf-completion.sh. So if we
happen to change the function for some reason, the result will behave in
a wrong state.

After this patch:

We can set preload_get_comp_words_by_ref="false" to not use the preloaded
function. Instead, it will use the function defined in perf-completion.sh,
which is renamed as __perf_get_comp_words_by_ref to avoid overwriting
the preloaded function _get_comp_words_by_ref.

 $ type __perf_get_comp_words_by_ref
 __perf_get_comp_words_by_ref is a function
 __perf_get_comp_words_by_ref ()
 {
     local exclude cur_ words_ cword_;
     if [ "$1" = "-n" ]; then
         exclude=$2;
         shift 2;
     fi;
     __my_reassemble_comp_words_by_ref "$exclude";
     cur_=${words_[cword_]};
     while [ $# -gt 0 ]; do
         case "$1" in
             cur)
                 cur=$cur_
             ;;
             prev)
                 prev=${words_[$cword_-1]}
             ;;
             words)
                 words=("${words_[@]}")
             ;;
             cword)
                 cword=$cword_
             ;;
         esac;
         shift;
     done
 }

As shown above, the function __perf_get_comp_words_by_ref is loaded and
can work this time.

Note that we do not change the original behavior when those functions are
not preloaded before perf bash completion script runs. In this case,
although the flag is set to "true", the code will still change it to
"false" to use the function defined in perf-completion.sh.

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-14-git-send-email-yunlong.song@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/perf-completion.sh | 36 ++++++++++++++++++++++++++++++------
 1 file changed, 30 insertions(+), 6 deletions(-)

diff --git a/tools/perf/perf-completion.sh b/tools/perf/perf-completion.sh
index bdd4035..3ba80b2 100644
--- a/tools/perf/perf-completion.sh
+++ b/tools/perf/perf-completion.sh
@@ -47,8 +47,16 @@ __my_reassemble_comp_words_by_ref()
 	done
 }
 
-type _get_comp_words_by_ref &>/dev/null ||
-_get_comp_words_by_ref()
+# Define preload_get_comp_words_by_ref="false", if the function
+# __perf_get_comp_words_by_ref() is required instead.
+preload_get_comp_words_by_ref="true"
+
+if [ $preload_get_comp_words_by_ref = "true" ]; then
+	type _get_comp_words_by_ref &>/dev/null ||
+	preload_get_comp_words_by_ref="false"
+fi
+[ $preload_get_comp_words_by_ref = "true" ] ||
+__perf_get_comp_words_by_ref()
 {
 	local exclude cur_ words_ cword_
 	if [ "$1" = "-n" ]; then
@@ -76,8 +84,16 @@ _get_comp_words_by_ref()
 	done
 }
 
-type __ltrim_colon_completions &>/dev/null ||
-__ltrim_colon_completions()
+# Define preload__ltrim_colon_completions="false", if the function
+# __perf__ltrim_colon_completions() is required instead.
+preload__ltrim_colon_completions="true"
+
+if [ $preload__ltrim_colon_completions = "true" ]; then
+	type __ltrim_colon_completions &>/dev/null ||
+	preload__ltrim_colon_completions="false"
+fi
+[ $preload__ltrim_colon_completions = "true" ] ||
+__perf__ltrim_colon_completions()
 {
 	if [[ "$1" == *:* && "$COMP_WORDBREAKS" == *:* ]]; then
 		# Remove colon-word prefix from COMPREPLY items
@@ -97,7 +113,11 @@ __perfcomp ()
 __perfcomp_colon ()
 {
 	__perfcomp "$1" "$2"
-	__ltrim_colon_completions $cur
+	if [ $preload__ltrim_colon_completions = "true" ]; then
+		__ltrim_colon_completions $cur
+	else
+		__perf__ltrim_colon_completions $cur
+	fi
 }
 
 __perf_prev_skip_opts ()
@@ -226,7 +246,11 @@ type perf &>/dev/null &&
 _perf()
 {
 	local cur words cword prev
-	_get_comp_words_by_ref -n =: cur words cword prev
+	if [ $preload_get_comp_words_by_ref = "true" ]; then
+		_get_comp_words_by_ref -n =: cur words cword prev
+	else
+		__perf_get_comp_words_by_ref -n =: cur words cword prev
+	fi
 	__perf_main
 } &&
 

^ permalink raw reply related	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2015-03-22 10:13 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-18 13:35 [PATCH 00/13] perf tools: Make some improvements and fixes Yunlong Song
2015-03-18 13:35 ` [PATCH 01/13] perf tools: Fix the bash completion for listing options of perf subcommand Yunlong Song
2015-03-22 10:09   ` [tip:perf/core] " tip-bot for Yunlong Song
2015-03-18 13:35 ` [PATCH 02/13] perf tools: Fix the bash completion for listing subsubcommands " Yunlong Song
2015-03-22 10:09   ` [tip:perf/core] " tip-bot for Yunlong Song
2015-03-18 13:35 ` [PATCH 03/13] perf tools: Provide the right bash completion for listing options of perf subcommand subsubcommand Yunlong Song
2015-03-22 10:09   ` [tip:perf/core] " tip-bot for Yunlong Song
2015-03-18 13:35 ` [PATCH 04/13] perf tools: Fix the bash completion for listing events of perf subcommand record|stat|top -e Yunlong Song
2015-03-22 10:10   ` [tip:perf/core] " tip-bot for Yunlong Song
2015-03-18 13:35 ` [PATCH 05/13] perf tools: Fix the bash completion to support listing events for --event Yunlong Song
2015-03-22 10:10   ` [tip:perf/core] " tip-bot for Yunlong Song
2015-03-18 13:35 ` [PATCH 06/13] perf tools: Fix the bash completion for listing subcommands of perf Yunlong Song
2015-03-22 10:10   ` [tip:perf/core] " tip-bot for Yunlong Song
2015-03-18 13:35 ` [PATCH 07/13] perf tools: Add the bash completion for listing subsubcommands of perf data Yunlong Song
2015-03-22 10:11   ` [tip:perf/core] " tip-bot for Yunlong Song
2015-03-18 13:35 ` [PATCH 08/13] perf tools: Add the bash completion for listing subsubcommands of perf help Yunlong Song
2015-03-22 10:11   ` [tip:perf/core] " tip-bot for Yunlong Song
2015-03-18 13:35 ` [PATCH 09/13] perf tools: Add the bash completion for listing subsubcommands of perf script Yunlong Song
2015-03-22 10:11   ` [tip:perf/core] " tip-bot for Yunlong Song
2015-03-18 13:35 ` [PATCH 10/13] perf tools: Add the bash completion for listing subsubcommands of perf test Yunlong Song
2015-03-22 10:11   ` [tip:perf/core] " tip-bot for Yunlong Song
2015-03-18 13:35 ` [PATCH 11/13] perf tools: Add the bash completion for listing subsubcommands of perf timechart Yunlong Song
2015-03-22 10:12   ` [tip:perf/core] " tip-bot for Yunlong Song
2015-03-18 13:35 ` [PATCH 12/13] perf tools: Add the bash completion for listing subsubcommands of perf trace Yunlong Song
2015-03-22 10:12   ` [tip:perf/core] " tip-bot for Yunlong Song
2015-03-18 13:35 ` [PATCH 13/13] perf tools: Avoid confusion with preloaded bash function for perf bash completion Yunlong Song
2015-03-22 10:12   ` [tip:perf/core] " tip-bot for Yunlong Song

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).