# This has absolutely no warranty. This attaches gdb to a process in the # background, if you kill this script or gdb you may leave your process # stopped. If you run this script it may never exit, necessitating killing it. # This may cause your host to crash, corrupt, catch fire, or start a global # thermonuclear war. I take no responsibility. mpid=`pidof mysqld` nsamples=$1 msleep=$2 if [[ x$msleep == 'x' || $msleep -lt 1 ]]; then echo 'setting sleep to 1ms' msleep=1 fi echo "set pagination 0" > hpmp.cmd echo "handle SIGUSR1 nostop pass" >> hpmp.cmd echo "handle SIGUSR2 stop nopass" >> hpmp.cmd for x in `seq 1 $nsamples` ; do echo "echo HPMP_READY '$x'\n" echo "continue" echo "thread apply all bt" done >> hpmp.cmd echo "handle SIGUSR2 nostop pass" >> hpmp.cmd echo "echo HPMP_EXITING\n" >> hpmp.cmd echo "quit" >> hpmp.cmd gdb --command=hpmp.cmd -p $mpid > hpmp.tmp & for x in `seq 1 $nsamples` ; do echo "$x: Waiting for GDB to be ready" until tail -n20 hpmp.tmp | grep -q "HPMP_READY '$x'"; do usleep 10000; done usleep $((msleep * 1000)) echo "$x: Sending SIGUSR2" kill -SIGUSR2 $mpid done echo "Waiting for GDB to exit" wait awk '/^\#/ { print $4 }' hpmp.tmp | \ sort | uniq -c | sort -r -n -k 1,1 > hpmpf.out awk 'BEGIN { s = ""; } /Thread/ { print s; s = ""; } /^\#/ { if (s != "" ) { s = s "," $4} else { s = $4 } } END { print s }' hpmp.tmp | \ sort | uniq -c | sort -r -n -k 1,1 > hpmph.out rm hpmp.tmp hpmp.cmd