linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] perf test: Fix shadow stat test for non-bash shells
@ 2021-01-08  7:47 Namhyung Kim
  2021-01-12  9:30 ` Jiri Olsa
  0 siblings, 1 reply; 4+ messages in thread
From: Namhyung Kim @ 2021-01-08  7:47 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Jiri Olsa
  Cc: Ingo Molnar, Peter Zijlstra, Mark Rutland, Alexander Shishkin,
	LKML, Stephane Eranian, Ian Rogers, Jin Yao

It was using some bash-specific features and failed to parse when
running with a different shell like below:

  root@kbl-ppc:~/kbl-ws/perf-dev/lck-9077/acme.tmp/tools/perf# ./perf test 83 -vv
  83: perf stat metrics (shadow stat) test                            :
  --- start ---
  test child forked, pid 3922
  ./tests/shell/stat+shadow_stat.sh: 19: ./tests/shell/stat+shadow_stat.sh: [[: not found
  ./tests/shell/stat+shadow_stat.sh: 24: ./tests/shell/stat+shadow_stat.sh: [[: not found
  ./tests/shell/stat+shadow_stat.sh: 30: ./tests/shell/stat+shadow_stat.sh: [[: not found
  (standard_in) 2: syntax error
  ./tests/shell/stat+shadow_stat.sh: 36: ./tests/shell/stat+shadow_stat.sh: [[: not found
  ./tests/shell/stat+shadow_stat.sh: 19: ./tests/shell/stat+shadow_stat.sh: [[: not found
  ./tests/shell/stat+shadow_stat.sh: 24: ./tests/shell/stat+shadow_stat.sh: [[: not found
  ./tests/shell/stat+shadow_stat.sh: 30: ./tests/shell/stat+shadow_stat.sh: [[: not found
  (standard_in) 2: syntax error
  ./tests/shell/stat+shadow_stat.sh: 36: ./tests/shell/stat+shadow_stat.sh: [[: not found
  ./tests/shell/stat+shadow_stat.sh: 45: ./tests/shell/stat+shadow_stat.sh: declare: not found
  test child finished with -1
  ---- end ----
  perf stat metrics (shadow stat) test: FAILED!

Reported-by: Jin Yao <yao.jin@linux.intel.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/tests/shell/stat+shadow_stat.sh | 24 ++++++++++++----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/tools/perf/tests/shell/stat+shadow_stat.sh b/tools/perf/tests/shell/stat+shadow_stat.sh
index 249dfe48cf6a..e2c7ac4ed91d 100755
--- a/tools/perf/tests/shell/stat+shadow_stat.sh
+++ b/tools/perf/tests/shell/stat+shadow_stat.sh
@@ -16,24 +16,24 @@ test_global_aggr()
 	while read num evt hash ipc rest
 	do
 		# skip not counted events
-		if [[ $num == "<not" ]]; then
+		if [ "$num" = "<not" ]; then
 			continue
 		fi
 
 		# save cycles count
-		if [[ $evt == "cycles" ]]; then
+		if [ "$evt" = "cycles" ]; then
 			cyc=$num
 			continue
 		fi
 
 		# skip if no cycles
-		if [[ -z $cyc ]]; then
+		if [ -z "$cyc" ]; then
 			continue
 		fi
 
 		# use printf for rounding and a leading zero
 		local res=`printf "%.2f" $(echo "scale=6; $num / $cyc" | bc -q)`
-		if [[ $ipc != $res ]]; then
+		if [ "$ipc" != "$res" ]; then
 			echo "IPC is different: $res != $ipc  ($num / $cyc)"
 			exit 1
 		fi
@@ -42,36 +42,38 @@ test_global_aggr()
 
 test_no_aggr()
 {
-	declare -A results
+	results=$(mktemp /tmp/perf-test-shadow-stat-XXXXXX)
 
 	perf stat -a -A --no-big-num -e cycles,instructions sleep 1  2>&1 | \
 	grep ^CPU | \
 	while read cpu num evt hash ipc rest
 	do
 		# skip not counted events
-		if [[ $num == "<not" ]]; then
+		if [ "$num" = "<not" ]; then
 			continue
 		fi
 
 		# save cycles count
-		if [[ $evt == "cycles" ]]; then
-			results[$cpu]=$num
+		if [ "$evt" = "cycles" ]; then
+			echo $cpu $num >> $results
 			continue
 		fi
 
 		# skip if no cycles
-		local cyc=${results[$cpu]}
-		if [[ -z $cyc ]]; then
+		local cyc=$(grep $cpu $results | cut -d' ' -f2)
+		if [ -z "$cyc" ]; then
 			continue
 		fi
 
 		# use printf for rounding and a leading zero
 		local res=`printf "%.2f" $(echo "scale=6; $num / $cyc" | bc -q)`
-		if [[ $ipc != $res ]]; then
+		if [ "$ipc" != "$res" ]; then
 			echo "IPC is different for $cpu: $res != $ipc  ($num / $cyc)"
+			rm -f $results
 			exit 1
 		fi
 	done
+	rm -f $results
 }
 
 test_global_aggr
-- 
2.30.0.284.gd98b1dd5eaa7-goog


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

* Re: [PATCH] perf test: Fix shadow stat test for non-bash shells
  2021-01-08  7:47 [PATCH] perf test: Fix shadow stat test for non-bash shells Namhyung Kim
@ 2021-01-12  9:30 ` Jiri Olsa
  2021-01-12 11:17   ` David Laight
  0 siblings, 1 reply; 4+ messages in thread
From: Jiri Olsa @ 2021-01-12  9:30 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Arnaldo Carvalho de Melo, Ingo Molnar, Peter Zijlstra,
	Mark Rutland, Alexander Shishkin, LKML, Stephane Eranian,
	Ian Rogers, Jin Yao

On Fri, Jan 08, 2021 at 04:47:12PM +0900, Namhyung Kim wrote:
> It was using some bash-specific features and failed to parse when
> running with a different shell like below:
> 
>   root@kbl-ppc:~/kbl-ws/perf-dev/lck-9077/acme.tmp/tools/perf# ./perf test 83 -vv
>   83: perf stat metrics (shadow stat) test                            :
>   --- start ---
>   test child forked, pid 3922
>   ./tests/shell/stat+shadow_stat.sh: 19: ./tests/shell/stat+shadow_stat.sh: [[: not found
>   ./tests/shell/stat+shadow_stat.sh: 24: ./tests/shell/stat+shadow_stat.sh: [[: not found
>   ./tests/shell/stat+shadow_stat.sh: 30: ./tests/shell/stat+shadow_stat.sh: [[: not found
>   (standard_in) 2: syntax error
>   ./tests/shell/stat+shadow_stat.sh: 36: ./tests/shell/stat+shadow_stat.sh: [[: not found
>   ./tests/shell/stat+shadow_stat.sh: 19: ./tests/shell/stat+shadow_stat.sh: [[: not found
>   ./tests/shell/stat+shadow_stat.sh: 24: ./tests/shell/stat+shadow_stat.sh: [[: not found
>   ./tests/shell/stat+shadow_stat.sh: 30: ./tests/shell/stat+shadow_stat.sh: [[: not found
>   (standard_in) 2: syntax error
>   ./tests/shell/stat+shadow_stat.sh: 36: ./tests/shell/stat+shadow_stat.sh: [[: not found
>   ./tests/shell/stat+shadow_stat.sh: 45: ./tests/shell/stat+shadow_stat.sh: declare: not found
>   test child finished with -1
>   ---- end ----
>   perf stat metrics (shadow stat) test: FAILED!
> 
> Reported-by: Jin Yao <yao.jin@linux.intel.com>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>

Acked-by: Jiri Olsa <jolsa@redhat.com>

thanks,
jirka

> ---
>  tools/perf/tests/shell/stat+shadow_stat.sh | 24 ++++++++++++----------
>  1 file changed, 13 insertions(+), 11 deletions(-)
> 
> diff --git a/tools/perf/tests/shell/stat+shadow_stat.sh b/tools/perf/tests/shell/stat+shadow_stat.sh
> index 249dfe48cf6a..e2c7ac4ed91d 100755
> --- a/tools/perf/tests/shell/stat+shadow_stat.sh
> +++ b/tools/perf/tests/shell/stat+shadow_stat.sh
> @@ -16,24 +16,24 @@ test_global_aggr()
>  	while read num evt hash ipc rest
>  	do
>  		# skip not counted events
> -		if [[ $num == "<not" ]]; then
> +		if [ "$num" = "<not" ]; then
>  			continue
>  		fi
>  
>  		# save cycles count
> -		if [[ $evt == "cycles" ]]; then
> +		if [ "$evt" = "cycles" ]; then
>  			cyc=$num
>  			continue
>  		fi
>  
>  		# skip if no cycles
> -		if [[ -z $cyc ]]; then
> +		if [ -z "$cyc" ]; then
>  			continue
>  		fi
>  
>  		# use printf for rounding and a leading zero
>  		local res=`printf "%.2f" $(echo "scale=6; $num / $cyc" | bc -q)`
> -		if [[ $ipc != $res ]]; then
> +		if [ "$ipc" != "$res" ]; then
>  			echo "IPC is different: $res != $ipc  ($num / $cyc)"
>  			exit 1
>  		fi
> @@ -42,36 +42,38 @@ test_global_aggr()
>  
>  test_no_aggr()
>  {
> -	declare -A results
> +	results=$(mktemp /tmp/perf-test-shadow-stat-XXXXXX)
>  
>  	perf stat -a -A --no-big-num -e cycles,instructions sleep 1  2>&1 | \
>  	grep ^CPU | \
>  	while read cpu num evt hash ipc rest
>  	do
>  		# skip not counted events
> -		if [[ $num == "<not" ]]; then
> +		if [ "$num" = "<not" ]; then
>  			continue
>  		fi
>  
>  		# save cycles count
> -		if [[ $evt == "cycles" ]]; then
> -			results[$cpu]=$num
> +		if [ "$evt" = "cycles" ]; then
> +			echo $cpu $num >> $results
>  			continue
>  		fi
>  
>  		# skip if no cycles
> -		local cyc=${results[$cpu]}
> -		if [[ -z $cyc ]]; then
> +		local cyc=$(grep $cpu $results | cut -d' ' -f2)
> +		if [ -z "$cyc" ]; then
>  			continue
>  		fi
>  
>  		# use printf for rounding and a leading zero
>  		local res=`printf "%.2f" $(echo "scale=6; $num / $cyc" | bc -q)`
> -		if [[ $ipc != $res ]]; then
> +		if [ "$ipc" != "$res" ]; then
>  			echo "IPC is different for $cpu: $res != $ipc  ($num / $cyc)"
> +			rm -f $results
>  			exit 1
>  		fi
>  	done
> +	rm -f $results
>  }
>  
>  test_global_aggr
> -- 
> 2.30.0.284.gd98b1dd5eaa7-goog
> 


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

* RE: [PATCH] perf test: Fix shadow stat test for non-bash shells
  2021-01-12  9:30 ` Jiri Olsa
