stat+event_uniquifying.sh 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/bin/bash
  2. # perf stat events uniquifying
  3. # SPDX-License-Identifier: GPL-2.0
  4. set -e
  5. err=0
  6. stat_output=$(mktemp /tmp/__perf_test.stat_output.XXXXX)
  7. cleanup() {
  8. rm -f "${stat_output}"
  9. trap - EXIT TERM INT
  10. }
  11. trap_cleanup() {
  12. echo "Unexpected signal in ${FUNCNAME[1]}"
  13. cleanup
  14. exit 1
  15. }
  16. trap trap_cleanup EXIT TERM INT
  17. test_event_uniquifying() {
  18. echo "Uniquification of PMU sysfs events test"
  19. # Read events from perf list with and without -v. With -v the duplicate PMUs
  20. # aren't deduplicated. Note, json events are listed by perf list without a
  21. # PMU.
  22. read -ra pmu_events <<< "$(perf list --raw pmu)"
  23. read -ra pmu_v_events <<< "$(perf list -v --raw pmu)"
  24. # For all non-deduplicated events.
  25. for pmu_v_event in "${pmu_v_events[@]}"; do
  26. # If the event matches an event in the deduplicated events then it musn't
  27. # be an event with duplicate PMUs, continue the outer loop.
  28. for pmu_event in "${pmu_events[@]}"; do
  29. if [[ "$pmu_v_event" == "$pmu_event" ]]; then
  30. continue 2
  31. fi
  32. done
  33. # Strip the suffix from the non-deduplicated event's PMU.
  34. event=$(echo "$pmu_v_event" | sed -E 's/_[0-9]+//')
  35. for pmu_event in "${pmu_events[@]}"; do
  36. if [[ "$event" == "$pmu_event" ]]; then
  37. echo "Testing event ${event} is uniquified to ${pmu_v_event}"
  38. if ! perf stat -e "$event" -A -o ${stat_output} -- true; then
  39. echo "Error running perf stat for event '$event' [Skip]"
  40. if [ $err = 0 ]; then
  41. err=2
  42. fi
  43. continue
  44. fi
  45. # Ensure the non-deduplicated event appears in the output.
  46. if ! grep -q "${pmu_v_event}" "${stat_output}"; then
  47. echo "Uniquification of PMU sysfs events test [Failed]"
  48. cat "${stat_output}"
  49. err=1
  50. fi
  51. break
  52. fi
  53. done
  54. done
  55. }
  56. test_event_uniquifying
  57. cleanup
  58. exit $err