#!/usr/bin/perl
# Input is back-to-back dinero simulations
# Output is a list of unified cache size and overall miss ratio

#  This is for the convenience of students, and is not represented
#   as a bullet-proof application program.  Please check any results for
#   common-sense.  Please report any bugs to the course instructor.

# get entire input file into an array
@aa = <STDIN>;

while (scalar(@aa))
{ $line = shift(@aa);
  @words = split(" ", $line);
  $www = shift(@words);
  if ($www eq "CACHE")
  { shift(@words); 
    $blocksize = substr(shift(@words),10); chop $blocksize;
    $subblocksize = substr(shift(@words),14); chop $subblocksize;
    $wordsize = substr(shift(@words),9); chop $wordsize;
    $usize = substr(shift(@words),6); chop $usize;
    $dsize = substr(shift(@words),6);  chop $dsize;
    $isize = substr(shift(@words),6); chop $isize;
    $buswidth = substr(shift(@words),10); chop $buswidth;
  }
  if ($www eq "POLICIES:")
  { $assoc = substr(shift(@words),6); 
                   $assoc = substr($assoc,0,length($assoc)-5);  
    $replacement = substr(shift(@words),12); chop $replacement;
    $fetch = substr(shift(@words),6); chop $fetch;
    $write = substr(shift(@words),6); chop $write;
    $allocate = substr(shift(@words),9); chop $allocate;
  }

  if ($www eq "Demand")
  { $www = shift(@words);
    if ($www eq "Misses")
    { $line = shift(@aa);
      @words = split(" ", $line);
      $missratio = shift(@words);
      $imiss = shift(@words);
      $dmiss = shift(@words);
      $rmiss = shift(@words);
      $wmiss = shift(@words);
    }
  }

  if ($www eq "Total")
  { $www = shift(@words);
    if ($www eq "Traffic")
    { $line = shift(@aa);
      @words = split(" ", $line);
      shift(@words); shift(@words); shift(@words); shift(@words);
      $traffic_ratio = shift(words);
      
      print $usize, "\t", $missratio, "\n";
    }
  }
}

