#!/bin/bash
# look for glitches in scheduling
#   glitch1.sh 1.6 2007/05/18 18:49:22 davidsen Stable

Jobs=""

# xterm scroll option - SCROLL
#   -j - do jump scroll
#   +j - do one line scroll
# if SCROLL is specified that's used instead
scroll=${SCROLL:-"+j"}
#
# number of xwindows scrolling - MAXWIN
MaxWin=${MAXWIN:-4}

rm -f gl_loop*
for n in $(seq 1 ${MaxWin}); do
  vpos=$[(n-1)*80+50]
  xterm -geom 100x2-0+${vpos} ${scroll} \
  -e bash -c "exec 3>gl_loop$n; lc=0; while true; do echo \$RANDOM; let lc=lc+1; echo \$lc >&3; done" &
  Jobs="$Jobs $!"
done

# save the uname info for identification
uname -a >gl_uname

# track the resources in use
vmstat 1 >gl_vmstat &
Jobs="$Jobs $!"

echo -e "\nObserve the gear rotation for obvious glitches\n" \
  "Close the glxgears window to end this test early\n" \
  "Test will end automatically after about 40sec" >&2

# save the fps information
script -c 'glxgears & sleep 43; kill $!' gl_gears

# close the rest
kill ${Jobs}

# summarize the loop files
for n in $(seq 1 ${MaxWin})
do
  echo -n "$n "
  tail -n1 gl_loop$n
  rm gl_loop$n
done >gl_fairloops
