Merge tag 'powerpc-5.11-3' of git://git.kernel.org/pub/scm/linux/kernel/git/powerpc...
[linux/fpc-iii.git] / tools / perf / tests / shell / stat+shadow_stat.sh
blob249dfe48cf6ad490d1f3066e137d7f843cce00ab
1 #!/bin/sh
2 # perf stat metrics (shadow stat) test
3 # SPDX-License-Identifier: GPL-2.0
5 set -e
7 # skip if system-wide mode is forbidden
8 perf stat -a true > /dev/null 2>&1 || exit 2
10 test_global_aggr()
12 local cyc
14 perf stat -a --no-big-num -e cycles,instructions sleep 1 2>&1 | \
15 grep -e cycles -e instructions | \
16 while read num evt hash ipc rest
18 # skip not counted events
19 if [[ $num == "<not" ]]; then
20 continue
23 # save cycles count
24 if [[ $evt == "cycles" ]]; then
25 cyc=$num
26 continue
29 # skip if no cycles
30 if [[ -z $cyc ]]; then
31 continue
34 # use printf for rounding and a leading zero
35 local res=`printf "%.2f" $(echo "scale=6; $num / $cyc" | bc -q)`
36 if [[ $ipc != $res ]]; then
37 echo "IPC is different: $res != $ipc ($num / $cyc)"
38 exit 1
40 done
43 test_no_aggr()
45 declare -A results
47 perf stat -a -A --no-big-num -e cycles,instructions sleep 1 2>&1 | \
48 grep ^CPU | \
49 while read cpu num evt hash ipc rest
51 # skip not counted events
52 if [[ $num == "<not" ]]; then
53 continue
56 # save cycles count
57 if [[ $evt == "cycles" ]]; then
58 results[$cpu]=$num
59 continue
62 # skip if no cycles
63 local cyc=${results[$cpu]}
64 if [[ -z $cyc ]]; then
65 continue
68 # use printf for rounding and a leading zero
69 local res=`printf "%.2f" $(echo "scale=6; $num / $cyc" | bc -q)`
70 if [[ $ipc != $res ]]; then
71 echo "IPC is different for $cpu: $res != $ipc ($num / $cyc)"
72 exit 1
74 done
77 test_global_aggr
78 test_no_aggr
80 exit 0