Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf test: Update all metrics test like metricgroups test

Like in the metricgroup tests, it should check the permission first and
then skip relevant failures accordingly.

Also it needs to try again with the system wide flag properly. On the
second round, check if the result has the metric name because other
failure cases are checked in the first round already.

Reviewed-by: Ian Rogers <irogers@google.com>
Link: https://lore.kernel.org/r/20241018204306.741972-1-namhyung@kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>

+66 -21
+66 -21
tools/perf/tests/shell/stat_all_metrics.sh
··· 2 2 # perf all metrics test 3 3 # SPDX-License-Identifier: GPL-2.0 4 4 5 + ParanoidAndNotRoot() 6 + { 7 + [ "$(id -u)" != 0 ] && [ "$(cat /proc/sys/kernel/perf_event_paranoid)" -gt $1 ] 8 + } 9 + 10 + system_wide_flag="-a" 11 + if ParanoidAndNotRoot 0 12 + then 13 + system_wide_flag="" 14 + fi 15 + 5 16 err=0 6 17 for m in $(perf list --raw-dump metrics); do 7 18 echo "Testing $m" 8 - result=$(perf stat -M "$m" true 2>&1) 9 - if [[ "$result" =~ ${m:0:50} ]] || [[ "$result" =~ "<not supported>" ]] 19 + result=$(perf stat -M "$m" $system_wide_flag -- sleep 0.01 2>&1) 20 + result_err=$? 21 + if [[ $result_err -gt 0 ]] 10 22 then 11 - continue 23 + if [[ "$result" =~ \ 24 + "Access to performance monitoring and observability operations is limited" ]] 25 + then 26 + echo "Permission failure" 27 + echo $result 28 + if [[ $err -eq 0 ]] 29 + then 30 + err=2 # Skip 31 + fi 32 + continue 33 + elif [[ "$result" =~ "in per-thread mode, enable system wide" ]] 34 + then 35 + echo "Permissions - need system wide mode" 36 + echo $result 37 + if [[ $err -eq 0 ]] 38 + then 39 + err=2 # Skip 40 + fi 41 + continue 42 + elif [[ "$result" =~ "<not supported>" ]] 43 + then 44 + echo "Not supported events" 45 + echo $result 46 + if [[ $err -eq 0 ]] 47 + then 48 + err=2 # Skip 49 + fi 50 + continue 51 + elif [[ "$result" =~ "FP_ARITH" || "$result" =~ "AMX" ]] 52 + then 53 + echo "FP issues" 54 + echo $result 55 + if [[ $err -eq 0 ]] 56 + then 57 + err=2 # Skip 58 + fi 59 + continue 60 + elif [[ "$result" =~ "PMM" ]] 61 + then 62 + echo "Optane memory issues" 63 + echo $result 64 + if [[ $err -eq 0 ]] 65 + then 66 + err=2 # Skip 67 + fi 68 + continue 69 + fi 12 70 fi 13 - # Failed so try system wide. 14 - result=$(perf stat -M "$m" -a sleep 0.01 2>&1) 71 + 15 72 if [[ "$result" =~ ${m:0:50} ]] 16 73 then 17 74 continue 18 75 fi 19 - # Failed again, possibly the workload was too small so retry with something 20 - # longer. 21 - result=$(perf stat -M "$m" perf bench internals synthesize 2>&1) 76 + 77 + # Failed, possibly the workload was too small so retry with something longer. 78 + result=$(perf stat -M "$m" $system_wide_flag -- perf bench internals synthesize 2>&1) 22 79 if [[ "$result" =~ ${m:0:50} ]] 23 80 then 24 81 continue 25 82 fi 26 83 echo "Metric '$m' not printed in:" 27 84 echo "$result" 28 - if [[ "$err" != "1" ]] 29 - then 30 - err=2 31 - if [[ "$result" =~ "FP_ARITH" || "$result" =~ "AMX" ]] 32 - then 33 - echo "Skip, not fail, for FP issues" 34 - elif [[ "$result" =~ "PMM" ]] 35 - then 36 - echo "Skip, not fail, for Optane memory issues" 37 - else 38 - err=1 39 - fi 40 - fi 85 + err=1 41 86 done 42 87 43 88 exit "$err"