#!/bin/csh -f
#
# udcost - show the cost of moving user data, not metadata
#   	ONLY for fake, not REAL_DATA
#
# usage:
#   dmcache ... |& udcost
# with UD_TRACE turned on
#
# 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

if ($#argv != 0) then
    echo usage: 'dmcache ... |& udcost'
    exit 1
endif

# The columns are:
#  1 "udtrace"
#  2 proc
#  3 time
#  4 copybytes
#  5 costbytes
#  6 where

# costbytes - (copybytes-4)  is the amount of userdata "moved"
# (costbytes when copybytes is 0)
# These formulas are not quite right in all cases
awk '$1 == "udtrace" {\
    if ($6 == "noncyc_WordCopy") next; \
    if ($5 == 0 || $5 - ($4 - 4) == 0) next; \
    if ($4 > 0) \
        printf "%5d %s\n", $5 - ($4 - 4), $6 \
    else \
        printf "%5d %s\n", $5, $6; \
}'
