Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / tools / perf / tests / shell / stat+shadow_stat.sh
blob0c7d79a230eac2918c0a8a528c3a6824edea738d
1 #!/bin/sh
2 # perf stat metrics (shadow stat) test
3 # SPDX-License-Identifier: GPL-2.0
5 set -e
7 THRESHOLD=0.015
9 # skip if system-wide mode is forbidden
10 perf stat -a true > /dev/null 2>&1 || exit 2
12 # skip if on hybrid platform
13 perf stat -a -e cycles sleep 1 2>&1 | grep -e cpu_core && exit 2
15 test_global_aggr()
17 perf stat -a --no-big-num -e cycles,instructions sleep 1 2>&1 | \
18 grep -e cycles -e instructions | \
19 while read num evt _ ipc rest
21 # skip not counted events
22 if [ "$num" = "<not" ]; then
23 continue
26 # save cycles count
27 if [ "$evt" = "cycles" ]; then
28 cyc=$num
29 continue
32 # skip if no cycles
33 if [ -z "$cyc" ]; then
34 continue
37 # use printf for rounding and a leading zero
38 res=`echo $num $cyc | awk '{printf "%.2f", $1 / $2}'`
39 if [ "$ipc" != "$res" ]; then
40 # check the difference from the real result for FP imperfections
41 diff=`echo $ipc $res $THRESHOLD | \
42 awk '{x = ($1 - $2) < 0 ? ($2 - $1) : ($1 - $2); print (x > $3)}'`
44 if [ $diff -eq 1 ]; then
45 echo "IPC is different: $res != $ipc ($num / $cyc)"
46 exit 1
49 echo "Warning: Difference of IPC is under the threshold"
51 done
54 test_no_aggr()
56 perf stat -a -A --no-big-num -e cycles,instructions sleep 1 2>&1 | \
57 grep ^CPU | \
58 while read cpu num evt _ ipc rest
60 # skip not counted events
61 if [ "$num" = "<not" ]; then
62 continue
65 # save cycles count
66 if [ "$evt" = "cycles" ]; then
67 results="$results $cpu:$num"
68 continue
71 cyc=${results##* $cpu:}
72 cyc=${cyc%% *}
74 # skip if no cycles
75 if [ -z "$cyc" ]; then
76 continue
79 # use printf for rounding and a leading zero
80 res=`echo $num $cyc | awk '{printf "%.2f", $1 / $2}'`
81 if [ "$ipc" != "$res" ]; then
82 # check difference from the real result for FP imperfections
83 diff=`echo $ipc $res $THRESHOLD | \
84 awk '{x = ($1 - $2) < 0 ? ($2 - $1) : ($1 - $2); print (x > $3)}'`
86 if [ $diff -eq 1 ]; then
87 echo "IPC is different: $res != $ipc ($num / $cyc)"
88 exit 1
91 echo "Warning: Difference of IPC is under the threshold"
93 done
96 test_global_aggr
97 test_no_aggr
99 exit 0