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

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

~ [ 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