perf test: Fix shadow stat test for non-bash shells
Namhyung Kim
maintainerPATCH 1/1 perf test: Fix shadow stat test for non-bash shells
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!
--- tools/perf/tests/shell/stat+shadow_stat.sh | 24 ++++++++++++---------- 1 file changed, 13 insertions(+), 11 deletions(-)
tools/perf/tests/shell/stat+shadow_stat.sh +13 -11
@@ -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
Signature · 1 line
2.30.0.284.gd98b1dd5eaa7-goog
Quoted 22 lines · Namhyung Kim
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!
Quoted 2 lines
Reported-by Jin Yao <[email protected]>Signed-off-by Namhyung Kim <[email protected]>
thanks,
jirka
Quoted 86 lines
--- tools/perf/tests/shell/stat+shadow_stat.sh | 24 ++++++++++++---------- 1 file changed, 13 insertions(+), 11 deletions(-)tools/perf/tests/shell/stat+shadow_stat.sh +13
-11@@ -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_aggrSignature · 1 line
2.30.0.284.gd98b1dd5eaa7-goog
From: Jiri Olsa
Quoted 5 lines
Sent: 12 January 2021 09:30
Quoted 2 lines · Namhyung Kim
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:
Quoted 3 lines
Quoted 3 lines
index
249dfe48cf6a..e2c7ac4ed91d100755tools/perf/tests/shell/stat+shadow_stat.sh +0
-0
...
Quoted 4 lines
Quoted 4 lines
tools/perf/tests/shell/stat+shadow_stat.sh +0
-0perf stat -a -A --no-big-num -e cycles,instructions sleep 1 2>&1 | \ grep ^CPU | \ while read cpu num evt hash ipc rest do
...
Quoted 2 lines
tools/perf/tests/shell/stat+shadow_stat.sh test_global_aggr() · line 58
Quoted 2 lines
tools/perf/tests/shell/stat+shadow_stat.sh +2
-0+ if [ "$evt" = "cycles" ]; then + echo $cpu $num >> $results
results="$results $cpu:$num"
Quoted 7 lines
tools/perf/tests/shell/stat+shadow_stat.sh test_global_aggr() · line 63
Quoted 7 lines
tools/perf/tests/shell/stat+shadow_stat.sh +1
-2continue 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%% *}Quoted 3 lines
tools/perf/tests/shell/stat+shadow_stat.sh test_global_aggr() · line 32
Quoted 3 lines
tools/perf/tests/shell/stat+shadow_stat.sh +1
-0+ 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)
Namhyung Kim
maintainerHello,
Quoted 36 lines · David Laight
From: Jiri Olsa
Quoted 5 lines
Sent: 12 January 2021 09:30
Quoted 2 lines · Namhyung Kim
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:
Quoted 3 lines
Quoted 3 lines
index
249dfe48cf6a..e2c7ac4ed91d100755tools/perf/tests/shell/stat+shadow_stat.sh +0
-0...
Quoted 4 lines
Quoted 4 lines
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...
Quoted 2 lines
tools/perf/tests/shell/stat+shadow_stat.sh test_global_aggr() · line 58
Quoted 2 lines
tools/perf/tests/shell/stat+shadow_stat.sh +2
-0+ if [ "$evt" = "cycles" ]; then + echo $cpu $num >> $resultsresults="$results $cpu:$num"
Quoted 7 lines
tools/perf/tests/shell/stat+shadow_stat.sh test_global_aggr() · line 63
Quoted 7 lines
continue
fi# skip if no cycles
tools/perf/tests/shell/stat+shadow_stat.sh +1
-2- local cyc=${results[$cpu]} - if [[ -z $cyc ]]; then + local cyc=$(grep $cpu $results | cut -d' ' -f2)cyc=${results##* $cpu:} cyc=$(cyc%% *}
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
+ if [ -z "$cyc" ]; then
continue
fiI 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