Browse Source

Have parse_logs compute stats from multiple runs

Ian Goldberg 1 year ago
parent
commit
70e511d481
1 changed files with 75 additions and 2 deletions
  1. 75 2
      parse_logs

+ 75 - 2
parse_logs

@@ -15,6 +15,8 @@ my $setupsize = 0;
 my $opsize = 0;
 my @seconds = (0, 0);
 my $netsetup = '';
+my %floram_s_data = ();
+my %floram_kib_data = ();
 
 while(<>) {
     chomp;
@@ -66,14 +68,85 @@ while(<>) {
     }
     $what = '';
     if (/===== End/) {
+        my $label = "Floram $mode $depth $netsetup$numops";
         my $maxsecs = $seconds[0];
         $maxsecs = $seconds[1] if $seconds[1] > $maxsecs;
-        print "Floram $mode $depth $netsetup$numops $maxsecs s\n";
+        &accum_data(\%floram_s_data, $label, $maxsecs);
         # The setupsize and opsize are the _sum_ for the two parties, so
         # add them to get the total size for both parties, and divide by
         # 2 to get the average size for each party
         my $bytes = ($setupsize + $opsize) / 2;
         my $kib = $bytes / 1024;
-        print "Floram $mode $depth $netsetup$numops $kib KiB\n";
+        &accum_data(\%floram_kib_data, $label, $kib);
+    }
+}
+
+# Convert the data (in the form [n, sum, sum_squares]) to statistics (in
+# the form [mean, variance])
+my %floram_s_stats = ();
+my %floram_kib_stats = ();
+&statsify(\%floram_s_stats, \%floram_s_data);
+&statsify(\%floram_kib_stats, \%floram_kib_data);
+
+# Output the data
+&output_stats(\%floram_s_stats, "s");
+&output_stats(\%floram_kib_stats, "KiB");
+
+# Subroutines
+
+# 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";
     }
 }