1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
#!/usr/bin/perl -w
use strict;
use English;
my $ECHOLOT_BASE = shift @ARGV;
die ("Usage: $PROGRAM_NAME <echolot base>\n") if (!defined $ECHOLOT_BASE || scalar @ARGV > 0);
my $INDEX = $ECHOLOT_BASE.'/results/thesaurus/index.txt';
my $STATSDIR = $ECHOLOT_BASE.'/data';
my $AUTORANGE = 'ploticus/plot-autorange.pls';
my $SAMERANGE = 'ploticus/plot-samerange.pls';
my $SAMERANGESMALL = 'ploticus/plot-samerange-small.pls';
my $DOTS_AUTORANGE = 'ploticus/plot-dots-autorange.pls';
my $DOTS_SAMERANGE = 'ploticus/plot-dots-samerange.pls';
my $DOTS_SAMERANGESMALL = 'ploticus/plot-dots-samerange-small.pls';
my $OUTDIR = 'result';
my $OUTINDEX = 'result/index.html';
my $OUTSTATS = 'result/stats.txt';
my $TMP = 'tmp';
my $NOW = time;
my $GMTIME = gmtime($NOW);
#my $IMG_URL = 'http://images.noreply.org/latency/';
my $IMG_URL = '';
my $VERBOSE = 0;
my $PLOTICUS = 'ploticus';
my $IDENTIFY = 'identify';
opendir(DIR, $STATSDIR) or die ("Cannot open $STATSDIR: $!\n");
my @FILES = readdir(DIR);
closedir(DIR);
sub getsize($) {
my ($fn) = @_;
open (FH, "$IDENTIFY $fn|") or die ("Cannot call $IDENTIFY: $!\n");
my $l = <FH>;
close FH;
unless (defined $l) {
warn ("Cannot identify $fn\n");
return {x => 0, y => 0};
};
my ($x, $y) = $l =~ /(\d+)x(\d+)/;
return {x => $x, y=> $y};
};
open(STATS, '>'.$OUTSTATS) or die ("Cannot open $OUTSTATS: $!\n");
print STATS "node median mean stddev\n";
my %remailers;
open (INDEX, $INDEX) or die("Cannot open $INDEX: $!\n");
while (<INDEX>) {
my ($nick, $id, $address) = split (/\s+/,$_);
my @address = quotemeta($address);
my @files = grep {/^$address\..*\.done$/} @FILES;
my @lines;
for my $file (@files) {
open(F, $STATSDIR.'/'.$file) or
warn("Cannot open $STATSDIR/$file: $!\n"),
next;
push @lines, map {chomp; $_} <F>;
close(F);
};
my $count = scalar @lines;
unless ($count) {
warn("No data for $address\n") if ($VERBOSE);
next;
};
my $sum = 0;
my @values = sort { $a <=> $b } map { my @tmp = split; $tmp[1] /= 60; $sum += $tmp[1]; $tmp[1]; } @lines;
my $mean = $sum / $count;
my $median = ($count % 2 == 0) ? ($values[$count/2 - 1] + $values[$count/2])/2 : $values[$count/2];
my @points = map { my @tmp = split; $tmp[0] = ($tmp[0]-$NOW)/(60*60*24); $tmp[1] /= 60; $tmp[0].' '.$tmp[1] } @lines;
my $sum_delta = 0;
for (@values) { my $tmp = $_ - $mean; $sum_delta += $tmp * $tmp };
my $stddev = sqrt( $sum_delta / $count );
open (STUBS, ">$TMP/stubs") or
warn ("Cannot open $TMP/stubs: $!\n"),
next;
print STUBS "$mean mean\n";
print STUBS "$median median\n";
close STUBS;
open (VALUES, ">$TMP/values") or
warn ("Cannot open $TMP/values: $!\n"),
next;
print VALUES "$_\n" for @values;
close VALUES;
open (POINTS, ">$TMP/points") or
warn ("Cannot open $TMP/points $!\n"),
next;
print POINTS "$_\n" for @points;
close POINTS;
my $autorange = $nick.'-autorange.png';
my $samerange = $nick.'-samerange.png';
my $samerangesmall = $nick.'-samerange.small.png';
system($PLOTICUS, '-o', $OUTDIR.'/'.$autorange, '-png', '-scale', '1.0,1.0', $AUTORANGE);
system($PLOTICUS, '-o', $OUTDIR.'/'.$samerange, '-png', '-scale', '1.0,1.0', $SAMERANGE);
system($PLOTICUS, '-o', $OUTDIR.'/'.$samerangesmall, '-png', '-scale', '1.0,1.0', $SAMERANGESMALL);
my $dots_autorange = $nick.'-dots-autorange.png';
my $dots_samerange = $nick.'-dots-samerange.png';
my $dots_samerangesmall = $nick.'-dots-samerange.small.png';
system($PLOTICUS, '-o', $OUTDIR.'/'.$dots_autorange, '-png', '-scale', '1.0,1.0', $DOTS_AUTORANGE);
system($PLOTICUS, '-o', $OUTDIR.'/'.$dots_samerange, '-png', '-scale', '1.0,1.0', $DOTS_SAMERANGE);
system($PLOTICUS, '-o', $OUTDIR.'/'.$dots_samerangesmall, '-png', '-scale', '1.0,1.0', $DOTS_SAMERANGESMALL);
$remailers{$address} = {
address => $address,
nick => $nick,
median => $median,
mean => $mean,
stddev => $stddev,
samerange => $samerange,
autorange => $autorange,
samerangesmall => $samerangesmall,
dots_samerange => $dots_samerange,
dots_autorange => $dots_autorange,
dots_samerangesmall => $dots_samerangesmall,
samerange_size => getsize($OUTDIR.'/'.$samerange),
autorange_size => getsize($OUTDIR.'/'.$autorange),
samerangesmall_size => getsize($OUTDIR.'/'.$samerangesmall),
dots_samerange_size => getsize($OUTDIR.'/'.$dots_samerange),
dots_autorange_size => getsize($OUTDIR.'/'.$dots_autorange),
dots_samerangesmall_size => getsize($OUTDIR.'/'.$dots_samerangesmall),
};
printf STATS "%s %6.0f %6.0f %6.0f\n", $nick, $median, $mean, $stddev;
}
close(INDEX);
close(STATS);
my $index;
my $body;
for my $remailer (sort { $remailers{$a}->{'nick'} cmp $remailers{$b}->{'nick'}} keys %remailers) {
my $nick = $remailers{$remailer}->{'nick'};
my $address = $remailers{$remailer}->{'address'};
my $median = $remailers{$remailer}->{'median'};
my $mean = $remailers{$remailer}->{'mean'};
my $stddev = $remailers{$remailer}->{'stddev'};
my $autorange = $remailers{$remailer}->{'autorange'};
my $samerange = $remailers{$remailer}->{'samerange'};
my $samerangesmall = $remailers{$remailer}->{'samerangesmall'};
my $dots_autorange = $remailers{$remailer}->{'dots_autorange'};
my $dots_samerange = $remailers{$remailer}->{'dots_samerange'};
my $dots_samerangesmall = $remailers{$remailer}->{'dots_samerangesmall'};
my $autorange_size = $remailers{$remailer}->{'autorange_size'};
my $samerange_size = $remailers{$remailer}->{'samerange_size'};
my $samerangesmall_size = $remailers{$remailer}->{'samerangesmall_size'};
my $dots_autorange_size = $remailers{$remailer}->{'dots_autorange_size'};
my $dots_samerange_size = $remailers{$remailer}->{'dots_samerange_size'};
my $dots_samerangesmall_size = $remailers{$remailer}->{'dots_samerangesmall_size'};
$index .= "<li><a href=\"#$nick\">$nick <$address></a></li>\n";
$body .= "<h2><a name=\"$nick\">$nick <$address></a></h2>\n<p>\n";
$body .= "<img src=\"$IMG_URL$samerangesmall\" width=\"$samerangesmall_size->{'x'}\" height=\"$samerangesmall_size->{'y'}\">\n";
$body .= "<img src=\"$IMG_URL$dots_samerangesmall\" width=\"$dots_samerangesmall_size->{'x'}\" height=\"$dots_samerangesmall_size->{'y'}\">\n";
$body .= "<br><small><a href=\"$nick.html\">Larger images and images with adapted scales</a>.</small></p>";
open (F, '>'.$OUTDIR.'/'.$nick.'.html') or die ("Cannot open $OUTDIR/$nick.html: $!\n");
print F "<html><head><title>Latency Stats for $nick</title></head><body>\n";
print F "<h1>Latency Stats for $nick</h1>\n";
print F "<a href=\"./\">index</a><br>\n";
print F "<p>\n";
printf F "Median: %6.0f minutes<br>\n", $median;
printf F "Arithmetic Mean: %6.0f minutes<br>\n", $mean;
printf F "Standard Deviation from Mean: %6.0f minutes<br>\n", $stddev;
print F "<table>\n";
print F "<tr><td><img src=\"$IMG_URL$samerange\" width=\"$samerange_size->{'x'}\" height=\"$samerange_size->{'y'}\">".
"</td><td><img src=\"$IMG_URL$dots_samerange\" width=\"$dots_samerange_size->{'x'}\" height=\"$dots_samerange_size->{'y'}\"></td></tr>\n";
print F "<tr><td><img src=\"$IMG_URL$autorange\" width=\"$autorange_size->{'x'}\" height=\"$autorange_size->{'y'}\">" .
"</td><td><img src=\"$IMG_URL$dots_autorange\" width=\"$dots_autorange_size->{'x'}\" height=\"$dots_autorange_size->{'y'}\"></td></tr>\n";
print F "</table>\n";
print F "<hr>\nBuilt at $GMTIME<br>\n";
print F "<a href=\"web\@palfrader.org\">Peter Palfrader <web\@palfrader.org></a>\n";
print F "</body></html>\n";
}
open (F, '>'.$OUTINDEX) or die ("Cannot open $OUTINDEX: $!\n");
print F "<html><head><title>Latencies</title></head><body>\n";
print F "<h1>Latency Stats</h1>\n";
print F "<a href=\"../\">..</a><br>\n";
#print F "<ul>$index</ul>\n";
print F "$body\n";
print F "<br><br><br>\n";
print F 'Images created with Steve Grubb\'s <a href="http://ploticus.sourceforge.net/">ploticus</a>'."\n";
print F "<hr>\nBuilt at $GMTIME<br>\n";
print F "<a href=\"web\@palfrader.org\">Peter Palfrader <web\@palfrader.org></a>\n";
print F "</body></html>\n";
close (F);
|