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

perf test: waiting.sh: Parameterize timeouts

Let helper functions accept a parameter to specify time out values in
tenths of a second.

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-3-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
84838712 5ebcdf07

+17 -9
+17 -9
tools/perf/tests/shell/lib/waiting.sh
··· 3 3 tenths=date\ +%s%1N 4 4 5 5 # Wait for PID $1 to have $2 number of threads started 6 + # Time out after $3 tenths of a second or 5 seconds if $3 is "" 6 7 wait_for_threads() 7 8 { 9 + tm_out=$3 ; [ -n "${tm_out}" ] || tm_out=50 8 10 start_time=$($tenths) 9 11 while [ -e "/proc/$1/task" ] ; do 10 12 th_cnt=$(find "/proc/$1/task" -mindepth 1 -maxdepth 1 -printf x | wc -c) 11 13 if [ "${th_cnt}" -ge "$2" ] ; then 12 14 return 0 13 15 fi 14 - # Wait at most 5 seconds 15 - if [ $(($($tenths) - start_time)) -ge 50 ] ; then 16 + # Wait at most tm_out tenths of a second 17 + if [ $(($($tenths) - start_time)) -ge $tm_out ] ; then 16 18 echo "PID $1 does not have $2 threads" 17 19 return 1 18 20 fi ··· 24 22 25 23 # Wait for perf record -vvv 2>$2 with PID $1 to start by looking at file $2 26 24 # It depends on capturing perf record debug message "perf record has started" 25 + # Time out after $3 tenths of a second or 5 seconds if $3 is "" 27 26 wait_for_perf_to_start() 28 27 { 28 + tm_out=$3 ; [ -n "${tm_out}" ] || tm_out=50 29 29 echo "Waiting for \"perf record has started\" message" 30 30 start_time=$($tenths) 31 31 while [ -e "/proc/$1" ] ; do ··· 35 31 echo OK 36 32 break 37 33 fi 38 - # Wait at most 5 seconds 39 - if [ $(($($tenths) - start_time)) -ge 50 ] ; then 34 + # Wait at most tm_out tenths of a second 35 + if [ $(($($tenths) - start_time)) -ge $tm_out ] ; then 40 36 echo "perf recording did not start" 41 37 return 1 42 38 fi ··· 45 41 } 46 42 47 43 # Wait for process PID %1 to exit 44 + # Time out after $2 tenths of a second or 5 seconds if $2 is "" 48 45 wait_for_process_to_exit() 49 46 { 47 + tm_out=$2 ; [ -n "${tm_out}" ] || tm_out=50 50 48 start_time=$($tenths) 51 49 while [ -e "/proc/$1" ] ; do 52 - # Wait at most 5 seconds 53 - if [ $(($($tenths) - start_time)) -ge 50 ] ; then 50 + # Wait at most tm_out tenths of a second 51 + if [ $(($($tenths) - start_time)) -ge $tm_out ] ; then 54 52 echo "PID $1 did not exit as expected" 55 53 return 1 56 54 fi ··· 60 54 return 0 61 55 } 62 56 63 - # Check if PID $1 is still running after 0.3 seconds 57 + # Check if PID $1 is still running after $2 tenths of a second 58 + # or 0.3 seconds if $2 is "" 64 59 is_running() 65 60 { 61 + tm_out=$2 ; [ -n "${tm_out}" ] || tm_out=3 66 62 start_time=$($tenths) 67 63 while [ -e "/proc/$1" ] ; do 68 - # Check for at least 0.3s 69 - if [ $(($($tenths) - start_time)) -gt 3 ] ; then 64 + # Check for at least tm_out tenths of a second 65 + if [ $(($($tenths) - start_time)) -gt $tm_out ] ; then 70 66 return 0 71 67 fi 72 68 done