#!/bin/csh -f
#
# diskused - plot the disk used for each demand or prefetch issued
#
# This uses the new RTELOG_DISKUSED events
#
# 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 =20 $logfile:r \
    	   | pickint $from $to \
        | (cd $TMP; Awk -f $P/diskused.awk)

    # find out how many points there are per file, and the time range
    set samples=`wc -l $TMP/disks`
    set samples=$samples[1]

    echo set title \"$logfile:r $from-$to\" > $plot
    echo set noclip >> $plot
    echo set samples $samples >> $plot
    echo set yrange "[0:21]" >> $plot
    echo plot \"disks\" w points >> $plot

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

    rm -f $TMP/*
end

cleanup:
rm -rf $TMP