@ 2021-01-12 11:17   ` David Laight
  2021-01-14  3:19     ` Namhyung Kim
  0 siblings, 1 reply; 4+ messages in thread
From: David Laight @ 2021-01-12 11:17 UTC (permalink / raw)
  To: 'Jiri Olsa', Namhyung Kim
  Cc: Arnaldo Carvalho de Melo, Ingo Molnar, Peter Zijlstra,
	Mark Rutland, Alexander Shishkin, LKML, Stephane Eranian,
	Ian Rogers, Jin Yao

From: Jiri Olsa
> Sent: 12 January 2021 09:30
> 
> On Fri, Jan 08, 2021 at 04:47:12PM +0900, Namhyung Kim wrote:
> > It was using some bash-specific features and failed to parse when
> > running with a different shell like below:
...

You don't need a temporary file, one option is:

> > index 249dfe48cf6a..e2c7ac4ed91d 100755
> > --- a/tools/perf/tests/shell/stat+shadow_stat.sh
> > +++ b/tools/perf/tests/shell/stat+shadow_stat.sh
...
> >  	perf stat -a -A --no-big-num -e cycles,instructions sleep 1  2>&1 | \
> >  	grep ^CPU | \
> >  	while read cpu num evt hash ipc rest
> >  	do
...
> > +		if [ "$evt" = "cycles" ]; then
> > +			echo $cpu $num >> $results

			results="$results $cpu:$num"

