Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf test: test_intel_pt.sh: Move helper functions for waiting

Move helper functions for waiting to a separate file so they can be
shared.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Link: https://lore.kernel.org/r/20220914080150.5888-2-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Adrian Hunter and committed by
Arnaldo Carvalho de Melo
5ebcdf07 fea753f8

+73 -64
+69
tools/perf/tests/shell/lib/waiting.sh
··· 1 + # SPDX-License-Identifier: GPL-2.0 2 + 3 + tenths=date\ +%s%1N 4 + 5 + # Wait for PID $1 to have $2 number of threads started 6 + wait_for_threads() 7 + { 8 + start_time=$($tenths) 9 + while [ -e "/proc/$1/task" ] ; do 10 + th_cnt=$(find "/proc/$1/task" -mindepth 1 -maxdepth 1 -printf x | wc -c) 11 + if [ "${th_cnt}" -ge "$2" ] ; then 12 + return 0 13 + fi 14 + # Wait at most 5 seconds 15 + if [ $(($($tenths) - start_time)) -ge 50 ] ; then 16 + echo "PID $1 does not have $2 threads" 17 + return 1 18 + fi 19 + done 20 + return 1 21 + } 22 + 23 + # Wait for perf record -vvv 2>$2 with PID $1 to start by looking at file $2 24 + # It depends on capturing perf record debug message "perf record has started" 25 + wait_for_perf_to_start() 26 + { 27 + echo "Waiting for \"perf record has started\" message" 28 + start_time=$($tenths) 29 + while [ -e "/proc/$1" ] ; do 30 + if grep -q "perf record has started" "$2" ; then 31 + echo OK 32 + break 33 + fi 34 + # Wait at most 5 seconds 35 + if [ $(($($tenths) - start_time)) -ge 50 ] ; then 36 + echo "perf recording did not start" 37 + return 1 38 + fi 39 + done 40 + return 0 41 + } 42 + 43 + # Wait for process PID %1 to exit 44 + wait_for_process_to_exit() 45 + { 46 + start_time=$($tenths) 47 + while [ -e "/proc/$1" ] ; do 48 + # Wait at most 5 seconds 49 + if [ $(($($tenths) - start_time)) -ge 50 ] ; then 50 + echo "PID $1 did not exit as expected" 51 + return 1 52 + fi 53 + done 54 + return 0 55 + } 56 + 57 + # Check if PID $1 is still running after 0.3 seconds 58 + is_running() 59 + { 60 + start_time=$($tenths) 61 + while [ -e "/proc/$1" ] ; do 62 + # Check for at least 0.3s 63 + if [ $(($($tenths) - start_time)) -gt 3 ] ; then 64 + return 0 65 + fi 66 + done 67 + echo "PID $1 exited prematurely" 68 + return 1 69 + }
+4 -64
tools/perf/tests/shell/test_intel_pt.sh
··· 4 4 5 5 set -e 6 6 7 - tenths=date\ +%s%1N 8 - 9 7 # Skip if no Intel PT 10 8 perf list | grep -q 'intel_pt//' || exit 2 9 + 10 + shelldir=$(dirname "$0") 11 + . "${shelldir}"/lib/waiting.sh 11 12 12 13 skip_cnt=0 13 14 ok_cnt=0 ··· 111 110 { 112 111 perf record -o "${tmpfile}" -B -N --no-bpf-event -e dummy:k true >/dev/null 2>&1 || return 2 113 112 return 0 114 - } 115 - 116 - wait_for_threads() 117 - { 118 - start_time=$($tenths) 119 - while [ -e "/proc/$1/task" ] ; do 120 - th_cnt=$(find "/proc/$1/task" -mindepth 1 -maxdepth 1 -printf x | wc -c) 121 - if [ "${th_cnt}" -ge "$2" ] ; then 122 - return 0 123 - fi 124 - # Wait at most 5 seconds 125 - if [ $(($($tenths) - start_time)) -ge 50 ] ; then 126 - echo "PID $1 does not have $2 threads" 127 - return 1 128 - fi 129 - done 130 - return 1 131 - } 132 - 133 - wait_for_perf_to_start() 134 - { 135 - echo "Waiting for \"perf record has started\" message" 136 - start_time=$($tenths) 137 - while [ -e "/proc/$1" ] ; do 138 - if grep -q "perf record has started" "${errfile}" ; then 139 - echo OK 140 - break 141 - fi 142 - # Wait at most 5 seconds 143 - if [ $(($($tenths) - start_time)) -ge 50 ] ; then 144 - echo "perf recording did not start" 145 - return 1 146 - fi 147 - done 148 - return 0 149 - } 150 - 151 - wait_for_process_to_exit() 152 - { 153 - start_time=$($tenths) 154 - while [ -e "/proc/$1" ] ; do 155 - # Wait at most 5 seconds 156 - if [ $(($($tenths) - start_time)) -ge 50 ] ; then 157 - echo "PID $1 did not exit as expected" 158 - return 1 159 - fi 160 - done 161 - return 0 162 - } 163 - 164 - is_running() 165 - { 166 - start_time=$($tenths) 167 - while [ -e "/proc/$1" ] ; do 168 - # Check for at least 0.3s 169 - if [ $(($($tenths) - start_time)) -gt 3 ] ; then 170 - return 0 171 - fi 172 - done 173 - echo "PID $1 exited prematurely" 174 - return 1 175 113 } 176 114 177 115 test_per_thread() ··· 238 298 perf record -B -N --no-bpf-event -o "${perfdatafile}" -e intel_pt//u"${k}" -vvv --per-thread -p "${w1},${w2}" 2>"${errfile}" >"${outfile}" & 239 299 ppid=$! 240 300 echo "perf PID is $ppid" 241 - wait_for_perf_to_start ${ppid} || return 1 301 + wait_for_perf_to_start ${ppid} "${errfile}" || return 1 242 302 243 303 kill ${w1} 244 304 wait_for_process_to_exit ${w1} || return 1