Debian Codegraph @

test/benchmark-report

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 #
2 # Part of the ht://Dig package <http://www.htdig.org/>
3 # Copyright (c) 1999-2004 The ht://Dig Group
4 # For copyright details, see the file COPYING in your distribution
5 # or the GNU Library General Public License (LGPL) version 2 or later
6 # <http://www.gnu.org/copyleft/lgpl.html>
7 #
8 #
9 # Use the result from WordMonitor (--input=file) and generate a report in
10 # benchmark/<--output=name>-YYYY-MM-DD/index.html.
11 # If --comment='bla bla' is provided it is copied in the comment.txt file.
12 #
13 use strict;
14 use Getopt::Long;
15 use File::Path;
16 use POSIX qw(strftime);
17
18 my($report) = "unknown";
19 my($verbose);
20 my($comment) = "";
21 my($dir);
22
23 sub main {
24 my($file) = "monitor.out";
25
26 GetOptions("input=s" => \$file,
27 "output=s" => \$report,
28 "comment=s" => \$comment,
29 "verbose=i" => \$verbose,
30 );
31
32 my($timestamp) = strftime("%Y-%m-%d", localtime);
33 $dir = "benchmark/$report-$timestamp";
34 if(-d $dir) {
35 print STDERR "directory $dir exists, will not override: abort\n";
36 exit(1);
37 }
38 mkpath($dir, 0, 0777) or die "cannot mkdirp $dir : $!";
39 my($cmds) = "$dir/README";
40 open(CMDS, ">$cmds") or die "cannot open $cmds for writing : $!";
41 report(build($file));
42 close(CMDS);
43 my($file) = "$dir/monitor.rrd";
44 unlink($file) or die "cannot unlink $file : $!";
45 }
46
47 sub report {
48 my($started, $finished, @fields) = @_;
49
50 my($file) = "$dir/config.html";
51 open(FILE, ">$file") or die "cannot open $file for writing : $!";
52 print FILE "<body bgcolor=#ffffff>\n<pre>";
53 close(FILE);
54 run("uname -a >> $file");
55 run("cat /proc/cpuinfo >> $file") if(-f "/proc/cpuinfo");
56 run("cat /proc/meminfo >> $file") if(-f "/proc/meminfo");
57
58 $file = "$dir/comment.html";
59 open(FILE, ">$file") or die "cannot open $file for writing : $!";
60 print FILE "<body bgcolor=#ffffff>\n<pre>";
61 if(!$comment) {
62 print FILE "No comment\n";
63 } else {
64 print FILE $comment;
65 }
66 close(FILE);
67
68 #
69 # Generate a graph for each value
70 #
71 my(%vlabel) = (
72 'Write' => 'Pages',
73 'Read' => 'Pages',
74 'P_IBTREE' => 'Pages',
75 'P_LBTREE' => 'Pages',
76 'P_UNKNOWN' => 'Pages',
77 'Put' => 'Put',
78 'Get__0_' => 'Get',
79 'Get__NEXT_' => 'Get',
80 'Get__SET_RANGE_' => 'Get',
81 'Get__Other_' => 'Get',
82 'LEVEL' => 'Level',
83 'PGNO' => 'Pages',
84 'CMP' => 'Compare',
85 );
86 my(%hlabel) = (
87 'Write' => 'Write/second',
88 'Read' => 'Read/second',
89 'P_IBTREE' => 'Internal B-Tree nodes read + write / second',
90 'P_LBTREE' => 'Leaf B-Tree nodes read + write / second',
91 'P_UNKNOWN' => 'Unknown pages read + write / second',
92 'Put' => 'Put / second',
93 'Get__0_' => 'Get(0) / second',
94 'Get__NEXT_' => 'Get(DB_NEXT) / second',
95 'Get__SET_RANGE_' => 'Get(DB_SET_RANGE) / second',
96 'Get__Other_' => 'Get(???) / second',
97 'LEVEL' => 'Height of the B-Tree',
98 'PGNO' => 'Size of the B-Tree in pages',
99 'CMP' => 'Key compare / second',
100 );
101
102 my(@graphs);
103 my($field);
104 foreach $field (@fields) {
105 my($image) = "$dir/$field.gif";
106 my($hlabel) = exists($hlabel{$field}) ? "--title '$hlabel{$field}'" : "";
107 my($vlabel) = exists($vlabel{$field}) ? "--vertical-label '$vlabel{$field}'" : "";
108 run("rrdtool graph $image --start $started --end $finished $hlabel $vlabel DEF:in=$dir/monitor.rrd:$field:AVERAGE 'LINE2:in#FF0000' >/dev/null");
109 }
110
111 #
112 # Generate a cumulated graph for compression rates
113 #
114 my(%rate) = (
115 'Compress_1_1' => 1,
116 'Compress_1_2' => 2,
117 'Compress_1_3' => 3,
118 'Compress_1_4' => 4,
119 'Compress_1_5' => 5,
120 'Compress_1_6' => 6,
121 'Compress_1_7' => 7,
122 'Compress_1_8' => 8,
123 'Compress_1_9' => 9,
124 'Compress_1_10' => 10,
125 'Compress_1__10' => 11,
126 );
127 my(%color) = (
128 'Compress_1_1' => "#ff0000",
129 'Compress_1_2' => "#ee1100",
130 'Compress_1_3' => "#dd2200",
131 'Compress_1_4' => "#cc3300",
132 'Compress_1_5' => "#bb4400",
133 'Compress_1_6' => "#996600",
134 'Compress_1_7' => "#778800",
135 'Compress_1_8' => "#55aa00",
136 'Compress_1_9' => "#33cc00",
137 'Compress_1_10' => "#11ee00",
138 'Compress_1__10' => "#00ff00",
139 );
140 my($last_total);
141 my(@lines);
142 foreach $field (@fields) {
143 next if($field !~ /^Compress/);
144 my($cdef) = "";
145 my($total) = "cmpr$rate{$field}";
146 if($last_total) {
147 $total = "total$rate{$field}";
148 $cdef = "CDEF:$total=$last_total,cmpr$rate{$field},+";
149 }
150 $last_total = $total;
151 push(@lines, "DEF:cmpr$rate{$field}=$dir/monitor.rrd:$field:AVERAGE $cdef 'LINE1:$total$color{$field}:1/$rate{$field}'");
152 }
153 run("rrdtool graph $dir/compress.gif --start $started --end $finished --title 'Compression rate comparison / second' --vertical-label 'Pages' @lines >/dev/null");
154
155 #
156 # Build home page
157 #
158 $file = "$dir/index.html";
159 open(FILE, ">$file") or die "cannot open $file for writing : $!";
160 print FILE <<EOF;
161 <body bgcolor=#ffffff>
162 <center>
163 [<a href=config.html>Configuration</a> | <a href=comment.html>Comment</a> | <a href=monitor.out>Samples</a> | <a href=compress.html>Compression</a>]
164 <p>
165 EOF
166 print FILE <<EOF;
167 <br>
168 <img src="compress.gif">
169 <br>
170 In the graph above, the area under each line is the number of pages
171 compressed in the corresponding proportions. The bottom line is always 1/1
172 compression. For instance the area between the 1/11 line and the 1/10 line
173 shows how many pages were compressed in a proportion equal or better than 1/11.
174 In <a href=compress.html>the compression report</a> an individual graph is
175 shown for each line.
176 <br>
177 EOF
178
179 foreach $field (@fields) {
180 next if($field =~ /^Compress/);
181 print FILE <<EOF;
182 <br>
183 <img src="$field.gif">
184 <br>
185 EOF
186 }
187 print FILE "</center>\n";
188 close(FILE);
189
190 #
191 # Build compression details page
192 #
193 $file = "$dir/compress.html";
194 open(FILE, ">$file") or die "cannot open $file for writing : $!";
195 print FILE <<EOF;
196 <body bgcolor=#ffffff>
197 <center>
198 [<a href=index.html>Home page</a>]
199 <p>
200 EOF
201 print FILE <<EOF;
202 <br>
203 <img src="compress.gif">
204 <br>
205 EOF
206
207 foreach $field (@fields) {
208 next if($field !~ /^Compress/);
209 print FILE <<EOF;
210 $field
211 <br>
212 <img src="$field.gif">
213 <br>
214 EOF
215 }
216 print FILE "</center>\n";
217 close(FILE);
218 }
219
220 sub run {
221 my($cmd) = @_;
222
223 system($cmd);
224 print STDERR "$cmd\n" if($verbose);
225 print CMDS "$cmd\n";
226 }
227
228 sub build {
229 my($file) = @_;
230
231 system("cp $file $dir");
232 my(@fields);
233 my($started);
234 my($step);
235 my($heartbeat);
236 my($finished);
237 my(@updates);
238 open(FILE, "<$file") or die "cannot open $file for reading : $!";
239 while(<FILE>) {
240 if(/WordMonitor starting/) {
241 ($started) = <FILE> =~ /^Started:(\d+)/;
242 ($step) = <FILE> =~ /^Period:(\d+)/;
243 $heartbeat = $step * 2;
244 my(@ds);
245 @fields = split(':', scalar(<FILE>));
246 shift(@fields); # get rid of Time field
247 pop(@fields); # get rid of last empty field
248 my($field);
249 foreach $field (@fields) {
250 my($type) = $field =~ /^(.)\./;
251 $field =~ s/^..//;
252 $field =~ s/[^a-z0-9_]/_/gi;
253 if($type eq 'C') {
254 push(@ds, "DS:$field:COUNTER:$heartbeat:U:U");
255 } elsif($type eq 'G') {
256 push(@ds, "DS:$field:GAUGE:$heartbeat:0:U");
257 } else {
258 print STDERR "Unknown type $type for field $field\n";
259 exit(1);
260 }
261 }
262 my($ds) = join(' ', @ds);
263 my($rra) = "RRA:AVERAGE:0.5:1:2000";
264 my($cmd) = "rrdtool create $dir/monitor.rrd --step $step --start $started $ds $rra";
265 run("rm -f $dir/monitor.rrd ; $cmd");
266 next;
267 }
268 next if(/-------------/ || /^\s*$/);
269 chop; # remove new line
270 chop; # remove last :
271 ($finished) = m/^(\d+):/;
272 print STDERR "$_\n" if($verbose);
273 push(@updates, $_);
274 if(@updates > 50) {
275 run("rrdtool update $dir/monitor.rrd " . join(' ', @updates));
276 @updates = ();
277 }
278 }
279 if(@updates) {
280 run("rrdtool update $dir/monitor.rrd " . join(' ', @updates));
281 }
282 close(FILE);
283
284 print STDERR "started = $started, finished = $finished\n" if($verbose);
285 return ($started, $finished, @fields);
286 }
287
288 main();
289
290