#!/usr/bin/env perl
use strict;

my @keys;
my %types;
my $setkeys = 1;
while (<>) {
  next if (!/^.* ([\w-]+)(\([^\)]*\))?: Debug: rusage: (.*)$/);
  my ($type, $data) = ($1, $3);
  
  my @new;
  my @list = split(" ", $data);
  foreach my $arg (@list) {
    die "broken: $arg" if ($arg !~ /^(.*)=([\d+.]+)$/);
    if ($setkeys) {
      push @keys, $1;
    }
    push @new, $2;
  }
  push @new, 1;
  push @keys, "count" if ($setkeys);
  $setkeys = 0;
  
  if (!defined($types{$type})) {
    $types{$type} = \@new;
  } else {
    for (my $i = 0; $i < scalar @new; $i++) {
      $types{$type}->[$i] += $new[$i];
    }
  }
}

print "type";
foreach my $key (@keys) {
  print "\t$key";
}
print "\n";
foreach my $type (keys %types) {
  print "$type";
  my @values = @{$types{$type}};
  for (my $i = 0; $i < scalar @values; $i++) {
    print "\t";
    if ($i < 3) {
      printf "%.2f", $values[$i];
    } else {
      print $values[$i];
    }
  }
  print "\n";
}
