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

my $subset='setup';
my $lasttime=0;

my %numcommands;
my %timespent;

my $timestamp;
my $output;

sub recordprev {
	return unless $lasttime;
	return if $subset eq 'setup' || $subset eq 'cleanup';
	
	$timespent{all} += $timestamp - $lasttime unless $subset eq 'null';
	$timespent{$subset} += $timestamp - $lasttime;
}

while (<>) {
	chomp;
	($timestamp, $output)=split(' ', $_, 2);
	if ($output =~ /^Benchmarker starting: (.*)/) {
		$subset=$1;
		recordprev();
	}
	elsif ($output =~ /^prompt> (.*)/) {
		if ($subset ne 'setup' && $subset ne 'cleanup') {
			$numcommands{all}++ unless $subset eq 'null';
			$numcommands{$subset}++;
			recordprev();
			$lasttime=$timestamp;
		}
	}
}

# Figure out what part of a second is used to run one null command.
my $nulloffset=$timespent{null} / $numcommands{null};

foreach my $key ((grep { $_ ne 'all' } keys %numcommands), 'all') {
	print "$key:".(' ' x (40 - length $key))." ";
	if ($key eq 'null') {
		print $nulloffset;
	}
	else {
		my $divisor = $timespent{$key} - $nulloffset * $numcommands{$key};
		if ($divisor > 0) {
		      print $numcommands{$key}/$divisor
		}
		else {
			print "<unmeasurable>";
		}
	}
	print " MOOstones";
#	print "\t(".($numcommands{$key} / $timespent{$key})." raw)";
	print "\n";
}
