Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
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
15err=0
16for m in $(perf list --raw-dump metricgroups)
17do
18 echo "Testing $m"
19 result=$(perf stat -M "$m" $system_wide_flag sleep 0.01 2>&1)
20 result_err=$?
21 if [[ $result_err -gt 0 ]]
22 then
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 elif [[ "$result" =~ "in per-thread mode, enable system wide" ]]
33 then
34 echo "Permissions - need system wide mode"
35 echo $result
36 if [[ $err -eq 0 ]]
37 then
38 err=2 # Skip
39 fi
40 elif [[ "$m" == @(Default2|Default3|Default4) ]]
41 then
42 echo "Ignoring failures in $m that may contain unsupported legacy events"
43 else
44 echo "Metric group $m failed"
45 echo $result
46 err=1 # Fail
47 fi
48 fi
49done
50
51exit $err