#
# This software is Copyright 2005 by Elsevier Inc.  You may use it
# under the terms of the license at http://perl.plover.com/hop/LICENSE.txt .
#



###
### memusage.pl
###

## Chapter 4 section 6.3.2

# memusage.pl
# generate iterator memory usage report from diagnostic output

my %CREATED;
my %EXISTING;
my %MAX;
while (<>) {
  my ($sign, $subr, $count) = split;
  if ($sign eq '+') { 
    $CREATED{$subr}++; 
    $EXISTING{$subr}++; 
    $CREATED{ALL}++; 
    $EXISTING{ALL}++; 
  } elsif ($sign eq '-') { 
    $EXISTING{$subr}--; 
    $EXISTING{ALL}--; 
  }
  $MAX{$subr} = $EXISTING{$subr} if $EXISTING{$subr} > $MAX{$subr};
  $MAX{ALL}   = $EXISTING{ALL}   if $EXISTING{ALL}   > $MAX{ALL};
}

for (sort keys %MAX) {
  printf "%22s: %5d created total; %5d simultaneously.\n",
          $_,   $CREATED{$_},      $MAX{$_};
}
