1#!/bin/bash 2# perf all metricgroups 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 10system_wide_flag="-a" 11if ParanoidAndNotRoot 0 12then 13 system_wide_flag="" 14fi 15 16err=3 17skip=0 18for m in $(perf list --raw-dump metricgroups) 19do 20 echo "Testing $m" 21 result=$(perf stat -M "$m" $system_wide_flag sleep 0.01 2>&1) 22 result_err=$? 23 if [[ $result_err -eq 0 ]] 24 then 25 if [[ "$err" -ne 1 ]] 26 then 27 err=0 28 fi 29 else 30 if [[ "$result" =~ \ 31 "Access to performance monitoring and observability operations is limited" ]] 32 then 33 echo "Permission failure" 34 echo $result 35 skip=1 36 elif [[ "$result" =~ "in per-thread mode, enable system wide" ]] 37 then 38 echo "Permissions - need system wide mode" 39 echo $result 40 skip=1 41 elif [[ "$m" == @(Default2|Default3|Default4) ]] 42 then 43 echo "Ignoring failures in $m that may contain unsupported legacy events" 44 else 45 echo "Metric group $m failed" 46 echo $result 47 err=1 # Fail 48 fi 49 fi 50done 51 52if [[ "$err" -eq 3 && "$skip" -eq 1 ]] 53then 54 err=2 55fi 56 57exit $err 58