123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- #!/usr/bin/perl
- # Parse the log output files of run-experiment
- # Send concatenated log files to stdin, or list them on the command
- # line.
- use strict;
- my $mode = '';
- my $depth = 0;
- my $numops = 0;
- my $who = 0;
- my @initsecs = (0, 0, 0);
- my @seconds = (0, 0, 0);
- my @bytes = (0, 0, 0);
- my $netsetup = '';
- my %ramen_s_data = ();
- my %ramen_kib_data = ();
- while(<>) {
- chomp;
- if (/Network setup: (.*)/) {
- $netsetup = "$1 ";
- next;
- }
- if (/===== Running ramen (\d+) (\d+)/) {
- $depth = $1;
- $numops = $2;
- @initsecs = (0,0,0);
- @seconds = (0,0,0);
- @bytes = (0,0,0);
- next;
- }
- if (/===== P([012]) output/) {
- $who = $1;
- next;
- }
- if (/^InitTime: (\d+\.?\d*) ms/) {
- $initsecs[$who] = $1/1000;
- next;
- }
- if (/^time accesses:\s+(\d+\.?\d*) ms/) {
- $seconds[$who] = $1/1000;
- next;
- }
- if (/num_bytes_sent: (\d+)/) {
- $bytes[$who] += $1;
- next;
- }
- if (/===== End/) {
- my $label = "Ramen read $depth $numops";
- my $maxinitsecs = &max3($initsecs[0], $initsecs[1], $initsecs[2]);
- my $maxsecs = &max3($seconds[0], $seconds[1], $seconds[2]);
- &accum_data(\%ramen_s_data, $label, $maxinitsecs + $maxsecs);
- # The bytes values are for each party, so average them to get the
- # average communication for each party
- my $avgbytes = ($bytes[0] + $bytes[1] + $bytes[2]) / 3;
- my $kib = $avgbytes / 1024;
- &accum_data(\%ramen_kib_data, $label, $kib);
- }
- }
- # Convert the data (in the form [n, sum, sum_squares]) to statistics (in
- # the form [mean, variance])
- my %ramen_s_stats = ();
- my %ramen_kib_stats = ();
- &statsify(\%ramen_s_stats, \%ramen_s_data);
- &statsify(\%ramen_kib_stats, \%ramen_kib_data);
- # Output the data
- &output_stats(\%ramen_s_stats, "s");
- &output_stats(\%ramen_kib_stats, "KiB");
- # Subroutines
- sub max3 {
- my $m = $_[0];
- $m = $_[1] if $_[1] > $m;
- $m = $_[2] if $_[2] > $m;
- $m;
- }
- # Pass:
- # - a reference to a dictionary
- # - the key into that dictionary
- # - the new data point
- # Data is stored in the dictionary as a triple (n, sum, sum_squares)
- sub accum_data {
- my ($dict, $key, $data) = @_;
- $dict->{$key} = [0, 0, 0] unless defined $dict->{$key};
- $dict->{$key}->[0] += 1;
- $dict->{$key}->[1] += $data;
- $dict->{$key}->[2] += ($data * $data);
- }
- # Convert data (in the form [n, sum, sum_squares]) to statistics (in
- # the form [mean, variance])
- sub statsify {
- my ($sdict, $ddict) = @_;
- my $key;
- foreach $key (keys %$ddict) {
- my $data = $ddict->{$key};
- my $n = $data->[0];
- my $sum = $data->[1];
- my $sumsq = $data->[2];
- if ($n == 0) {
- $sdict->{$key} = [undef, undef];
- } elsif ($n == 1) {
- $sdict->{$key} = [$sum, undef];
- } else {
- $sdict->{$key} = [$sum/$n, ($sumsq - ($sum*$sum/$n))/($n-1)];
- }
- }
- }
- # Turn a stat array [mean, variance] into a string to display
- sub statstr {
- my $data = $_[0];
- if (defined $data->[1]) {
- my $mean = $data->[0];
- my $stddev = $data->[1] > 0 ? sqrt($data->[1]) : 0;
- return "$mean ± $stddev";
- } elsif (defined $data->[0]) {
- return $data->[0];
- } else {
- return "none"
- }
- }
- # Output the stats in the given dictionary. Append $phase to the
- # protocol name, and add $units to the end.
- sub output_stats {
- my ($dict, $units) = @_;
- my $label;
- foreach $label (sort keys %$dict) {
- print $label, " ", &statstr($dict->{$label}), " $units\n";
- }
- }
|