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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
|
#
# Part of the ht://Dig package <http://www.htdig.org/>
# Copyright (c) 1999-2004 The ht://Dig Group
# For copyright details, see the file COPYING in your distribution
# or the GNU Library General Public License (LGPL) version 2 or later
# <http://www.gnu.org/copyleft/lgpl.html>
#
#
# Use the result from WordMonitor (--input=file) and generate a report in
# benchmark/<--output=name>-YYYY-MM-DD/index.html.
# If --comment='bla bla' is provided it is copied in the comment.txt file.
#
use strict;
use Getopt::Long;
use File::Path;
use POSIX qw(strftime);
my($report) = "unknown";
my($verbose);
my($comment) = "";
my($dir);
sub main {
my($file) = "monitor.out";
GetOptions("input=s" => \$file,
"output=s" => \$report,
"comment=s" => \$comment,
"verbose=i" => \$verbose,
);
my($timestamp) = strftime("%Y-%m-%d", localtime);
$dir = "benchmark/$report-$timestamp";
if(-d $dir) {
print STDERR "directory $dir exists, will not override: abort\n";
exit(1);
}
mkpath($dir, 0, 0777) or die "cannot mkdirp $dir : $!";
my($cmds) = "$dir/README";
open(CMDS, ">$cmds") or die "cannot open $cmds for writing : $!";
report(build($file));
close(CMDS);
my($file) = "$dir/monitor.rrd";
unlink($file) or die "cannot unlink $file : $!";
}
sub report {
my($started, $finished, @fields) = @_;
my($file) = "$dir/config.html";
open(FILE, ">$file") or die "cannot open $file for writing : $!";
print FILE "<body bgcolor=#ffffff>\n<pre>";
close(FILE);
run("uname -a >> $file");
run("cat /proc/cpuinfo >> $file") if(-f "/proc/cpuinfo");
run("cat /proc/meminfo >> $file") if(-f "/proc/meminfo");
$file = "$dir/comment.html";
open(FILE, ">$file") or die "cannot open $file for writing : $!";
print FILE "<body bgcolor=#ffffff>\n<pre>";
if(!$comment) {
print FILE "No comment\n";
} else {
print FILE $comment;
}
close(FILE);
#
# Generate a graph for each value
#
my(%vlabel) = (
'Write' => 'Pages',
'Read' => 'Pages',
'P_IBTREE' => 'Pages',
'P_LBTREE' => 'Pages',
'P_UNKNOWN' => 'Pages',
'Put' => 'Put',
'Get__0_' => 'Get',
'Get__NEXT_' => 'Get',
'Get__SET_RANGE_' => 'Get',
'Get__Other_' => 'Get',
'LEVEL' => 'Level',
'PGNO' => 'Pages',
'CMP' => 'Compare',
);
my(%hlabel) = (
'Write' => 'Write/second',
'Read' => 'Read/second',
'P_IBTREE' => 'Internal B-Tree nodes read + write / second',
'P_LBTREE' => 'Leaf B-Tree nodes read + write / second',
'P_UNKNOWN' => 'Unknown pages read + write / second',
'Put' => 'Put / second',
'Get__0_' => 'Get(0) / second',
'Get__NEXT_' => 'Get(DB_NEXT) / second',
'Get__SET_RANGE_' => 'Get(DB_SET_RANGE) / second',
'Get__Other_' => 'Get(???) / second',
'LEVEL' => 'Height of the B-Tree',
'PGNO' => 'Size of the B-Tree in pages',
'CMP' => 'Key compare / second',
);
my(@graphs);
my($field);
foreach $field (@fields) {
my($image) = "$dir/$field.gif";
my($hlabel) = exists($hlabel{$field}) ? "--title '$hlabel{$field}'" : "";
my($vlabel) = exists($vlabel{$field}) ? "--vertical-label '$vlabel{$field}'" : "";
run("rrdtool graph $image --start $started --end $finished $hlabel $vlabel DEF:in=$dir/monitor.rrd:$field:AVERAGE 'LINE2:in#FF0000' >/dev/null");
}
#
# Generate a cumulated graph for compression rates
#
my(%rate) = (
'Compress_1_1' => 1,
'Compress_1_2' => 2,
'Compress_1_3' => 3,
'Compress_1_4' => 4,
'Compress_1_5' => 5,
'Compress_1_6' => 6,
'Compress_1_7' => 7,
'Compress_1_8' => 8,
'Compress_1_9' => 9,
'Compress_1_10' => 10,
'Compress_1__10' => 11,
);
my(%color) = (
'Compress_1_1' => "#ff0000",
'Compress_1_2' => "#ee1100",
'Compress_1_3' => "#dd2200",
'Compress_1_4' => "#cc3300",
'Compress_1_5' => "#bb4400",
'Compress_1_6' => "#996600",
'Compress_1_7' => "#778800",
'Compress_1_8' => "#55aa00",
'Compress_1_9' => "#33cc00",
'Compress_1_10' => "#11ee00",
'Compress_1__10' => "#00ff00",
);
my($last_total);
my(@lines);
foreach $field (@fields) {
next if($field !~ /^Compress/);
my($cdef) = "";
my($total) = "cmpr$rate{$field}";
if($last_total) {
$total = "total$rate{$field}";
$cdef = "CDEF:$total=$last_total,cmpr$rate{$field},+";
}
$last_total = $total;
push(@lines, "DEF:cmpr$rate{$field}=$dir/monitor.rrd:$field:AVERAGE $cdef 'LINE1:$total$color{$field}:1/$rate{$field}'");
}
run("rrdtool graph $dir/compress.gif --start $started --end $finished --title 'Compression rate comparison / second' --vertical-label 'Pages' @lines >/dev/null");
#
# Build home page
#
$file = "$dir/index.html";
open(FILE, ">$file") or die "cannot open $file for writing : $!";
print FILE <<EOF;
<body bgcolor=#ffffff>
<center>
[<a href=config.html>Configuration</a> | <a href=comment.html>Comment</a> | <a href=monitor.out>Samples</a> | <a href=compress.html>Compression</a>]
<p>
EOF
print FILE <<EOF;
<br>
<img src="compress.gif">
<br>
In the graph above, the area under each line is the number of pages
compressed in the corresponding proportions. The bottom line is always 1/1
compression. For instance the area between the 1/11 line and the 1/10 line
shows how many pages were compressed in a proportion equal or better than 1/11.
In <a href=compress.html>the compression report</a> an individual graph is
shown for each line.
<br>
EOF
foreach $field (@fields) {
next if($field =~ /^Compress/);
print FILE <<EOF;
<br>
<img src="$field.gif">
<br>
EOF
}
print FILE "</center>\n";
close(FILE);
#
# Build compression details page
#
$file = "$dir/compress.html";
open(FILE, ">$file") or die "cannot open $file for writing : $!";
print FILE <<EOF;
<body bgcolor=#ffffff>
<center>
[<a href=index.html>Home page</a>]
<p>
EOF
print FILE <<EOF;
<br>
<img src="compress.gif">
<br>
EOF
foreach $field (@fields) {
next if($field !~ /^Compress/);
print FILE <<EOF;
$field
<br>
<img src="$field.gif">
<br>
EOF
}
print FILE "</center>\n";
close(FILE);
}
sub run {
my($cmd) = @_;
system($cmd);
print STDERR "$cmd\n" if($verbose);
print CMDS "$cmd\n";
}
sub build {
my($file) = @_;
system("cp $file $dir");
my(@fields);
my($started);
my($step);
my($heartbeat);
my($finished);
my(@updates);
open(FILE, "<$file") or die "cannot open $file for reading : $!";
while(<FILE>) {
if(/WordMonitor starting/) {
($started) = <FILE> =~ /^Started:(\d+)/;
($step) = <FILE> =~ /^Period:(\d+)/;
$heartbeat = $step * 2;
my(@ds);
@fields = split(':', scalar(<FILE>));
shift(@fields); # get rid of Time field
pop(@fields); # get rid of last empty field
my($field);
foreach $field (@fields) {
my($type) = $field =~ /^(.)\./;
$field =~ s/^..//;
$field =~ s/[^a-z0-9_]/_/gi;
if($type eq 'C') {
push(@ds, "DS:$field:COUNTER:$heartbeat:U:U");
} elsif($type eq 'G') {
push(@ds, "DS:$field:GAUGE:$heartbeat:0:U");
} else {
print STDERR "Unknown type $type for field $field\n";
exit(1);
}
}
my($ds) = join(' ', @ds);
my($rra) = "RRA:AVERAGE:0.5:1:2000";
my($cmd) = "rrdtool create $dir/monitor.rrd --step $step --start $started $ds $rra";
run("rm -f $dir/monitor.rrd ; $cmd");
next;
}
next if(/-------------/ || /^\s*$/);
chop; # remove new line
chop; # remove last :
($finished) = m/^(\d+):/;
print STDERR "$_\n" if($verbose);
push(@updates, $_);
if(@updates > 50) {
run("rrdtool update $dir/monitor.rrd " . join(' ', @updates));
@updates = ();
}
}
if(@updates) {
run("rrdtool update $dir/monitor.rrd " . join(' ', @updates));
}
close(FILE);
print STDERR "started = $started, finished = $finished\n" if($verbose);
return ($started, $finished, @fields);
}
main();
|