Commit | Line | Data |
---|---|---|
94b69c61 NK |
1 | #!/bin/sh |
2 | # perf stat metrics (shadow stat) test | |
3 | # SPDX-License-Identifier: GPL-2.0 | |
4 | ||
5 | set -e | |
6 | ||
7 | # skip if system-wide mode is forbidden | |
8 | perf stat -a true > /dev/null 2>&1 || exit 2 | |
9 | ||
10 | test_global_aggr() | |
11 | { | |
94b69c61 NK |
12 | perf stat -a --no-big-num -e cycles,instructions sleep 1 2>&1 | \ |
13 | grep -e cycles -e instructions | \ | |
14 | while read num evt hash ipc rest | |
15 | do | |
16 | # skip not counted events | |
a042a82d | 17 | if [ "$num" = "<not" ]; then |
94b69c61 NK |
18 | continue |
19 | fi | |
20 | ||
21 | # save cycles count | |
a042a82d | 22 | if [ "$evt" = "cycles" ]; then |
94b69c61 NK |
23 | cyc=$num |
24 | continue | |
25 | fi | |
26 | ||
27 | # skip if no cycles | |
a042a82d | 28 | if [ -z "$cyc" ]; then |
94b69c61 NK |
29 | continue |
30 | fi | |
31 | ||
32 | # use printf for rounding and a leading zero | |
a042a82d NK |
33 | res=`printf "%.2f" $(echo "scale=6; $num / $cyc" | bc -q)` |
34 | if [ "$ipc" != "$res" ]; then | |
94b69c61 NK |
35 | echo "IPC is different: $res != $ipc ($num / $cyc)" |
36 | exit 1 | |
37 | fi | |
38 | done | |
39 | } | |
40 | ||
41 | test_no_aggr() | |
42 | { | |
94b69c61 NK |
43 | perf stat -a -A --no-big-num -e cycles,instructions sleep 1 2>&1 | \ |
44 | grep ^CPU | \ | |
45 | while read cpu num evt hash ipc rest | |
46 | do | |
47 | # skip not counted events | |
a042a82d | 48 | if [ "$num" = "<not" ]; then |
94b69c61 NK |
49 | continue |
50 | fi | |
51 | ||
52 | # save cycles count | |
a042a82d NK |
53 | if [ "$evt" = "cycles" ]; then |
54 | results="$results $cpu:$num" | |
94b69c61 NK |
55 | continue |
56 | fi | |
57 | ||
a042a82d NK |
58 | cyc=${results##* $cpu:} |
59 | cyc=${cyc%% *} | |
60 | ||
94b69c61 | 61 | # skip if no cycles |
a042a82d | 62 | if [ -z "$cyc" ]; then |
94b69c61 NK |
63 | continue |
64 | fi | |
65 | ||
66 | # use printf for rounding and a leading zero | |
a042a82d NK |
67 | res=`printf "%.2f" $(echo "scale=6; $num / $cyc" | bc -q)` |
68 | if [ "$ipc" != "$res" ]; then | |
94b69c61 NK |
69 | echo "IPC is different for $cpu: $res != $ipc ($num / $cyc)" |
70 | exit 1 | |
71 | fi | |
72 | done | |
73 | } | |
74 | ||
75 | test_global_aggr | |
76 | test_no_aggr | |
77 | ||
78 | exit 0 |