#!/usr/local/bin/gawk -f
#
#  memcheck2 -- second pass of the memcheck; see memcheck1
#   	After the memtrace records are extracted and sorted, we check
# to make sure that there were no gaps in the memory locations, and that
# the overall memory range ends in the right place.  We print out any
# gaps, and we print out the offset of the next byte that would be 
# referenced on each CP (should be == the number of bytes on that CP,
# if no gaps).
#
#  (An executable awk script.)
#
# Make sure that DEBUG_TRACE is turned on in iopfs-general.
#
# usage:
#   dmcache 'parms...' |& memcheck1 | sort +0n +1n | memcheck2
#
# 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

BEGIN {CPnum = -1}

{   	    	    # input is sorted by $1 then $2, ie, by CP then by offset
    offset = $2;
    len = $3;

    if (CPnum != $1) {	      # encountering a new CPnum
    	if (CPnum >= 0) print CPnum, expect;
    	CPnum = $1;
    	expect = 0;
    }

    if (offset != expect)
    	print "GAP", CPnum, expect, offset-1;  # a gap!

    expect = offset+len;
}

END {print CPnum, expect}
