1#!/bin/sh 2# perf stat metrics (shadow stat) test 3# SPDX-License-Identifier: GPL-2.0 4 5set -e 6 7# skip if system-wide mode is forbidden 8perf stat -a true > /dev/null 2>&1 || exit 2 9 10test_global_aggr() 11{ 12 local cyc 13 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 17 do 18 # skip not counted events 19 if [[ $num == "<not" ]]; then 20 continue 21 fi 22 23 # save cycles count 24 if [[ $evt == "cycles" ]]; then 25 cyc=$num 26 continue 27 fi 28 29 # skip if no cycles 30 if [[ -z $cyc ]]; then 31 continue 32 fi 33 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 39 fi 40 done 41} 42 43test_no_aggr() 44{ 45 declare -A results 46 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 50 do 51 # skip not counted events 52 if [[ $num == "<not" ]]; then 53 continue 54 fi 55 56 # save cycles count 57 if [[ $evt == "cycles" ]]; then 58 results[$cpu]=$num 59 continue 60 fi 61 62 # skip if no cycles 63 local cyc=${results[$cpu]} 64 if [[ -z $cyc ]]; then 65 continue 66 fi 67 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 73 fi 74 done 75} 76 77test_global_aggr 78test_no_aggr 79 80exit 0 81