| 1 | |
| 2 | |
| 3 |
|
| 4 | tenths=date\ +%s%1N
|
| 5 |
|
| 6 | |
| 7 | |
| 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 | |
| 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 | |
| 27 | |
| 28 | |
| 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 | |
| 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 | |
| 49 | |
| 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 | |
| 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 | |
| 65 | |
| 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 | |
| 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 | }
|