File do-xenpaging.sh of Package xenpaging-scripts
#!/bin/bash
set -x
declare -i secs=1234567
guest=$1
trace_log_bin=log.${guest}.xentrace.bin.gz
trace_log_txt=log.${guest}.xentrace.txt.gz
paging_log_txt=log.${guest}.xenpaging.txt
xentrace_fifo=/dev/shm/xentrace.${PPID}.$$.fifo
xenalyze_fifo=/dev/shm/xenalyze.${PPID}.$$.fifo
xentrace_pid=
xenpaging_pid=
qemudm_pid=
cd /abuild
sync &
if test -n "${guest}"
then
rm -fv ${trace_log_bin}
mknod ${xentrace_fifo} p
nice -n -19 gzip -v1 < ${xentrace_fifo} > ${trace_log_bin} &
# xentrace -s 1 -e all ${xentrace_fifo} &
nice -n -19 xentrace -D -S $(( ( ( ( ( 1 << 4 ) * 4096 ) / 4 ) - 129) / 8 )) -s 1 -e $(( 0x10f000 )) ${xentrace_fifo} &
xentrace_pid=$!
sleep 3
id="`xm domid ${guest}`"
if test "${id}" = "None"
then
xm start --vncviewer ${guest}
sleep 1
fi
id="`xm domid ${guest}`"
if test "${id}" != "None" && test -n "${id}"
then
if false
then
qemudm_pid=`pidof /usr/lib/xen/bin/qemu-dm | xargs --no-run-if-empty ps | awk "/ ${guest} /{ print \\$1}" `
echo "guest ${guest} has id '${id}', qemu-dm process '$qemudm_pid'"
fi
if test -n "${qemudm_pid}"
then
screen -dmS gdb_${guest} -h 123456 -- \
gdb \
--readnow \
-ex 'set width 0' \
-ex 'set height 0' \
-ex 'handle SIGWINCH nostop noprint' \
-ex 'handle SIGUSR1 nostop noprint' \
-ex 'handle SIGUSR2 nostop noprint' \
-ex 'handle SIGHUP nostop noprint' \
-ex 'info proc' \
-ex continue \
-p ${qemudm_pid}
fi
if false
then
xenpaging ${id} $(( ( ( 4 * 64 ) * (1 * 1024 * 1024) ) / 4096 )) > ${paging_log_txt} 2>&1 &
xenpaging_pid=$!
fi
if test -n "${xenpaging_pid}"
then
screen -dmS xenpaging_${guest} -h 1234567 -- \
gdb \
--readnow \
-ex 'set width 0' \
-ex 'set height 0' \
-ex 'handle SIGWINCH nostop noprint' \
-ex 'handle SIGUSR1 nostop noprint' \
-ex 'handle SIGUSR2 nostop noprint' \
-ex 'handle SIGTERM nostop noprint' \
-ex 'handle SIGHUP nostop noprint' \
-ex 'info proc' \
-ex continue \
-p ${xenpaging_pid}
fi
declare -i shutoff=0
while test $secs -gt 0
do
sleep 3
: secs $((--secs))
if test $secs = 1
then
xm shutdown ${guest}
secs=123
fi
id="`xm domstate ${guest}`"
case "${id}" in
*Usage:*) sleep 654321 ;;
esac
if test "${id}" = "shutoff"
then
: shutoff $((++shutoff))
elif test "${id}" = "idle" || test "${id}" = "paused" || test "${id}" = "running"
then
shutoff=0
fi
if test "${shutoff}" -gt 12
then
break
fi
done
sleep 1
fi
: xentrace_pid $xentrace_pid
if test -n "${xentrace_pid}"
then
( sleep 42 ; kill $xentrace_pid ) &
bg_xentrace_killer=$!
if false
then
mknod ${xenalyze_fifo} p
zcat ${trace_log_bin} > ${xenalyze_fifo} &
time xenalyze -a ${xenalyze_fifo} | gzip -v9 > ${trace_log_txt}
kill $xentrace_pid $bg_xentrace_killer
else
wait $xentrace_pid
wait $bg_xentrace_killer
fi
fi
: xenpaging_pid ${xenpaging_pid}
if test -n "${xenpaging_pid}"
then
kill ${xenpaging_pid}
fi
: qemudm_pid ${qemudm_pid}
if test -n "${qemudm_pid}"
then
kill ${qemudm_pid}
fi
fi