> >  			continue
> >  		fi
> >
> >  		# skip if no cycles
> > -		local cyc=${results[$cpu]}
> > -		if [[ -z $cyc ]]; then
> > +		local cyc=$(grep $cpu $results | cut -d' ' -f2)

		cyc=${results##* $cpu:}
		cyc=$(cyc%% *}

> > +		if [ -z "$cyc" ]; then
> >  			continue
> >  		fi

I can't remember when 'local' was invented.
You may find shells that don't support it.
In any case, since this is a small standalone file I'd
remove them just in case.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


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

* Re: [PATCH] perf test: Fix shadow stat test for non-bash shells
  2021-01-12 11:17   ` David Laight
@ 2021-01-14  3:19     ` Namhyung Kim
  0 siblings, 0 replies; 4+ messages in thread
From: Namhyung Kim @ 2021-01-14  3:19 UTC (permalink / raw)
  To: David Laight
  Cc: Jiri Olsa, Arnaldo Carvalho de Melo, Ingo Molnar, Peter Zijlstra,
	Mark Rutland, Alexander Shishkin, LKML, Stephane Eranian,
	Ian Rogers, Jin Yao

Hello,

On Tue, Jan 12, 2021 at 8:17 PM David Laight <David.Laight@aculab.com> wrote:
>
> From: Jiri Olsa
> > Sent: 12 January 2021 09:30
> >
> > On Fri, Jan 08, 2021 at 04:47:12PM +0900, Namhyung Kim wrote:
> > > It was using some bash-specific features and failed to parse when
> > > running with a different shell like below:
> ...
>
> You don't need a temporary file, one option is:
>
> > > index 249dfe48cf6a..e2c7ac4ed91d 100755
> > > --- a/tools/perf/tests/shell/stat+shadow_stat.sh
> > > +++ b/tools/perf/tests/shell/stat+shadow_stat.sh
> ...
> > >     perf stat -a -A --no-big-num -e cycles,instructions sleep 1  2>&1 | \
> > >     grep ^CPU | \
> > >     while read cpu num evt hash ipc rest
> > >     do
> ...
> > > +           if [ "$evt" = "cycles" ]; then
> > > +                   echo $cpu $num >> $results
>
>                         results="$results $cpu:$num"
>
> > >                     continue
> > >             fi
> > >
> > >             # skip if no cycles
> > > -           local cyc=${results[$cpu]}
> > > -           if [[ -z $cyc ]]; then
> > > +           local cyc=$(grep $cpu $results | cut -d' ' -f2)
>
>                 cyc=${results##* $cpu:}
>                 cyc=$(cyc%% *}
>
> > > +           if [ -z "$cyc" ]; then
> > >                     continue
> > >             fi
>
> I can't remember when 'local' was invented.
> You may find shells that don't support it.
> In any case, since this is a small standalone file I'd
> remove them just in case.

Thanks for your review, I'll make the change.

Thanks,
Namhyung

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

end of thread, other threads:[~2021-01-14  3:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-08  7:47 [PATCH] perf test: Fix shadow stat test for non-bash shells Namhyung Kim
2021-01-12  9:30 ` Jiri Olsa
2021-01-12 11:17   ` David Laight
2021-01-14  3:19     ` Namhyung Kim

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).