#!/usr/bin/perl
$0 =~ s/.*\///;

use ZEDAT::Perl;
use autodie;

my @results = ();                       # ({ workers => reqs, ...}, ...)
my %workers_exist = ();

for my $file (@ARGV) {
        say("read $file");
        open(my $in, "<", $file);
        my $data = {};
        my $workers;
        while (defined($_ = <$in>)) {
                if (/======== running with (\d+) workers/) {
                        $workers = $1;
                        $workers_exist{$workers} = 1;
                } elsif (/Requests\/sec: +(\d+)/) {
                        $data->{$workers} = $1;
                }
        }
        close($in);
        push(@results, $data);
}

printf("workers");
for (my $run = 1; $run <= @results; $run++) {
        print("  run $run");
}
say('');

for my $workers (sort {$a <=> $b} keys(%workers_exist)) {
        printf("%6d ", $workers);
        for (my $run = 1; $run <= @results; $run++) {
                printf(" %6d", $results[$run - 1]->{$workers} // 0);
        }
        say('');
}
