test_stat_intel_tpebs.sh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/bin/bash
  2. # test Intel TPEBS counting mode (exclusive)
  3. # SPDX-License-Identifier: GPL-2.0
  4. set -e
  5. ParanoidAndNotRoot() {
  6. [ "$(id -u)" != 0 ] && [ "$(cat /proc/sys/kernel/perf_event_paranoid)" -gt $1 ]
  7. }
  8. if ! grep -q GenuineIntel /proc/cpuinfo
  9. then
  10. echo "Skipping non-Intel"
  11. exit 2
  12. fi
  13. if ParanoidAndNotRoot 0
  14. then
  15. echo "Skipping paranoid >0 and not root"
  16. exit 2
  17. fi
  18. stat_output=$(mktemp /tmp/__perf_stat_tpebs_output.XXXXX)
  19. cleanup() {
  20. rm -rf "${stat_output}"
  21. trap - EXIT TERM INT
  22. }
  23. trap_cleanup() {
  24. echo "Unexpected signal in ${FUNCNAME[1]}"
  25. cat "${stat_output}"
  26. cleanup
  27. exit 1
  28. }
  29. trap trap_cleanup EXIT TERM INT
  30. # Event to be used in tests
  31. event=cache-misses
  32. if ! perf record -e "${event}:p" -a -o /dev/null sleep 0.01 > "${stat_output}" 2>&1
  33. then
  34. echo "Missing ${event} support"
  35. cleanup
  36. exit 2
  37. fi
  38. test_with_record_tpebs() {
  39. echo "Testing with --record-tpebs"
  40. if ! perf stat -e "${event}:R" --record-tpebs -a sleep 0.01 > "${stat_output}" 2>&1
  41. then
  42. echo "Testing with --record-tpebs [Failed perf stat]"
  43. cat "${stat_output}"
  44. exit 1
  45. fi
  46. # Expected output:
  47. # $ perf stat --record-tpebs -e cache-misses:R -a sleep 0.01
  48. # Events enabled
  49. # [ perf record: Woken up 2 times to write data ]
  50. # [ perf record: Captured and wrote 0.056 MB - ]
  51. #
  52. # Performance counter stats for 'system wide':
  53. #
  54. # 0 cache-misses:R
  55. #
  56. # 0.013963299 seconds time elapsed
  57. if ! grep "perf record" "${stat_output}"
  58. then
  59. echo "Testing with --record-tpebs [Failed missing perf record]"
  60. cat "${stat_output}"
  61. exit 1
  62. fi
  63. if ! grep "${event}:R" "${stat_output}" && ! grep "/${event}/R" "${stat_output}"
  64. then
  65. echo "Testing with --record-tpebs [Failed missing event name]"
  66. cat "${stat_output}"
  67. exit 1
  68. fi
  69. echo "Testing with --record-tpebs [Success]"
  70. }
  71. test_with_record_tpebs
  72. cleanup
  73. exit 0