File Index
Files and directories
Sign in
FILE

stat_all_metrics.sh

File preview with syntax highlighting.

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