parse_logs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #!/usr/bin/perl
  2. # Parse the log output files of run-experiment
  3. # Send concatenated log files to stdin, or list them on the command
  4. # line.
  5. use strict;
  6. my $mode = '';
  7. my $depth = 0;
  8. my $numops = 0;
  9. my $who = 0;
  10. my @initsecs = (0, 0, 0);
  11. my @seconds = (0, 0, 0);
  12. my @bytes = (0, 0, 0);
  13. my $netsetup = '';
  14. my %ramen_s_data = ();
  15. my %ramen_kib_data = ();
  16. while(<>) {
  17. chomp;
  18. if (/Network setup: (.*)/) {
  19. $netsetup = "$1 ";
  20. next;
  21. }
  22. if (/===== Running ramen (\d+) (\d+)/) {
  23. $depth = $1;
  24. $numops = $2;
  25. @initsecs = (0,0,0);
  26. @seconds = (0,0,0);
  27. @bytes = (0,0,0);
  28. next;
  29. }
  30. if (/===== P([012]) output/) {
  31. $who = $1;
  32. next;
  33. }
  34. if (/^InitTime: (\d+\.?\d*) ms/) {
  35. $initsecs[$who] = $1/1000;
  36. next;
  37. }
  38. if (/^time accesses:\s+(\d+\.?\d*) ms/) {
  39. $seconds[$who] = $1/1000;
  40. next;
  41. }
  42. if (/num_bytes_sent: (\d+)/) {
  43. $bytes[$who] += $1;
  44. next;
  45. }
  46. if (/===== End/) {
  47. my $label = "Ramen read $depth $numops";
  48. my $maxinitsecs = &max3($initsecs[0], $initsecs[1], $initsecs[2]);
  49. my $maxsecs = &max3($seconds[0], $seconds[1], $seconds[2]);
  50. &accum_data(\%ramen_s_data, $label, $maxinitsecs + $maxsecs);
  51. # The bytes values are for each party, so average them to get the
  52. # average communication for each party
  53. my $avgbytes = ($bytes[0] + $bytes[1] + $bytes[2]) / 3;
  54. my $kib = $avgbytes / 1024;
  55. &accum_data(\%ramen_kib_data, $label, $kib);
  56. }
  57. }
  58. # Convert the data (in the form [n, sum, sum_squares]) to statistics (in
  59. # the form [mean, variance])
  60. my %ramen_s_stats = ();
  61. my %ramen_kib_stats = ();
  62. &statsify(\%ramen_s_stats, \%ramen_s_data);
  63. &statsify(\%ramen_kib_stats, \%ramen_kib_data);
  64. # Output the data
  65. &output_stats(\%ramen_s_stats, "s");
  66. &output_stats(\%ramen_kib_stats, "KiB");
  67. # Subroutines
  68. sub max3 {
  69. my $m = $_[0];
  70. $m = $_[1] if $_[1] > $m;
  71. $m = $_[2] if $_[2] > $m;
  72. $m;
  73. }
  74. # Pass:
  75. # - a reference to a dictionary
  76. # - the key into that dictionary
  77. # - the new data point
  78. # Data is stored in the dictionary as a triple (n, sum, sum_squares)
  79. sub accum_data {
  80. my ($dict, $key, $data) = @_;
  81. $dict->{$key} = [0, 0, 0] unless defined $dict->{$key};
  82. $dict->{$key}->[0] += 1;
  83. $dict->{$key}->[1] += $data;
  84. $dict->{$key}->[2] += ($data * $data);
  85. }
  86. # Convert data (in the form [n, sum, sum_squares]) to statistics (in
  87. # the form [mean, variance])
  88. sub statsify {
  89. my ($sdict, $ddict) = @_;
  90. my $key;
  91. foreach $key (keys %$ddict) {
  92. my $data = $ddict->{$key};
  93. my $n = $data->[0];
  94. my $sum = $data->[1];
  95. my $sumsq = $data->[2];
  96. if ($n == 0) {
  97. $sdict->{$key} = [undef, undef];
  98. } elsif ($n == 1) {
  99. $sdict->{$key} = [$sum, undef];
  100. } else {
  101. $sdict->{$key} = [$sum/$n, ($sumsq - ($sum*$sum/$n))/($n-1)];
  102. }
  103. }
  104. }
  105. # Turn a stat array [mean, variance] into a string to display
  106. sub statstr {
  107. my $data = $_[0];
  108. if (defined $data->[1]) {
  109. my $mean = $data->[0];
  110. my $stddev = $data->[1] > 0 ? sqrt($data->[1]) : 0;
  111. return "$mean ± $stddev";
  112. } elsif (defined $data->[0]) {
  113. return $data->[0];
  114. } else {
  115. return "none"
  116. }
  117. }
  118. # Output the stats in the given dictionary. Append $phase to the
  119. # protocol name, and add $units to the end.
  120. sub output_stats {
  121. my ($dict, $units) = @_;
  122. my $label;
  123. foreach $label (sort keys %$dict) {
  124. print $label, " ", &statstr($dict->{$label}), " $units\n";
  125. }
  126. }