Home | History | Annotate | Download | only in perf-load-setup
      1 #!/system/bin/sh
      2 # Usage: spin_n_threads.sh <num_threads> [<nice>]
      3 #        spin_n_threads.sh kill
      4 
      5 TGID_FILE=/data/local/tmp/spin_n_threads_tgid.txt
      6 
      7 spin_loop() {
      8   while :
      9   do
     10     NUM=$(expr 1 + 1)
     11   done
     12 }
     13 
     14 clean_up() {
     15   trap - SIGINT SIGTERM SIGKILL
     16   kill -- -$$
     17 }
     18 
     19 NUM_THREADS=1
     20 if [ ! -z ${1} ]; then
     21   if [ ${1} == "kill" ]; then
     22     TGID=$(cat ${TGID_FILE})
     23     kill -- -${TGID}
     24     exit 0
     25   fi
     26 
     27   if [ ${1} -gt 1 ]; then
     28     NUM_THREADS=${1}
     29   else
     30     exit 0
     31   fi
     32 fi
     33 
     34 if [ ! -z ${2} ]; then
     35  renice -n ${2} -p $$
     36 fi
     37 
     38 # Register cleanup on trap
     39 trap clean_up SIGINT SIGTERM SIGKILL
     40 for i in $(seq 1 $NUM_THREADS ); do
     41   spin_loop &
     42 done
     43 
     44 echo $$ > ${TGID_FILE}
     45