#!/usr/local/bin/gawk -f
#
#  memtrace -- graphically examine the memories filled 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...' |& memtrace | 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;
}

/^memtrace/ {
    CPnum = $2;
    offset = $3;
    len = $4;

    print offset / RecordSize, CPnum > "memtrace.data";
    print (offset+len) / RecordSize, CPnum > "memtrace.data";
    print "" > "memtrace.data";
}

END {
    # issue gnuplot commands to stdout
    print "set nokey"
    print "set noxzeroaxis"
    print "set title \"", title, Nio, Ncomp, "memtrace\""
    print "set xlabel \"memory offset address (record number)\""
    print "set ylabel \"CPnum\""
    print "set offset 0, 0, .5, .5"
#    print "set xtics 0,1024"
    print "set ytics 0,1"
    print "plot \"memtrace.data\" with lines";
    print "pause 0 \"data is in memtrace.data\""
    print "pause 5 \"You have 5 seconds to look at this... (last one!)\""
}
