#!/bin/csh -f
#
# diskused - plot the disk used for each demand or prefetch issued
#
# Unfortunately, the timing is not perfect; the time used is that of
# the demand fetch or prefetch elog entry, not when the disk request 
# was queued.
#
# It plots them in a sortof gantt chart 
#
# usage: diskused from to logfile.elog...
#  only intervals [from..to] are plotted. See pickint for details.

set P=`procdir`

if ($#argv < 3) then
	echo usage: diskused from to logfile.elog...
	exit 1
endif

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

set from=$1
set to=$2
shift;shift

foreach logfile ($*)
    elogdump -stp =3 =5 =6 =10 =12 $logfile:r \
    	   | pickint $from $to \
        | (cd $TMP; Awk -f $P/diskused1.awk)

    # find out how many points there are per file, and the time range
    wc -l $TMP/{demand,prefetch} | cols 1 | stats max > $TMP/max
    set samples=`cat $TMP/max`

    echo set title \"$logfile:r $from-$to\" > $plot
    echo set noclip >> $plot
    echo set data style points >> $plot
    echo set samples $samples >> $plot
    echo set yrange "[0:21]" >> $plot
    echo plot \"demand\", \"prefetch\" >> $plot

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

    rm -f $TMP/*
end

cleanup:
rm -rf $TMP
