#!/bin/csh -f
#
# diskwaitused - plot the disk wait time, over time, for all disks separately
#
# This uses the new RTELOG_DISKWAIT and RTELOG_DISKUSED events
#
# usage: diskwaitused logfile.elog...

set P=`procdir`

if ($#argv < 1) then
	echo usage: diskwaitused logfile.elog...
	exit 1
endif

set TMP=/tmp/diskwait$$
set plot=$TMP/plot
onintr cleanup
mkdir $TMP

foreach logfile ($*)
    elogdump -msu =20 =21 $logfile:r \
    	   | Awk -f $P/diskwaitused.awk1 \
    	   | sort +0n +1n \
        | (cd $TMP; Awk -f $P/diskwaitused.awk2)

    # find out how many points there are 
    set samples=`wc -l $TMP/wait* | cols 1 | stats max`

    echo set title \"$logfile:r\" > $plot
    echo set noclip >> $plot
    echo set samples $samples >> $plot
    echo set data style lines >> $plot
    set count=0
    foreach i ($TMP/wait*)
    	   @ count = ($count + 1) % 10
    	   if ($count == 1) then
    	       echo -n plot >> $plot
    	   endif
    	   if ($count == 0) then
            echo \"$i:t\" >> $plot
    	   else
            echo -n \"$i:t\", >> $plot
    	   endif
    end
    if ($count > 0) then
    	   echo 0 >> $plot
    endif

    (cd $TMP; lasergnu -l -f plot)

    rm -f $TMP/*
end

cleanup:
rm -rf $TMP
