#!/usr/local/bin/gawk -f
#
#  blocktrace -- graphically examine the blocks processed by dmcache's
#      *_doblock routines in iopfs-general.
#   
#  (An executable awk script.)
#
# Make sure that DEBUG_TRACE is turned on in iopfs-general.
#
# usage:
#   dmcache 'parms...' |& blocktrace | gnuplot
#
# Part of
#              The STARFISH Parallel file-system simulator
#        (Simulation Tool for Advanced Research in File Systems)
# 
#                               David Kotz
#                           Dartmouth College
#                              Version 3.0
#                              October 1996
#                          dfk@cs.dartmouth.edu

# We ignore all lines except those meant for us.
/^alltrace/ {
    RecordSize = $2;
    Nio = $3;
    Ncomp = $4;
}

/^tracetitle/ {
    title = $2;
}

/^blocktrace/ {
    block = $2;

    print block > "blocktrace.data";
}

END {
    # issue gnuplot commands to stdout
    print "! sort -n blocktrace.data > blocktrace.sorted"
    print "set nokey"
    print "set noxzeroaxis"
    print "set title \"", title, Nio, Ncomp, "blocktrace\""
    print "set xlabel \"order\""
    print "set ylabel \"file block\""
    print "set autoscale y";
    print "plot \"blocktrace.sorted\" with points 1 2";
    print "pause 0 \"data is in blocktrace.data and blocktrace.sorted\""
    print "pause 5 \"You have 5 seconds to look at this...\""
}
