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

perf tests metrics: Permission related fixes

When permissions are limited running sleep without system wide isn't a
good benchmark to run to achieve samples, switch to running noploop.

Remove indent for non-success cases.

Allow skip for the not counted case.

Minor debug changes.

Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Weilin Wang <weilin.wang@intel.com>
Link: https://lore.kernel.org/r/20250412004704.2297939-2-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Ian Rogers and committed by
Arnaldo Carvalho de Melo
365e02dd f0869f31

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