addr2line_inlines.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #!/bin/bash
  2. # test addr2line inline unwinding
  3. # SPDX-License-Identifier: GPL-2.0
  4. set -e
  5. err=0
  6. test_dir=$(mktemp -d /tmp/perf-test-inline-addr2line.XXXXXXXXXX)
  7. perf_data="${test_dir}/perf.data"
  8. perf_script_txt="${test_dir}/perf_script.txt"
  9. cleanup() {
  10. rm -rf "${test_dir}"
  11. trap - EXIT TERM INT
  12. }
  13. trap_cleanup() {
  14. echo "Unexpected signal in ${FUNCNAME[1]}"
  15. cleanup
  16. exit 1
  17. }
  18. trap trap_cleanup EXIT TERM INT
  19. test_fp() {
  20. echo "Inline unwinding fp verification test"
  21. # Record data. Currently only dwarf callchains support inlined functions.
  22. perf record --call-graph fp -e task-clock:u -o "${perf_data}" -- perf test -w inlineloop 1
  23. # Check output with inline (default) and srcline
  24. perf script -i "${perf_data}" --fields +srcline > "${perf_script_txt}"
  25. # Expect the leaf and middle functions to occur on lines in the 20s, with
  26. # the non-inlined parent function on a line in the 30s.
  27. if grep -q "inlineloop.c:2. (inlined)" "${perf_script_txt}" &&
  28. grep -q "inlineloop.c:3.$" "${perf_script_txt}"
  29. then
  30. echo "Inline unwinding fp verification test [Success]"
  31. else
  32. echo "Inline unwinding fp verification test [Failed missing inlined functions]"
  33. err=1
  34. fi
  35. }
  36. test_dwarf() {
  37. echo "Inline unwinding dwarf verification test"
  38. # Record data. Currently only dwarf callchains support inlined functions.
  39. perf record --call-graph dwarf -e task-clock:u -o "${perf_data}" -- perf test -w inlineloop 1
  40. # Check output with inline (default) and srcline
  41. perf script -i "${perf_data}" --fields +srcline > "${perf_script_txt}"
  42. # Expect the leaf and middle functions to occur on lines in the 20s, with
  43. # the non-inlined parent function on a line in the 30s.
  44. if grep -q "inlineloop.c:2. (inlined)" "${perf_script_txt}" &&
  45. grep -q "inlineloop.c:3.$" "${perf_script_txt}"
  46. then
  47. echo "Inline unwinding dwarf verification test [Success]"
  48. else
  49. echo "Inline unwinding dwarf verification test [Failed missing inlined functions]"
  50. err=1
  51. fi
  52. }
  53. test_lbr() {
  54. echo "Inline unwinding LBR verification test"
  55. if [ ! -f /sys/bus/event_source/devices/cpu/caps/branches ] &&
  56. [ ! -f /sys/bus/event_source/devices/cpu_core/caps/branches ]
  57. then
  58. echo "Skip: only x86 CPUs support LBR"
  59. return
  60. fi
  61. # Record data. Currently only dwarf callchains support inlined functions.
  62. perf record --call-graph lbr -e cycles:u -o "${perf_data}" -- perf test -w inlineloop 1
  63. # Check output with inline (default) and srcline
  64. perf script -i "${perf_data}" --fields +srcline > "${perf_script_txt}"
  65. # Expect the leaf and middle functions to occur on lines in the 20s, with
  66. # the non-inlined parent function on a line in the 30s.
  67. if grep -q "inlineloop.c:2. (inlined)" "${perf_script_txt}" &&
  68. grep -q "inlineloop.c:3.$" "${perf_script_txt}"
  69. then
  70. echo "Inline unwinding lbr verification test [Success]"
  71. else
  72. echo "Inline unwinding lbr verification test [Failed missing inlined functions]"
  73. err=1
  74. fi
  75. }
  76. test_fp
  77. test_dwarf
  78. test_lbr
  79. cleanup
  80. exit $err