stat_all_metricgroups.sh 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/bin/bash
  2. # perf all metricgroups test
  3. # SPDX-License-Identifier: GPL-2.0
  4. ParanoidAndNotRoot()
  5. {
  6. [ "$(id -u)" != 0 ] && [ "$(cat /proc/sys/kernel/perf_event_paranoid)" -gt $1 ]
  7. }
  8. system_wide_flag="-a"
  9. if ParanoidAndNotRoot 0
  10. then
  11. system_wide_flag=""
  12. fi
  13. err=3
  14. skip=0
  15. for m in $(perf list --raw-dump metricgroups)
  16. do
  17. echo "Testing $m"
  18. result=$(perf stat -M "$m" $system_wide_flag sleep 0.01 2>&1)
  19. result_err=$?
  20. if [[ $result_err -eq 0 ]]
  21. then
  22. if [[ "$err" -ne 1 ]]
  23. then
  24. err=0
  25. fi
  26. else
  27. if [[ "$result" =~ \
  28. "Access to performance monitoring and observability operations is limited" ]]
  29. then
  30. echo "Permission failure"
  31. echo $result
  32. skip=1
  33. elif [[ "$result" =~ "in per-thread mode, enable system wide" ]]
  34. then
  35. echo "Permissions - need system wide mode"
  36. echo $result
  37. skip=1
  38. elif [[ "$m" == @(Default2|Default3|Default4) ]]
  39. then
  40. echo "Ignoring failures in $m that may contain unsupported legacy events"
  41. else
  42. echo "Metric group $m failed"
  43. echo $result
  44. err=1 # Fail
  45. fi
  46. fi
  47. done
  48. if [[ "$err" -eq 3 && "$skip" -eq 1 ]]
  49. then
  50. err=2
  51. fi
  52. exit $err