(unnamed)
text/plain
#! /usr/bin/perl
use strict;
use POSIX qw(floor);
my $state = 0;
my $wal_level = '';
my $pages = 0;
my $binary = '';
my $scale = 0;
my $paramcount = 0;
my $mode = '';
my $sumtps = 0;
my $sumlat = 0;
my $count = 0;
my $trig = 0;
my $title = "(undef)";
my $ddltime = 0;
my @lines = ();
my $trailstr = '';
my $verbose = 1 if ($ARGV[0] eq '-v');
my %tps = ();
my %lat = ();
my %ddltime = ();
my %modestr=("n", "none", "s", "sync", "w", "WAL");
while (<STDIN>) {
push(@lines, $_);
chomp;
next if (/^(END|START)$/);
next if (/NOTICE: /);
# print "$state: $_\n";
if ($state == 0) {
if (/^## params: count=([0-9.]+) pages=([0-9.]+) mode=(.) binary=([^ ]+) scale=([0-9.]+) wal_level=([a-z]+)/) {
$paramcount = $1;
$pages = $2;
$mode = $3;
$binary = $4;
$scale = $5;
$wal_level = $6;
my $modestr = $modestr{$mode};
print "## params: wal_level=$wal_level mode=$modestr pages=$pages count=$paramcount scale=$scale\n";
print "(% are relative to \"before\")\n";
$state = 1;
next;
} else {
next;
}
} elsif ($state == 1) {
if (/^starting vacuum/) {
$state = 2;
}
next;
} elsif ($state == 2) {
if (/^bench.*/) {
$trig = 1;
$title = "before";
$state = 3;
}
} elsif ($state == 3) {
if (/^size ([0-9]+): procs ([0-9]+): time ([0-9]+)$/) {
$ddltime{$mode} = $3;
$trig = 1;
$title = "during";
$trailstr = '';
$state = 4;
}
} elsif ($state == 4) {
if (/^transaction type: /) {
$trig = 1;
$title = "after";
$trailstr = "# $_\n";
$state = 5;
}
} elsif ($state == 5) {
if (!/^statement latencies /) {
$trailstr .= "# $_\n";
next;
}
printf "DDL time: %6.0f ms (%6.1f%% relative to mode=%s)\n",
$ddltime{$mode},
floor(1000.0 * $ddltime{$mode} / $ddltime{n} + 0.5) / 10,
$modestr{n};
$trailstr .= "# $_\n";
$state = 6;
next;
} elsif ($state == 6) {
if (/^ {8}/) {
$trailstr.= "# $_\n";
next;
}
if ($verbose) {
print $trailstr;
}
$state = 0;
next;
}
if ($trig) {
die "count 0?\n" if ($count == 0);
$tps{$title} = $sumtps / $count;
$lat{$title} = $sumlat / $count;
printf "%6s: tps %6.1f (%5.1f%%), lat %9.3f ms (%5.1f%%) (%d samples)\n",
$title,
$tps{$title}, floor(1000.0 * $tps{$title} / $tps{before} + 0.5)/10,
$lat{$title}, floor(1000.0 * $lat{$title} / $lat{before} + 0.5)/10,
$count;
$sumtps = $sumlat = $count = 0;
$trig = 0;
next;
}
if (!/^progress: ([0-9.]+) s, ([0-9.]+) tps, lat ([0-9.]+) ms stddev ([0-9.]+|NaN)$/) {
last;
}
$sumtps += $2;
$sumlat += $3;
$count++;
}
if ($state != 0) {
print "Wrong state after EOF: state = $state\n";
print "=====================================\n";
foreach (-10 .. -1) {
printf "%d: %s", ($. + $_), $lines[$. + $_];
}
print "=====================================\n";
exit(1);
}
die "uncounted lines?\n" if ($count > 0);