~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/perf/tests/shell/record_lbr.sh

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #!/bin/bash
  2 # perf record LBR tests
  3 # SPDX-License-Identifier: GPL-2.0
  4 
  5 set -e
  6 
  7 if [ ! -f /sys/devices/cpu/caps/branches ] && [ ! -f /sys/devices/cpu_core/caps/branches ]
  8 then
  9   echo "Skip: only x86 CPUs support LBR"
 10   exit 2
 11 fi
 12 
 13 err=0
 14 perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
 15 
 16 cleanup() {
 17   rm -rf "${perfdata}"
 18   rm -rf "${perfdata}".old
 19   rm -rf "${perfdata}".txt
 20 
 21   trap - EXIT TERM INT
 22 }
 23 
 24 trap_cleanup() {
 25   cleanup
 26   exit 1
 27 }
 28 trap trap_cleanup EXIT TERM INT
 29 
 30 
 31 lbr_callgraph_test() {
 32   test="LBR callgraph"
 33 
 34   echo "$test"
 35   if ! perf record -e cycles --call-graph lbr -o "${perfdata}" perf test -w thloop
 36   then
 37     echo "$test [Failed support missing]"
 38     if [ $err -eq 0 ]
 39     then
 40       err=2
 41     fi
 42     return
 43   fi
 44 
 45   if ! perf report --stitch-lbr -i "${perfdata}" > "${perfdata}".txt
 46   then
 47     cat "${perfdata}".txt
 48     echo "$test [Failed in perf report]"
 49     err=1
 50     return
 51   fi
 52 
 53   echo "$test [Success]"
 54 }
 55 
 56 lbr_test() {
 57   local branch_flags=$1
 58   local test="LBR $2 test"
 59   local threshold=$3
 60   local out
 61   local sam_nr
 62   local bs_nr
 63   local zero_nr
 64   local r
 65 
 66   echo "$test"
 67   if ! perf record -e cycles $branch_flags -o "${perfdata}" perf test -w thloop
 68   then
 69     echo "$test [Failed support missing]"
 70     perf record -e cycles $branch_flags -o "${perfdata}" perf test -w thloop || true
 71     if [ $err -eq 0 ]
 72     then
 73       err=2
 74     fi
 75     return
 76   fi
 77 
 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)
 80   if [ $sam_nr -eq 0 ]
 81   then
 82     echo "$test [Failed no samples captured]"
 83     err=1
 84     return
 85   fi
 86   echo "$test: $sam_nr samples"
 87 
 88   bs_nr=$(echo "$out" | grep -c 'branch stack: nr:' || true)
 89   if [ $sam_nr -ne $bs_nr ]
 90   then
 91     echo "$test [Failed samples missing branch stacks]"
 92     err=1
 93     return
 94   fi
 95 
 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%]"
100     err=1
101     return
102   fi
103 
104   echo "$test [Success]"
105 }
106 
107 parallel_lbr_test() {
108   err=0
109   perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
110   lbr_test "$1" "$2" "$3"
111   cleanup
112   exit $err
113 }
114 
115 lbr_callgraph_test
116 
117 # Sequential
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
127 
128 # Parallel
129 parallel_lbr_test "-b" "parallel any branch" 100 &
130 pid1=$!
131 parallel_lbr_test "-j any_call" "parallel any call" 100 &
132 pid2=$!
133 parallel_lbr_test "-j any_ret" "parallel any ret" 100 &
134 pid3=$!
135 parallel_lbr_test "-j ind_call" "parallel any indirect call" 100 &
136 pid4=$!
137 parallel_lbr_test "-j ind_jmp" "parallel any indirect jump" 100 &
138 pid5=$!
139 parallel_lbr_test "-j call" "parallel direct calls" 100 &
140 pid6=$!
141 parallel_lbr_test "-j ind_call,u" "parallel any indirect user call" 100 &
142 pid7=$!
143 parallel_lbr_test "-a -b" "parallel system wide any branch" 100 &
144 pid8=$!
145 parallel_lbr_test "-a -j any_call" "parallel system wide any call" 100 &
146 pid9=$!
147 
148 for pid in $pid1 $pid2 $pid3 $pid4 $pid5 $pid6 $pid7 $pid8 $pid9
149 do
150   set +e
151   wait $pid
152   child_err=$?
153   set -e
154   if ([ $err -eq 2 ] && [ $child_err -eq 1 ]) || [ $err -eq 0 ]
155   then
156     err=$child_err
157   fi
158 done
159 
160 cleanup
161 exit $err

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php