2 # perf record LBR tests (exclusive)
3 # SPDX-License-Identifier: GPL-2.0
7 if [ ! -f /sys
/devices
/cpu
/caps
/branches
] && [ ! -f /sys
/devices
/cpu_core
/caps
/branches
]
9 echo "Skip: only x86 CPUs support LBR"
14 perfdata
=$
(mktemp
/tmp
/__perf_test.perf.data.XXXXX
)
18 rm -rf "${perfdata}".old
19 rm -rf "${perfdata}".txt
28 trap trap_cleanup EXIT TERM INT
31 lbr_callgraph_test
() {
35 if ! perf record
-e cycles
--call-graph lbr
-o "${perfdata}" perf
test -w thloop
37 echo "$test [Failed support missing]"
45 if ! perf report
--stitch-lbr -i "${perfdata}" > "${perfdata}".txt
48 echo "$test [Failed in perf report]"
53 echo "$test [Success]"
58 local test="LBR $2 test"
67 if ! perf record
-e cycles
$branch_flags -o "${perfdata}" perf
test -w thloop
69 echo "$test [Failed support missing]"
70 perf record
-e cycles
$branch_flags -o "${perfdata}" perf
test -w thloop || true
78 out
=$
(perf report
-D -i "${perfdata}" 2> /dev
/null |
grep -A1 'PERF_RECORD_SAMPLE')
79 sam_nr
=$
(echo "$out" |
grep -c 'PERF_RECORD_SAMPLE' || true
)
82 echo "$test [Failed no samples captured]"
86 echo "$test: $sam_nr samples"
88 bs_nr
=$
(echo "$out" |
grep -c 'branch stack: nr:' || true
)
89 if [ $sam_nr -ne $bs_nr ]
91 echo "$test [Failed samples missing branch stacks]"
96 zero_nr
=$
(echo "$out" |
grep -c 'branch stack: nr:0' || true
)
97 r
=$
(($zero_nr * 100 / $bs_nr))
98 if [ $r -gt $threshold ]; then
99 echo "$test [Failed empty br stack ratio exceed $threshold%: $r%]"
104 echo "$test [Success]"
107 parallel_lbr_test
() {
109 perfdata
=$
(mktemp
/tmp
/__perf_test.perf.data.XXXXX
)
110 lbr_test
"$1" "$2" "$3"
118 lbr_test
"-b" "any branch" 2
119 lbr_test
"-j any_call" "any call" 2
120 lbr_test
"-j any_ret" "any ret" 2
121 lbr_test
"-j ind_call" "any indirect call" 2
122 lbr_test
"-j ind_jmp" "any indirect jump" 100
123 lbr_test
"-j call" "direct calls" 2
124 lbr_test
"-j ind_call,u" "any indirect user call" 100
125 lbr_test
"-a -b" "system wide any branch" 2
126 lbr_test
"-a -j any_call" "system wide any call" 2
129 parallel_lbr_test
"-b" "parallel any branch" 100 &
131 parallel_lbr_test
"-j any_call" "parallel any call" 100 &
133 parallel_lbr_test
"-j any_ret" "parallel any ret" 100 &
135 parallel_lbr_test
"-j ind_call" "parallel any indirect call" 100 &
137 parallel_lbr_test
"-j ind_jmp" "parallel any indirect jump" 100 &
139 parallel_lbr_test
"-j call" "parallel direct calls" 100 &
141 parallel_lbr_test
"-j ind_call,u" "parallel any indirect user call" 100 &
143 parallel_lbr_test
"-a -b" "parallel system wide any branch" 100 &
145 parallel_lbr_test
"-a -j any_call" "parallel system wide any call" 100 &
148 for pid
in $pid1 $pid2 $pid3 $pid4 $pid5 $pid6 $pid7 $pid8 $pid9
154 if ([ $err -eq 2 ] && [ $child_err -eq 1 ]) ||
[ $err -eq 0 ]