2
#### Hello ... this is a heavily hacked script by Luuk
3
#### instead of printing the result it makes a nice gif
4
#### when you want to look at the code ... beware of the
5
#### ugliest code ever seen .... but it works ...
6
#### and that's sometimes the only thing you want ... isn't it ...
7
#### as the original script ... Hope you like it
9
#### Greetz..... Luuk de Boer 1997.
12
## if you want the seconds behind the bar printed or not ...
13
## or only the one where the bar is too big for the graph ...
14
## look at line 535 of this program and below ...
15
## look in sub calculate for allmost all hard/soft settings :-)
17
# a little program to generate a table of results
18
# just read all the RUN-*.log files and format them nicely
19
# Made by Luuk de Boer
26
$opt_cmp="mysql,pg,solid";
27
$opt_cmp="msql,mysql,pg,solid";
28
$opt_cmp="empress,mysql,pg,solid";
31
$opt_relative=$opt_same_server=$opt_help=$opt_Information=$opt_skip_count=0;
33
GetOptions("Information","help","server=s","cmp=s","machine=s","relative","same-server","dir=s","skip-count") || usage();
35
usage() if ($opt_help || $opt_Information);
39
$files="$opt_dir/RUN-$opt_server-*$opt_machine";
43
$files="$opt_dir/RUN-*$opt_machine";
45
$files.= "-cmp-$opt_cmp" if (length($opt_cmp));
56
# Go trough all RUN files and gather statistics.
62
next if (defined($found{$_})); # remove duplicates
66
push(@key_order,$prog);
68
open(TMP, "<$filename") || die "Can't open $filename: $!\n";
73
if (/Server version:\s+(\S+.*)/i)
75
$tot{$prog}{'server'} = $1;
77
elsif (/Arguments:\s+(.+)/i)
79
$tot{$prog}{'arguments'} = $1;
80
# Remove some standard, not informative arguments
81
$tot{$prog}{'arguments'} =~ s/--log|--use-old-results|--server=\S+|--cmp=\S+|--user=\S+|--pass=\S+|--machine=\S+//g;
82
$tot{$prog}{'arguments'} =~ s/\s+/ /g;
84
elsif (/Comments:\s+(.+)/i) {
85
$tot{$prog}{'comments'} = $1;
86
} elsif (/^(\S+):\s*(estimated\s|)total\stime:\s+(\d+)\s+secs/i)
88
$tmp = $1; $tmp =~ s/://;
89
$tot{$prog}{$tmp} = [ $3, (length($2) ? "+" : "")];
91
} elsif (/Totals per operation:/i) {
98
if (/^(\S+)\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)\s*([+|?])*/)
100
$tot1{$prog}{$1} = [$2,$6,$7];
102
#print "TEST - $_ \n * $prog - $1 - $2 - $6 - $7 ****\n";
106
# $6 - number of loops
107
# $7 - nothing / + / ? / * => estimated time ...
108
# get the highest value ....
109
$highest = ($2/$6) if (($highest < ($2/$6)) && ($1 !~/TOTALS/i));
111
$giftotal += ($2/$6);
119
print "Didn't find any files matching: '$files'\n";
120
print "Use the --cmp=server,server option to compare benchmarks\n";
125
# everything is loaded ...
126
# now we have to create a fancy output :-)
128
# I prefer to redirect scripts instead to force it to file ; Monty
130
# open(RES, ">$resultfile") || die "Can't write to $resultfile: $!\n";
135
#<cut for this moment>
141
# print "Column 1 is in seconds. All other columns are presented relative\n";
142
# print "to this. 1.00 is the same, bigger numbers indicates slower\n\n";
145
#print "The result logs which where found and the options:\n";
147
if ($automatic_files)
149
if ($key_order[$i] =~ /^$opt_server/)
151
if ($key_order[$i] =~ /^$opt_server/)
153
unshift(@key_order,$key_order[$i]);
154
splice(@key_order,$i+1,1);
158
# extra for mysql and mysql_pgcc
159
#$number1 = shift(@key_order);
160
#$number2 = shift(@key_order);
161
#unshift(@key_order,$number1);
162
#unshift(@key_order,$number2);
167
foreach $key (@key_order)
170
# printf "%2d %-40.40s: %s %s\n", $column_count, $key,
171
# $tot{$key}{'server'}, $tot{$key}{'arguments'};
172
# print "Comments: $tot{$key}{'comments'}\n"
173
# if ($tot{$key}{'comments'} =~ /\w+/);
178
$namewidth=$opt_skip_count ? 20 :25;
179
$colwidth= $opt_relative ? 9 : 6;
182
#printf "%-$namewidth.${namewidth}s|", "Operation";
184
foreach $key (@key_order)
186
# printf "%${colwidth}d|", $count;
191
#print_string("Results per test:");
194
foreach $key (sort {$a cmp $b} keys %op1)
196
# printf "%-$namewidth.${namewidth}s|", $key;
198
foreach $server (@key_order)
200
print_value($first,$tot{$server}{$key}->[0],$tot{$server}{$key}->[1]);
201
$first=$tot{$server}{$key}->[0] if (!defined($first));
207
print_string("The results per operation:");
210
foreach $key (sort {$a cmp $b} keys %op)
212
next if ($key =~ /TOTALS/i);
214
$tmp.= " (" . $tot1{$key_order[0]}{$key}->[1] . ")" if (!$skip_count);
215
# printf "%-$namewidth.${namewidth}s|", $tmp;
217
foreach $server (@key_order)
219
print_value($first,$tot1{$server}{$key}->[0],$tot1{$server}{$key}->[2]);
220
$first=$tot1{$server}{$key}->[0] if (!defined($first));
228
#printf "%-$namewidth.${namewidth}s|", $key;
230
foreach $server (@key_order)
232
# print_value($first,$tot1{$server}{$key}->[0],$tot1{$server}{$key}->[2]);
233
$first=$tot1{$server}{$key}->[0] if (!defined($first));
242
# some format functions;
248
# print $sep x ($namewidth + (($colwidth+1) * $column_count)+1),"\n";
254
my ($first,$value,$flags)=@_;
259
if (!defined($first) || !$opt_relative)
261
$tmp=sprintf("%d",$value);
265
$first=1 if (!$first); # Assume that it took one second instead of 0
266
$tmp= sprintf("%.2f",$value/$first);
270
$tmp="+".$tmp if ($flags =~ /\+/);
271
$tmp="?".$tmp if ($flags =~ /\?/);
278
$tmp= " " x ($colwidth-length($tmp)) . $tmp if (length($tmp) < $colwidth);
287
$width=$namewidth + ($colwidth+1)*$column_count;
289
$str=substr($str,1,$width) if (length($str) > $width);
290
# print($str," " x ($width - length($str)),"|\n");
300
###########################################
301
###########################################
302
###########################################
303
# making here a gif of the results ... (lets try it :-))
305
###########################################
306
## take care that $highest / $giftotal / $gifcount / $luukcounter
307
## are getting there value above ... so don't forget them while
308
## copying the code to some other program ....
311
&gd; # some base things ....
312
&legend; # make the nice legend
313
&lines; # yep sometimes you have to print some lines
314
&gif("gif/benchmark2-".$opt_cmp); # and finally we can print all to a gif file ...
316
##### mmm we are finished now ...
319
# first we have to calculate some limits and some other stuff
321
# here is the list which I have to know to make everything .....
322
# the small border width ... $sm_border =
323
# the border default $border =
324
# the step default ... if it must be calculated then no value $step =
325
# the highest number $highest =
326
# the max length of the text of the x borders $max_len_lb=
327
# the max length of a legend entry $max_len_le=
328
# number of entries in the legend $num_legen =
329
# the length of the color blocks for the legend $legend_block=
330
# the width of the gif ...if it must be calculated - no value $width =
331
# the height of the gif .. if it must be calculated - no value $height =
332
# the width of the grey field ' ' ' ' $width_grey=
333
# the height of the grey field ' ' ' ' $height_grey=
334
# number of dashed lines $lines=
335
# if bars must overlap how much they must be overlapped $overlap=
336
# titlebar title of graph in two colors big $titlebar=
337
# titlebar1 sub title of graph in small font in black $titlebar1=
340
# the name of the gif ... $name=
341
# then the following things must be knows .....
342
# xlabel below or on the left side ?
344
# where must the legend be placed?
345
# must the xlabel be printed horizontal or vertical?
346
# must the ylabel be printed horizontal or vertical?
347
# must the graph be a line or a bar graph?
348
# is a xlabel several different entries or some sub entries of one?
349
# so xlabel 1 => test1=10, test2=15, test3=7 etc
350
# or xlabel 1 => test1a=12, test1b=10, test1c=7 etc
351
# must the bars overlap (only with the second example I think)
352
# must the number be printed above or next to the bar?
353
# when must the number be printed .... only when it extends the graph ...???
354
# the space between the bars .... are that the same width of the bars ...
355
# or is it a separate space ... defined ???
356
# must the date printed below or some where else ....
358
#calculate all space for text and other things ....
359
$sm_border = 8; # the grey border around ...
360
$border = 40; #default ...
361
$left_border = 2.75 * $border; #default ...
362
$right_border = $border; #default ...
363
$up_border = $border; #default ...
364
$down_border = $border; # default ...
365
$step = ($height - $up_border - $down_border)/ ($luukcounter + (($#key_order + 1) * $luukcounter));
366
# can set $step to get nice graphs ... and change the format ...
367
$step = 8; # set hard the step value
369
$gifavg = ($giftotal/$gifcount);
370
$highest = 2 * $gifavg;
371
$highest = 1; # set hard the highest value ...
372
$xhigh = int($highest + .5 * $highest);
374
# here to get the max lenght of the test entries ...
375
# so we can calculate the with of the left border
376
foreach $oper (sort keys (%op)) {
377
$max_len_lb = length($oper) if (length($oper) > $max_len_lb);
378
# print "oper = $oper - $max_len_lb\n";
380
$max_len_lb = $max_len_lb * gdSmallFont->width;
381
$left_border = (3*$sm_border) + $max_len_lb;
382
$down_border = (4*$sm_border) + (gdSmallFont->width*(length($xhigh)+3)) + (gdSmallFont->height *2);
383
$right_border = (3*$sm_border) + 3 + (gdSmallFont->width*(length($highest)+5));
385
# calculate the space for the legend .....
386
foreach $key (@key_order) {
388
$tmp =~ s/-cmp-$opt_cmp//i;
389
$giflegend = sprintf "%-24.24s: %-40.40s",$tmp,$tot{$key}{'server'};
390
$max_len_le = length($giflegend) if (length($giflegend) > $max_len_le);
392
$max_len_le = $max_len_le * gdSmallFont->width;
393
$legend_block = 10; # the length of the block in the legend
394
$max_high_le = (($#key_order + 1)*(gdSmallFont->height+2)) + (2*$legend_block);
395
$down_border += $max_high_le;
396
$up_border = (5 * $sm_border) + gdSmallFont->height + gdLargeFont->height;
398
print "Here some things we already know ....\n";
399
# print "luukcounter = $luukcounter (number of tests)\n";
400
# print "gifcount = $gifcount (number of total entries)\n";
401
# print "giftotal = $giftotal (total secs)\n";
402
# print "gifavg = $gifavg\n";
403
# print "highest = $highest\n";
404
# print "xhigh = $xhigh\n";
405
# print "step = $step -- $#key_order\n";
406
# print "max_len_lb = $max_len_lb\n";
407
# printf "Small- width %d - height %s\n",gdSmallFont->width,gdSmallFont->height;
408
# printf "Tiny- width %d - height %s\n",gdTinyFont->width,gdTinyFont->height;
413
$width = 600; # the width ....
414
$height = 500; # the height ...
415
$width_greyfield = 430;
416
# when $step is set ... count the height ....????
417
$width = $width_greyfield + $left_border + $right_border;
418
$height = ($step * ($luukcounter + ($luukcounter * ($#key_order + 1)))) + $down_border + $up_border;
419
$b_width = $width - ($left_border + $right_border); # width within the grey field
420
$overlap = 0; # how far each colum can fall over each other ...nice :-)
422
# make the gif image ....
423
$im = new GD::Image($width,$height);
425
# allocate the colors to use ...
426
$white = $im->colorAllocate(255,255,255);
427
$black = $im->colorAllocate(0,0,0);
428
$paper_white = $im->colorAllocate(220, 220, 220);
429
$grey1 = $im->colorAllocate(240, 240, 240);
430
$grey4 = $im->colorAllocate(229, 229, 229);
431
$grey2 = $im->colorAllocate(102, 102, 102);
432
$grey3 = $im->colorAllocate(153, 153, 153);
434
$red = $im->colorAllocate(205,0,0); # msql
435
$lred = $im->colorAllocate(255,0,0);
436
$blue = $im->colorAllocate(0,0,205); # mysql
437
$lblue = $im->colorAllocate(0,0,255); # mysql_pgcc
438
$green = $im->colorAllocate(0, 205, 0); # postgres
439
$lgreen = $im->colorAllocate(0, 255, 0); # pg_fast
440
$orange = $im->colorAllocate(205,133, 0); # solid
441
$lorange = $im->colorAllocate(255, 165, 0); # Adabas
442
$yellow = $im->colorAllocate(205,205,0); # empress
443
$lyellow = $im->colorAllocate(255,255,0);
444
$magenta = $im->colorAllocate(255,0,255); # oracle
445
$lmagenta = $im->colorAllocate(255,200,255);
446
$cyan = $im->colorAllocate(0,205,205); # sybase
447
$lcyan = $im->colorAllocate(0,255,255);
448
$sienna = $im->colorAllocate(139,71,38); # db2
449
$lsienna = $im->colorAllocate(160,82,45);
450
$coral = $im->colorAllocate(205,91,69); # Informix
451
$lcoral = $im->colorAllocate(255,114,86);
452
$peach = $im->colorAllocate(205,175,149);
453
$lpeach = $im->colorAllocate(255,218,185);
455
@colors = ($red, $blue, $green, $orange, $yellow, $magenta, $cyan, $sienna, $coral, $peach);
456
@lcolors = ($lred, $lblue, $lgreen, $lorange, $lyellow, $lmagenta, $lcyan, $lsienna, $lcoral, $lpeach);
458
# set a color per server so in every result it has the same color ....
459
foreach $key (@key_order) {
460
if ($tot{$key}{'server'} =~ /mysql/i) {
461
if ($key =~ /mysql_pgcc/i || $key =~ /mysql_odbc/i || $key =~ /mysql_fast/i) {
462
$tot{$key}{'color'} = $lblue;
464
$tot{$key}{'color'} = $blue;
466
} elsif ($tot{$key}{'server'} =~ /msql/i) {
467
$tot{$key}{'color'} = $lred;
468
} elsif ($tot{$key}{'server'} =~ /postgres/i) {
469
if ($key =~ /pg_fast/i) {
470
$tot{$key}{'color'} = $lgreen;
472
$tot{$key}{'color'} = $green;
474
} elsif ($tot{$key}{'server'} =~ /solid/i) {
475
$tot{$key}{'color'} = $lorange;
476
} elsif ($tot{$key}{'server'} =~ /empress/i) {
477
$tot{$key}{'color'} = $lyellow;
478
} elsif ($tot{$key}{'server'} =~ /oracle/i) {
479
$tot{$key}{'color'} = $magenta;
480
} elsif ($tot{$key}{'server'} =~ /sybase/i) {
481
$tot{$key}{'color'} = $cyan;
482
} elsif ($tot{$key}{'server'} =~ /db2/i) {
483
$tot{$key}{'color'} = $sienna;
484
} elsif ($tot{$key}{'server'} =~ /informix/i) {
485
$tot{$key}{'color'} = $coral;
486
} elsif ($tot{$key}{'server'} =~ /microsoft/i) {
487
$tot{$key}{'color'} = $peach;
488
} elsif ($tot{$key}{'server'} =~ /access/i) {
489
$tot{$key}{'color'} = $lpeach;
490
} elsif ($tot{$key}{'server'} =~ /adabas/i) {
491
$tot{$key}{'color'} = $lorange;
495
# make the nice little borders
497
$poly0 = new GD::Polygon;
499
$poly0->addPt($sm_border,$sm_border);
500
$poly0->addPt($sm_border,($height - $sm_border));
501
$poly0->addPt(0,$height);
502
$im->filledPolygon($poly0,$grey1);
503
$im->polygon($poly0, $grey4);
505
$poly3 = new GD::Polygon;
507
$poly3->addPt($sm_border,$sm_border);
508
$poly3->addPt(($width - $sm_border),$sm_border);
509
$poly3->addPt($width,0);
510
$im->polygon($poly3, $grey4);
511
$tmptime = localtime(time);
512
$im->string(gdSmallFont,($width - $sm_border - (gdSmallFont->width * length($tmptime))),($height - ($sm_border) - gdSmallFont->height), $tmptime, $grey3);
515
$poly1 = new GD::Polygon;
516
$poly1->addPt($width,0);
517
$poly1->addPt(($width - $sm_border),$sm_border);
518
$poly1->addPt(($width - $sm_border),($height - $sm_border));
519
$poly1->addPt($width,$height);
520
$im->filledPolygon($poly1, $grey3);
521
$im->stringUp(gdSmallFont,($width - 10),($height - (2 * $sm_border)), "Made by Luuk de Boer - 1997 (c)", $blue);
523
$poly2 = new GD::Polygon;
524
$poly2->addPt(0,$height);
525
$poly2->addPt($sm_border,($height - $sm_border));
526
$poly2->addPt(($width - $sm_border),($height - $sm_border));
527
$poly2->addPt($width,$height);
528
$im->filledPolygon($poly2, $grey2);
530
# do the black line around where in you will print ... (must be done at last
531
# but is hard to develop with ... but the filled grey must be done first :-)
532
$im->filledRectangle($left_border,$up_border,($width - ($right_border)),($height-$down_border),$grey4);
535
# print the nice title ...
536
$titlebar = "MySQL Benchmark results"; # head title ...
537
$titlebar1 = "Compare $opt_cmp "; # sub title
538
$header2 = "seconds/test"; # header value
539
$center = ($width / 2) - ((gdLargeFont->width * length($titlebar)) / 2);
540
$center1 = ($width / 2) - ((gdSmallFont->width * length($titlebar1)) / 2);
541
$center2 = ($width_greyfield/2) - ((gdSmallFont->width*length($header2))/2);
542
$bovenkant = $sm_border * 3;
543
$bovenkant1 = $bovenkant + gdLargeFont->height + (.5*$sm_border);
544
$bovenkant2 = $height - $down_border + (1*$sm_border) + (gdSmallFont->width*(length($xhigh)+3));
545
$im->string(gdLargeFont,($center),($bovenkant + 1), $titlebar, $grey3);
546
$im->string(gdLargeFont,($center),($bovenkant), $titlebar, $red);
547
$im->string(gdSmallFont,($center1),($bovenkant1), $titlebar1, $black);
548
$im->string(gdSmallFont,($left_border + $center2),($bovenkant2), $header2, $black);
550
$xlength = $width - $left_border - $right_border;
551
$lines = 10; # hard coded number of dashed lines
552
$xverh = $xlength / $xhigh;
553
# print " de verhouding ===> $xverh --- $xlength -- $xhigh \n";
555
$xstep = ($xhigh / $lines) * $xverh;
557
# make the nice dashed lines and print the values ...
558
for ($i = 0; $i <= $lines; $i++) {
559
$st2 = ($left_border) + ($i * $xstep);
560
$im->dashedLine($st2,($height-$down_border),$st2,($up_border), $grey3);
561
if (($i != 0) && ($teller == 2)) {
562
$st3 = sprintf("%.2f", $i*($xhigh/$lines));
563
$im->stringUp(gdTinyFont,($st2 - (gdSmallFont->height/2)),($height - $down_border +(.5*$sm_border) + (gdSmallFont->width*(length($xhigh)+3))), $st3, $black);
568
$im->rectangle($left_border,$up_border,($width - ($right_border)),($height-$down_border),$black);
572
# make the legend ...
573
$legxbegin = $left_border;
575
$legybegin = $height - $down_border + (2*$sm_border) + (gdSmallFont->width * (length($xhigh) + 3)) + gdSmallFont->height;
576
$legxend = $legxbegin + $max_len_le + (4*$legend_block);
577
$legxend = $legxbegin + $width_greyfield;
578
$legyend = $legybegin + $max_high_le;
579
$im->filledRectangle($legxbegin,$legybegin,$legxend,$legyend,$grey4);
580
$im->rectangle($legxbegin,$legybegin,$legxend,$legyend,$black);
581
# calculate the space for the legend .....
583
$legybegin += $legend_block;
584
foreach $key (@key_order) {
585
$xtmp = $legxbegin + $legend_block;
586
$ytmp = $legybegin + ($c * (gdSmallFont->height +2));
587
$xtmp1 = $xtmp + $legend_block;
588
$ytmp1 = $ytmp + gdSmallFont->height;
589
$im->filledRectangle($xtmp,$ytmp,$xtmp1,$ytmp1,$tot{$key}{'color'});
590
$im->rectangle($xtmp,$ytmp,$xtmp1,$ytmp1,$black);
592
$tmp =~ s/-cmp-$opt_cmp//i;
593
$giflegend = sprintf "%-24.24s: %-40.40s",$tmp,$tot{$key}{'server'};
594
$xtmp2 = $xtmp1 + $legend_block;
595
$im->string(gdSmallFont,$xtmp2,$ytmp,"$giflegend",$black);
598
# print "$c $i -> $giflegend\n";
607
$ybegin = $up_border + ((($#key_order + 2)/2)*$step);
608
$xbegin = $left_border;
609
foreach $key (sort {$a cmp $b} keys %op) {
610
next if ($key =~ /TOTALS/i);
612
# print "key - $key\n";
613
foreach $server (@key_order) {
614
$tot1{$server}{$key}->[1] = 1 if ($tot1{$server}{$key}->[1] == 0);
615
$entry = $tot1{$server}{$key}->[0]/$tot1{$server}{$key}->[1];
616
$ytmp = $ybegin + ($i * $step) ;
617
$xtmp = $xbegin + ($entry * $xverh) ;
618
$ytmp1 = $ytmp + $step;
619
# print "$server -- $entry --x $xtmp -- y $ytmp - $c\n";
620
$entry1 = sprintf("%.2f", $entry);
621
if ($entry < $xhigh) {
622
$im->filledRectangle($xbegin, $ytmp, $xtmp, $ytmp1, $tot{$server}{'color'});
623
$im->rectangle($xbegin, $ytmp, $xtmp, $ytmp1, $black);
624
# print the seconds behind the bar (look below for another entry)
625
# this entry is for the bars that are not greater then the max width
626
# of the grey field ...
627
# $im->string(gdTinyFont,(($xtmp+3),($ytmp),"$entry1",$black));
628
# if you want the seconds in the color of the bar just uncomment it (below)
629
# $im->string(gdTinyFont,(($xtmp+3),($ytmp),"$entry1",$tot{$server}{'color'}));
631
$im->filledRectangle($xbegin, $ytmp, ($xbegin + ($xhigh*$xverh)), $ytmp1, $tot{$server}{'color'});
632
$im->rectangle($xbegin, $ytmp, ($xbegin + ($xhigh*$xverh)), $ytmp1, $black);
634
# print the seconds behind the bar (look below for another entry)
635
# here is the seconds printed behind the bar is the bar is too big for
636
# the graph ... (seconds is greater then xhigh ...)
637
$im->string(gdTinyFont, ($xbegin + ($xhigh*$xverh)+3),($ytmp),"$entry1",$black);
638
# if you want the seconds in the color of the bar just uncomment it (below)
639
# $im->string(gdTinyFont, ($xbegin + ($xhigh*$xverh)+3),($ytmp),"$entry1",$colors[$c]);
644
# see if we can center the text between the bars ...
645
$ytmp2 = $ytmp1 - (((($c)*$step) + gdSmallFont->height)/2);
646
$im->string(gdSmallFont,($sm_border*2),$ytmp2,$key, $black);
654
$name_gif = $name . ".gif";
655
print "name --> $name_gif\n";
656
open (GIF, "> $name_gif") || die "Can't open $name_gif: $!\n";