1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
#!/usr/bin/perl
use File::Temp ();
package row;
use Moose;
has 'exp' => ( is => 'ro', 'isa' => 'Num' );
has 'gen' => ( is => 'ro', 'isa' => 'Num' );
has 'temp' => ( is => 'ro', 'isa' => 'Num' );
has 'update' => ( is => 'ro', 'isa' => 'Num' );
has 'withdraw' => ( is => 'ro', 'isa' => 'Num' );
sub reduce {
my $self = shift;
my $N = 1 << $self->exp;
return row->new(
exp => $self->exp,
gen => $self->gen / $N,
temp => $self->temp / $N,
update => $self->update / $N,
withdraw => $self->withdraw / $N
);
}
sub dump {
my ($self, $fh) = @_;
print $fh join ",", $self->exp, $self->gen, $self->temp, $self->update, $self->withdraw;
print $fh "\n";
}
package results;
use Moose;
has 'name' => (
is => 'ro',
isa => 'Str',
required => 1,
);
has 'date' => (
is => 'ro',
isa => 'Str',
required => 1,
);
has 'reduced' => (
is => 'ro',
isa => 'Bool',
default => 0,
);
has 'rows' => (
is => 'ro',
isa => 'ArrayRef[row]',
default => sub { [] },
);
has 'stub' => (
is => 'ro',
isa => 'Str',
lazy => 1,
builder => '_build_stub',
);
sub _build_stub {
my $self = shift;
my $date = $self->date;
my $name = $self->name;
my $reduced = "-reduced" if $self->reduced;
my $stub = $date . "-" . $name . $reduced;
$stub =~ tr/a-zA-Z0-9_-/@/c;
return $stub;
}
sub add {
my $self = shift;
push @{$self->rows}, row->new(@_);
}
sub reduce {
my $self = shift;
return $self if $self->reduced;
return results->new(
name => $self->name,
date => $self->date,
reduced => 1,
rows => [
map { $_->reduce } @{$self->rows}
],
);
}
sub dump {
my $self = shift;
my $fn = $self->stub . ".csv";
open my $CSV, ">", $fn;
map {
$_->dump($CSV);
} @{$self->rows};
close $CSV;
return $fn;
}
sub draw {
my $self = shift;
my $csv = $self->dump();
my $svg = $self->stub . ".svg";
my $title = $self->name;
$title =~ s/_/ /g;
open PLOT, "|-", "gnuplot -p";
print PLOT "set terminal svg;\n";
print PLOT "set output '$svg';\n";
print PLOT "set title '$title';\n";
print PLOT "set datafile separator ',';\n";
print PLOT "set jitter over 0.3 spread 0.3;\n";
print PLOT "plot '$csv' using 1:2 title 'gen', '$csv' using 1:3 title 'temp', '$csv' using 1:4 title 'update', '$csv' using 1:5 title 'withdraw';\n";
close PLOT;
}
package main;
my %results;
my @done;
while (<>) {
if (m/(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}).*?Perf (.+) starting$/) {
my $date = $1;
my $name = $2;
die "Garbled input data" if exists $results{$name};
$results{$name} = results->new(name => $name, date => $date);
next;
}
if (m/Perf (.+) done with exp=(\d+)$/) {
my $name = $1;
die "Garbled input data" unless exists $results{$name};
push @done, $results{$name};
delete $results{$name};
next;
}
my ($name, $exp, $gen, $temp, $update, $withdraw) = m/Perf (.+) exp=(\d+) times: gen=(\d+) temp=(\d+) update=(\d+) withdraw=(\d+)$/ or next;
exists $results{$name} or die "Garbled input data";
$results{$name}->add(exp => $exp, gen => $gen, temp => $temp, update => $update, withdraw => $withdraw);
}
scalar %results and die "Incomplete input data";
foreach my $res (@done) {
$res->reduce->draw();
}
|