#!/bin/sh CWD=$(pwd) TMP="/tmp" TMPDIR=$TMP/timetest HELPER=$TMP/timetest-executor.sh LOGFILE=$TMPDIR/timetest.log ENDLOGFILE=$CWD/Desktop/timetest.csv PROGS="gedit xterm" SLEEP="1" LOAD="yes" function prepare () { mkdir -p $TMPDIR echo '#!/bin/sh' > $HELPER echo '$1 &' >> $HELPER echo 'sleep $2' >> $HELPER echo 'kill $!' >> $HELPER chmod u+x $HELPER } function clearlogs () { for FILE in $LOGFILE $ENDLOGFILE do if [ -e $FILE ] then rm $FILE fi done } function timerun () { if [ $(which $PROG) ] then if [ $LOAD ] then systemload fi echo "?$PROG" >> $LOGFILE for i in $(seq 0 99) do echo "run $i" >> $LOGFILE /usr/bin/time -p -o $LOGFILE -a $HELPER $PROG $SLEEP done if [ $LOAD ] then killall dd killall bzip2 killall bunzip2 fi sleep 5 fi } function systemload () { dd if=/dev/urandom of=$TMPDIR/random.dd bs=1024 count=262144 && bzip2 $TMPDIR/random.dd && bunzip2 $TMPDIR/random.dd.bz2 & } function parselog { cat $LOGFILE | tr '\n' ',' | sed -e 's/run/\nrun/g' -e '$s/\(.\)$/\1\n/' -e 's/\?/\n/g' > $ENDLOGFILE } function cleanup { rm $HELPER rm -fr $TMPDIR } # ============================== echo "test begin" clearlogs prepare for PROG in $PROGS do timerun done parselog cleanup echo "test end" # ============================== # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: