drm_pmu.sh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/bin/bash
  2. # DRM PMU
  3. # SPDX-License-Identifier: GPL-2.0
  4. set -e
  5. output=$(mktemp /tmp/perf.drm_pmu.XXXXXX.txt)
  6. cleanup() {
  7. rm -f "${output}"
  8. trap - EXIT TERM INT
  9. }
  10. trap_cleanup() {
  11. echo "Unexpected signal in ${FUNCNAME[1]}"
  12. cleanup
  13. exit 1
  14. }
  15. trap trap_cleanup EXIT TERM INT
  16. # Array to store file descriptors and device names
  17. declare -A device_fds
  18. # Open all devices and store file descriptors. Opening the device will create a
  19. # /proc/$$/fdinfo file containing the DRM statistics.
  20. fd_count=3 # Start with file descriptor 3
  21. for device in /dev/dri/*
  22. do
  23. if [[ ! -c "$device" ]]
  24. then
  25. continue
  26. fi
  27. major=$(stat -c "%Hr" "$device")
  28. if [[ "$major" != 226 ]]
  29. then
  30. continue
  31. fi
  32. echo "Opening $device"
  33. eval "exec $fd_count<\"$device\""
  34. echo "fdinfo for: $device (FD: $fd_count)"
  35. cat "/proc/$$/fdinfo/$fd_count"
  36. echo
  37. device_fds["$device"]="$fd_count"
  38. fd_count=$((fd_count + 1))
  39. done
  40. if [[ ${#device_fds[@]} -eq 0 ]]
  41. then
  42. echo "No DRM devices found [Skip]"
  43. cleanup
  44. exit 2
  45. fi
  46. # For each DRM event
  47. err=0
  48. for p in $(perf list --raw-dump drm-)
  49. do
  50. echo -n "Testing perf stat of $p. "
  51. perf stat -e "$p" --pid=$$ true > "$output" 2>&1
  52. if ! grep -q "$p" "$output"
  53. then
  54. echo "Missing DRM event in: [Failed]"
  55. cat "$output"
  56. err=1
  57. else
  58. echo "[OK]"
  59. fi
  60. done
  61. # Close all file descriptors
  62. for fd in "${device_fds[@]}"; do
  63. eval "exec $fd<&-"
  64. done
  65. # Finished
  66. cleanup
  67. exit $err