#!/bin/csh -f
#
#  Pull out the idle and busy event times from IOPs in a 16-IOP
# simulation.   Note that WATCH_IDLE must have been defined to capture
# these events.  See the perturb/ subdirectory for some awk scripts
# that read these traces.
#
# usage: extrace simfile
#
# Part of
#              The STARFISH Parallel file-system simulator
#        (Simulation Tool for Advanced Research in File Systems)
# 
#                               David Kotz
#                           Dartmouth College
#                              Version 2.0
#                              January 1995
#                          dfk@cs.dartmouth.edu

set simfile=$1
if ($simfile:e == gz || $simfile:e == Z) then
	set tracefile=$simfile:r
	set tracefile=$tracefile:r.trace
else
	set tracefile=$simfile:r.trace
endif

set BWfile=$tracefile:r.bw

statgraph -f $simfile -s -trace -t 2000000 \
  | awk '/^Metric.\[tthruput\]/ {print $NF/1000. > "'$BWfile'"} \
        /(EV_BUSY|EV_IDLE)/ {print}' \
  | sed -e 's/: EV_/ /' -e 's/\[/ /g' -e 's/\].*//' | awk '$3>=1 && $3<=16' \
  > $tracefile
