xref: /linux/tools/perf/tests/shell/stat_all_metricgroups.sh (revision cdd30ebb1b9f36159d66f088b61aee264e649d7a)
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    else
41      echo "Metric group $m failed"
42      echo $result
43      err=1 # Fail
44    fi
45  fi
46done
47
48exit $err
49