1#!/bin/bash 2# perf all metrics test 3# SPDX-License-Identifier: GPL-2.0 4 5ParanoidAndNotRoot() 6{ 7 [ "$(id -u)" != 0 ] && [ "$(cat /proc/sys/kernel/perf_event_paranoid)" -gt $1 ] 8} 9 10test_prog="true" 11system_wide_flag="-a" 12if ParanoidAndNotRoot 0 13then 14 system_wide_flag="" 15 test_prog="perf test -w noploop 0.01" 16fi 17 18check_metric() { 19 local output="$1" 20 local status="$2" 21 local metric="$3" 22 23 if [[ $status -ne 0 || ! "$output" =~ ${metric:0:50} ]]; then 24 return 1 25 fi 26 27 if [[ "$output" =~ "<not counted>" || "$output" =~ "<not supported>" ]]; then 28 return 1 29 fi 30 31 return 0 32} 33 34skip=0 35err=3 36for m in $(perf list --raw-dump metrics); do 37 echo "Testing $m" 38 result=$(perf stat -M "$m" $system_wide_flag -- $test_prog 2>&1) 39 result_err=$? 40 41 if check_metric "$result" $result_err "$m"; then 42 if [[ "$err" -ne 1 ]] 43 then 44 err=0 45 fi 46 continue 47 fi 48 49 if [[ "$result" =~ "Access to performance monitoring and observability operations is limited" || \ 50 "$result" =~ "in per-thread mode, enable system wide" || \ 51 "$result" =~ "<not supported>" || \ 52 "$result" =~ "Cannot resolve IDs for" || \ 53 "$result" =~ "No supported events found" || \ 54 "$result" =~ "FP_ARITH" || \ 55 "$result" =~ "AMX" || \ 56 "$result" =~ "PMM" ]] 57 then 58 true 59 else 60 result=$(perf stat -M "$m" $system_wide_flag -- perf test -w noploop 0.1 2>&1) 61 result_err=$? 62 63 if check_metric "$result" $result_err "$m"; then 64 if [[ "$err" -ne 1 ]] 65 then 66 err=0 67 fi 68 continue 69 fi 70 fi 71 72 # If retry also failed, determine if we skip, ignore, or fail 73 if [[ "$result" =~ "Access to performance monitoring and observability operations is limited" ]] 74 then 75 echo "[Skipped $m] Permission failure" 76 echo $result 77 if [[ $err -eq 0 ]] 78 then 79 skip=1 80 fi 81 continue 82 elif [[ "$result" =~ "in per-thread mode, enable system wide" ]] 83 then 84 echo "[Skipped $m] Permissions - need system wide mode" 85 echo $result 86 if [[ $err -eq 0 ]] 87 then 88 skip=1 89 fi 90 continue 91 elif [[ "$result" =~ "<not supported>" || \ 92 "$result" =~ "Cannot resolve IDs for" || \ 93 "$result" =~ "No supported events found" ]] 94 then 95 if [[ $(perf list --raw-dump $m) == "Default"* ]] 96 then 97 echo "[Ignored $m] failed but as a Default metric this can be expected" 98 echo $result 99 continue 100 fi 101 echo "[Skipped $m] Not supported events" 102 echo $result 103 if [[ $err -eq 0 ]] 104 then 105 skip=1 106 fi 107 continue 108 elif [[ "$result" =~ "<not counted>" ]] 109 then 110 echo "[Skipped $m] Not counted events" 111 echo $result 112 if [[ $err -eq 0 ]] 113 then 114 skip=1 115 fi 116 continue 117 elif [[ "$result" =~ "FP_ARITH" || "$result" =~ "AMX" ]] 118 then 119 echo "[Skipped $m] FP issues" 120 echo $result 121 if [[ $err -eq 0 ]] 122 then 123 skip=1 124 fi 125 continue 126 elif [[ "$result" =~ "PMM" ]] 127 then 128 echo "[Skipped $m] Optane memory issues" 129 echo $result 130 if [[ $err -eq 0 ]] 131 then 132 skip=1 133 fi 134 continue 135 fi 136 137 echo "[Failed $m] has non-zero error '$result_err' or not printed/counted in:" 138 echo "$result" 139 err=1 140done 141 142# return SKIP only if no success returned 143if [[ "$err" -eq 3 && "$skip" -eq 1 ]] 144then 145 err=2 146fi 147 148exit "$err" 149