parse_logs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. #!/usr/bin/perl
  2. use strict;
  3. my $size = 0;
  4. my $iters = 0;
  5. my $who = '';
  6. my $mode = '';
  7. my %res = ();
  8. my $offlinebytes = 0;
  9. my $netsetup = '';
  10. my %online_s_data = ();
  11. my %online_kib_data = ();
  12. my %total_s_data = ();
  13. my %total_kib_data = ();
  14. while(<>) {
  15. if (/Network setup: (.*)/) {
  16. $netsetup = "$1 ";
  17. next;
  18. }
  19. ($size,$iters) = ($1,$2) if /===== Running oram (\d+) (\d+)/;
  20. $res{$size} = {} unless defined $res{$size};
  21. $who = $1 if /===== ([CDE]) output/;
  22. $mode = $1 if /(Online Time|Offline Time|ETE)/;
  23. if(/WC\(ms\): (\d+)/) {
  24. if (defined $res{$size}->{$who.$mode}) {
  25. print "Redefinition of res{$size}->{$who$mode}\n";
  26. } else {
  27. $res{$size}->{$who.$mode} = $1/1000
  28. }
  29. }
  30. if (/Total Offline Band\(bytes\): (\d+)/) {
  31. $offlinebytes = $1;
  32. }
  33. if (/Total Online Band\(bytes\): (\d+)/) {
  34. # Note that the java code reports bandwidth *per iteration*
  35. my $onlinebytes = $1;
  36. my $totbytes = $onlinebytes + $offlinebytes;
  37. $res{$size}->{'onlbytes'} = 0 unless
  38. defined $res{$size}->{'onlbytes'};
  39. $res{$size}->{'totbytes'} = 0 unless
  40. defined $res{$size}->{'totbytes'};
  41. $res{$size}->{'onlbytes'} += $onlinebytes;
  42. $res{$size}->{'totbytes'} += $totbytes;
  43. }
  44. if (/===== End /) {
  45. my $label = "CircuitORAM read $size $netsetup$iters";
  46. my $online = &max3($res{$size}->{'COnline Time'},
  47. $res{$size}->{'DOnline Time'},
  48. $res{$size}->{'EOnline Time'});
  49. my $total = &max3($res{$size}->{'CETE'},
  50. $res{$size}->{'DETE'},
  51. $res{$size}->{'EETE'});
  52. &accum_data(\%online_s_data, $label, $online);
  53. &accum_data(\%total_s_data, $label, $total);
  54. # Note that the java code reports bandwidth *per iteration*
  55. my $onlinekib = $res{$size}->{'onlbytes'} * $iters / 1024;
  56. my $totalkib = $res{$size}->{'totbytes'} * $iters / 1024;
  57. &accum_data(\%online_kib_data, $label, $onlinekib);
  58. &accum_data(\%total_kib_data, $label, $totalkib);
  59. undef $res{$size};
  60. }
  61. }
  62. # Convert the data (in the form [n, sum, sum_squares]) to statistics (in
  63. # the form [mean, variance])
  64. my %online_s_stats = ();
  65. my %online_kib_stats = ();
  66. my %total_s_stats = ();
  67. my %total_kib_stats = ();
  68. &statsify(\%online_s_stats, \%online_s_data);
  69. &statsify(\%online_kib_stats, \%online_kib_data);
  70. &statsify(\%total_s_stats, \%total_s_data);
  71. &statsify(\%total_kib_stats, \%total_kib_data);
  72. # Output the data
  73. &output_stats(\%online_s_stats, "Onln", "s");
  74. &output_stats(\%online_kib_stats, "Onln", "KiB");
  75. &output_stats(\%total_s_stats, "Totl", "s");
  76. &output_stats(\%total_kib_stats, "Totl", "KiB");
  77. # Subroutines
  78. sub max3 {
  79. my $m = $_[0];
  80. $m = $_[1] if $_[1] > $m;
  81. $m = $_[2] if $_[2] > $m;
  82. $m;
  83. }
  84. # Pass:
  85. # - a reference to a dictionary
  86. # - the key into that dictionary
  87. # - the new data point
  88. # Data is stored in the dictionary as a triple (n, sum, sum_squares)
  89. sub accum_data {
  90. my ($dict, $key, $data) = @_;
  91. $dict->{$key} = [0, 0, 0] unless defined $dict->{$key};
  92. $dict->{$key}->[0] += 1;
  93. $dict->{$key}->[1] += $data;
  94. $dict->{$key}->[2] += ($data * $data);
  95. }
  96. # Convert data (in the form [n, sum, sum_squares]) to statistics (in
  97. # the form [mean, variance])
  98. sub statsify {
  99. my ($sdict, $ddict) = @_;
  100. my $key;
  101. foreach $key (keys %$ddict) {
  102. my $data = $ddict->{$key};
  103. my $n = $data->[0];
  104. my $sum = $data->[1];
  105. my $sumsq = $data->[2];
  106. if ($n == 0) {
  107. $sdict->{$key} = [undef, undef];
  108. } elsif ($n == 1) {
  109. $sdict->{$key} = [$sum, undef];
  110. } else {
  111. $sdict->{$key} = [$sum/$n, ($sumsq - ($sum*$sum/$n))/($n-1)];
  112. }
  113. }
  114. }
  115. # Turn a stat array [mean, variance] into a string to display
  116. sub statstr {
  117. my $data = $_[0];
  118. if (defined $data->[1]) {
  119. my $mean = $data->[0];
  120. my $stddev = $data->[1] > 0 ? sqrt($data->[1]) : 0;
  121. return "$mean ± $stddev";
  122. } elsif (defined $data->[0]) {
  123. return $data->[0];
  124. } else {
  125. return "none"
  126. }
  127. }
  128. # Output the stats in the given dictionary. Append $phase to the
  129. # protocol name, and add $units to the end.
  130. sub output_stats {
  131. my ($dict, $phase, $units) = @_;
  132. my $label;
  133. foreach $label (sort keys %$dict) {
  134. my $printlabel = $label;
  135. $printlabel =~ s/CircuitORAM/CircuitORAM$phase/;
  136. print $printlabel, " ", &statstr($dict->{$label}), " $units\n";
  137. }
  138. }