1#!/usr/bin/env perl
2####
3#### Hello ... this is a heavily hacked script by Luuk
4#### instead of printing the result it makes a nice gif
5#### when you want to look at the code ... beware of the
6#### ugliest code ever seen .... but it works ...
7#### and that's sometimes the only thing you want ... isn't it ...
8#### as the original script ... Hope you like it
9####
10#### Greetz..... Luuk de Boer 1997.
11####
12
13## if you want the seconds behind the bar printed or not ...
14## or only the one where the bar is too big for the graph ...
15## look at line 535 of this program and below ...
16## look in sub calculate for allmost all hard/soft settings :-)
17
18# a little program to generate a table of results
19# just read all the RUN-*.log files and format them nicely
20# Made by Luuk de Boer
21# Patched by Monty
22
23use Getopt::Long;
24use GD;
25
26$opt_server="mysql";
27$opt_cmp="mysql,pg,solid";
28$opt_cmp="msql,mysql,pg,solid";
29$opt_cmp="empress,mysql,pg,solid";
30$opt_dir="output";
31$opt_machine="";
32$opt_relative=$opt_same_server=$opt_help=$opt_Information=$opt_skip_count=0;
33
34GetOptions("Information","help","server=s","cmp=s","machine=s","relative","same-server","dir=s","skip-count") || usage();
35
36usage() if ($opt_help || $opt_Information);
37
38if ($opt_same_server)
39{
40  $files="$opt_dir/RUN-$opt_server-*$opt_machine";
41}
42else
43{
44  $files="$opt_dir/RUN-*$opt_machine";
45}
46$files.= "-cmp-$opt_cmp" if (length($opt_cmp));
47
48$automatic_files=0;
49if ($#ARGV == -1)
50{
51  @ARGV=glob($files);
52  $automatic_files=1;
53}
54
55
56#
57# Go trough all RUN files and gather statistics.
58#
59
60foreach (@ARGV)
61{
62  $filename = $_;
63  next if (defined($found{$_})); # remove duplicates
64  $found{$_}=1;
65  /RUN-(.*)$/;
66  $prog = $1;
67  push(@key_order,$prog);
68  $next = 0;
69  open(TMP, "<$filename") || die "Can't open $filename: $!\n";
70  while (<TMP>)
71  {
72    chomp;
73    if ($next == 0) {
74      if (/Server version:\s+(\S+.*)/i)
75      {
76	$tot{$prog}{'server'} = $1;
77      }
78      elsif (/Arguments:\s+(.+)/i)
79      {
80	$tot{$prog}{'arguments'} = $1;
81	# Remove some standard, not informative arguments
82	$tot{$prog}{'arguments'} =~ s/--log|--use-old-results|--server=\S+|--cmp=\S+|--user=\S+|--pass=\S+|--machine=\S+//g;
83	$tot{$prog}{'arguments'} =~ s/\s+/ /g;
84      }
85      elsif (/Comments:\s+(.+)/i) {
86	$tot{$prog}{'comments'} = $1;
87      } elsif (/^(\S+):\s*(estimated\s|)total\stime:\s+(\d+)\s+secs/i)
88      {
89	$tmp = $1; $tmp =~ s/://;
90	$tot{$prog}{$tmp} = [ $3, (length($2) ? "+" : "")];
91	$op1{$tmp} = $tmp;
92      } elsif (/Totals per operation:/i) {
93	$next = 1;
94	next;
95      }
96    }
97    elsif ($next == 1)
98    {
99      if (/^(\S+)\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)\s*([+|?])*/)
100      {
101	$tot1{$prog}{$1} = [$2,$6,$7];
102	$op{$1} = $1;
103#print "TEST - $_ \n * $prog - $1 - $2 - $6 - $7 ****\n";
104# $prog - filename
105# $1 - operation
106# $2 - time in secs
107# $6 - number of loops
108# $7 - nothing / + / ? / * => estimated time ...
109      # get the highest value ....
110      $highest = ($2/$6) if (($highest < ($2/$6)) && ($1 !~/TOTALS/i));
111      $gifcount++;
112      $giftotal += ($2/$6);
113      }
114    }
115  }
116}
117
118if (!%op)
119{
120  print "Didn't find any files matching: '$files'\n";
121  print "Use the --cmp=server,server option to compare benchmarks\n";
122  exit 1;
123}
124
125
126# everything is loaded ...
127# now we have to create a fancy output :-)
128
129# I prefer to redirect scripts instead to force it to file ; Monty
130#
131# open(RES, ">$resultfile") || die "Can't write to $resultfile: $!\n";
132# select(RES)
133#
134
135#print <<EOF;
136#<cut for this moment>
137#
138#EOF
139
140if ($opt_relative)
141{
142#  print "Column 1 is in seconds. All other columns are presented relative\n";
143#  print "to this. 1.00 is the same, bigger numbers indicates slower\n\n";
144}
145
146#print "The result logs which where found and the options:\n";
147
148if ($automatic_files)
149{
150  if ($key_order[$i] =~ /^$opt_server/)
151  {
152    if ($key_order[$i] =~ /^$opt_server/)
153    {
154      unshift(@key_order,$key_order[$i]);
155      splice(@key_order,$i+1,1);
156    }
157  }
158}
159# extra for mysql and mysql_pgcc
160#$number1 = shift(@key_order);
161#$number2 = shift(@key_order);
162#unshift(@key_order,$number1);
163#unshift(@key_order,$number2);
164
165# Print header
166
167$column_count=0;
168foreach $key (@key_order)
169{
170  $column_count++;
171#  printf "%2d %-40.40s: %s %s\n", $column_count, $key,
172#  $tot{$key}{'server'}, $tot{$key}{'arguments'};
173#  print "Comments: $tot{$key}{'comments'}\n"
174#    if ($tot{$key}{'comments'} =~ /\w+/);
175}
176
177#print "\n";
178
179$namewidth=$opt_skip_count ? 20 :25;
180$colwidth= $opt_relative ? 9 : 6;
181
182print_sep("=");
183#printf "%-$namewidth.${namewidth}s|", "Operation";
184$count = 1;
185foreach $key (@key_order)
186{
187#  printf "%${colwidth}d|", $count;
188  $count++;
189}
190#print "\n";
191#print_sep("-");
192#print_string("Results per test:");
193#print_sep("-");
194
195foreach $key (sort {$a cmp $b} keys %op1)
196{
197#  printf "%-$namewidth.${namewidth}s|", $key;
198  $first=undef();
199  foreach $server (@key_order)
200  {
201    print_value($first,$tot{$server}{$key}->[0],$tot{$server}{$key}->[1]);
202    $first=$tot{$server}{$key}->[0] if (!defined($first));
203  }
204#  print "\n";
205}
206
207print_sep("-");
208print_string("The results per operation:");
209print_sep("-");
210$luukcounter = 1;
211foreach $key (sort {$a cmp $b} keys %op)
212{
213  next if ($key =~ /TOTALS/i);
214  $tmp=$key;
215  $tmp.= " (" . $tot1{$key_order[0]}{$key}->[1] . ")" if (!$skip_count);
216#  printf "%-$namewidth.${namewidth}s|", $tmp;
217  $first=undef();
218  foreach $server (@key_order)
219  {
220    print_value($first,$tot1{$server}{$key}->[0],$tot1{$server}{$key}->[2]);
221    $first=$tot1{$server}{$key}->[0] if (!defined($first));
222  }
223#  print "\n";
224  $luukcounter++;
225}
226
227#print_sep("-");
228$key="TOTALS";
229#printf "%-$namewidth.${namewidth}s|", $key;
230$first=undef();
231foreach $server (@key_order)
232{
233#  print_value($first,$tot1{$server}{$key}->[0],$tot1{$server}{$key}->[2]);
234  $first=$tot1{$server}{$key}->[0] if (!defined($first));
235}
236#print "\n";
237#print_sep("=");
238&make_gif;
239
240exit 0;
241
242#
243# some format functions;
244#
245
246sub print_sep
247{
248  my ($sep)=@_;
249#  print $sep x ($namewidth + (($colwidth+1) * $column_count)+1),"\n";
250}
251
252
253sub print_value
254{
255  my ($first,$value,$flags)=@_;
256  my ($tmp);
257
258  if (defined($value))
259  {
260    if (!defined($first) || !$opt_relative)
261    {
262      $tmp=sprintf("%d",$value);
263    }
264    else
265    {
266      $first=1 if (!$first);	# Assume that it took one second instead of 0
267      $tmp= sprintf("%.2f",$value/$first);
268    }
269    if (defined($flags))
270    {
271      $tmp="+".$tmp if ($flags =~ /\+/);
272      $tmp="?".$tmp if ($flags =~ /\?/);
273    }
274  }
275  else
276  {
277    $tmp="";
278  }
279  $tmp= " " x ($colwidth-length($tmp)) . $tmp if (length($tmp) < $colwidth);
280#  print $tmp . "|";
281}
282
283
284sub print_string
285{
286  my ($str)=@_;
287  my ($width);
288  $width=$namewidth + ($colwidth+1)*$column_count;
289
290  $str=substr($str,1,$width) if (length($str) > $width);
291#  print($str," " x ($width - length($str)),"|\n");
292}
293
294sub usage
295{
296  exit(0);
297}
298
299
300
301###########################################
302###########################################
303###########################################
304# making here a gif of the results ... (lets try it :-))
305# luuk .... 1997
306###########################################
307## take care that $highest / $giftotal / $gifcount / $luukcounter
308## are getting there value above ... so don't forget them while
309## copying the code to some other program ....
310
311sub make_gif {
312  &gd; # some base things ....
313  &legend; # make the nice legend
314  &lines; # yep sometimes you have to print some lines
315  &gif("gif/benchmark2-".$opt_cmp); # and finally we can print all to a gif file ...
316}
317##### mmm we are finished now ...
318
319
320# first we have to calculate some limits and some other stuff
321sub calculate {
322# here is the list which I have to know to make everything .....
323# the small border width ... 					$sm_border =
324# the border default						$border =
325# the step default ... if it must be calculated then no value	$step =
326# the highest number						$highest =
327# the max length of the text of the x borders			$max_len_lb=
328# the max length of a legend entry				$max_len_le=
329# number of entries in the legend				$num_legen =
330# the length of the color blocks for the legend			$legend_block=
331# the width of the gif ...if it must be calculated - no value   $width =
332# the height of the gif .. if it must be calculated - no value	$height =
333# the width of the grey field ' 	'	'	'	$width_grey=
334# the height of the grey field '	'	'	'	$height_grey=
335# number of dashed lines					$lines=
336# if bars must overlap how much they must be overlapped		$overlap=
337# titlebar title of graph in two colors big			$titlebar=
338# titlebar1 sub title of graph in small font in black		$titlebar1=
339# xlabel							$xlabel=
340# ylabel							$ylabel=
341# the name of the gif ...					$name=
342# then the following things must be knows .....
343# xlabel below or on the left side ?
344# legend yes/no?
345# where must the legend be placed?
346# must the xlabel be printed horizontal or vertical?
347# must the ylabel be printed horizontal or vertical?
348# must the graph be a line or a bar graph?
349# is a xlabel several different entries or some sub entries of one?
350#    so xlabel 1 => test1=10, test2=15, test3=7 etc
351#    or xlabel 1 => test1a=12, test1b=10, test1c=7 etc
352# must the bars overlap (only with the second example I think)
353# must the number be printed above or next to the bar?
354# when must the number be printed .... only when it extends the graph ...???
355# the space between the bars .... are that the same width of the bars ...
356#    or is it a separate space ... defined ???
357# must the date printed below or some where else ....
358
359#calculate all space for text and other things ....
360  $sm_border = 8; # the grey border around ...
361  $border = 40; #default ...
362  $left_border = 2.75 * $border; #default ...
363  $right_border = $border; #default ...
364  $up_border = $border; #default ...
365  $down_border = $border; # default ...
366  $step = ($height - $up_border - $down_border)/ ($luukcounter + (($#key_order + 1) * $luukcounter));
367  # can set $step to get nice graphs ... and change the format ...
368  $step = 8; # set hard the step value
369
370  $gifavg = ($giftotal/$gifcount);
371  $highest = 2 * $gifavg;
372  $highest = 1; # set hard the highest value ...
373  $xhigh = int($highest + .5 * $highest);
374
375  # here to get the max lenght of the test entries ...
376  # so we can calculate the with of the left border
377  foreach $oper (sort keys (%op)) {
378    $max_len_lb = length($oper) if (length($oper) > $max_len_lb);
379#    print "oper = $oper - $max_len_lb\n";
380  }
381  $max_len_lb = $max_len_lb * gdSmallFont->width;
382  $left_border = (3*$sm_border) + $max_len_lb;
383  $down_border = (4*$sm_border) + (gdSmallFont->width*(length($xhigh)+3)) + (gdSmallFont->height *2);
384  $right_border = (3*$sm_border) + 3 + (gdSmallFont->width*(length($highest)+5));
385
386  # calculate the space for the legend .....
387  foreach $key (@key_order) {
388    $tmp = $key;
389    $tmp =~ s/-cmp-$opt_cmp//i;
390    $giflegend = sprintf "%-24.24s: %-40.40s",$tmp,$tot{$key}{'server'};
391    $max_len_le = length($giflegend) if (length($giflegend) > $max_len_le);
392  }
393  $max_len_le = $max_len_le * gdSmallFont->width;
394  $legend_block = 10; # the length of the block in the legend
395  $max_high_le = (($#key_order + 1)*(gdSmallFont->height+2)) + (2*$legend_block);
396  $down_border += $max_high_le;
397  $up_border = (5 * $sm_border) + gdSmallFont->height + gdLargeFont->height;
398
399  print "Here some things we already know ....\n";
400#  print "luukcounter = $luukcounter (number of tests)\n";
401#  print "gifcount = $gifcount (number of total entries)\n";
402#  print "giftotal = $giftotal (total secs)\n";
403#  print "gifavg = $gifavg\n";
404#  print "highest = $highest\n";
405#  print "xhigh = $xhigh\n";
406#  print "step = $step -- $#key_order\n";
407#  print "max_len_lb = $max_len_lb\n";
408#  printf "Small- width %d - height %s\n",gdSmallFont->width,gdSmallFont->height;
409#  printf "Tiny- width %d - height %s\n",gdTinyFont->width,gdTinyFont->height;
410}
411
412sub gd {
413  &calculate;
414  $width = 600; # the width ....
415  $height = 500; # the height ...
416  $width_greyfield = 430;
417  # when $step is set ... count the height ....????
418  $width = $width_greyfield + $left_border + $right_border;
419  $height = ($step * ($luukcounter + ($luukcounter * ($#key_order + 1)))) + $down_border + $up_border;
420  $b_width = $width - ($left_border + $right_border); # width within the grey field
421  $overlap = 0; # how far each colum can fall over each other ...nice :-)
422
423  # make the gif image ....
424  $im = new GD::Image($width,$height);
425
426  # allocate the colors to use ...
427  $white 		= $im->colorAllocate(255,255,255);
428  $black 		= $im->colorAllocate(0,0,0);
429  $paper_white 		= $im->colorAllocate(220, 220, 220);
430  $grey1 		= $im->colorAllocate(240, 240, 240);
431  $grey4 		= $im->colorAllocate(229, 229, 229);
432  $grey2 		= $im->colorAllocate(102, 102, 102);
433  $grey3 		= $im->colorAllocate(153, 153, 153);
434
435  $red 			= $im->colorAllocate(205,0,0); # msql
436  $lred 		= $im->colorAllocate(255,0,0);
437  $blue 		= $im->colorAllocate(0,0,205); # mysql
438  $lblue 		= $im->colorAllocate(0,0,255); # mysql_pgcc
439  $green 		= $im->colorAllocate(0, 205, 0); # postgres
440  $lgreen 		= $im->colorAllocate(0, 255, 0); # pg_fast
441  $orange 		= $im->colorAllocate(205,133, 0); # solid
442  $lorange 		= $im->colorAllocate(255, 165, 0); # Adabas
443  $yellow 		= $im->colorAllocate(205,205,0);  # empress
444  $lyellow 		= $im->colorAllocate(255,255,0);
445  $magenta 		= $im->colorAllocate(255,0,255); # oracle
446  $lmagenta 		= $im->colorAllocate(255,200,255);
447  $cyan 		= $im->colorAllocate(0,205,205); # sybase
448  $lcyan 		= $im->colorAllocate(0,255,255);
449  $sienna 		= $im->colorAllocate(139,71,38); # db2
450  $lsienna 		= $im->colorAllocate(160,82,45);
451  $coral 		= $im->colorAllocate(205,91,69); # Informix
452  $lcoral 		= $im->colorAllocate(255,114,86);
453  $peach		= $im->colorAllocate(205,175,149);
454  $lpeach		= $im->colorAllocate(255,218,185);
455
456  @colors = ($red, $blue, $green, $orange, $yellow, $magenta, $cyan, $sienna, $coral, $peach);
457  @lcolors = ($lred, $lblue, $lgreen, $lorange, $lyellow, $lmagenta, $lcyan, $lsienna, $lcoral, $lpeach);
458
459  # set a color per server so in every result it has the same color ....
460  foreach $key (@key_order) {
461    if ($tot{$key}{'server'} =~ /mysql/i) {
462      if ($key =~ /mysql_pgcc/i || $key =~ /mysql_odbc/i || $key =~ /mysql_fast/i) {
463        $tot{$key}{'color'} = $lblue;
464      } else {
465        $tot{$key}{'color'} = $blue;
466      }
467    } elsif ($tot{$key}{'server'} =~ /msql/i) {
468      $tot{$key}{'color'} = $lred;
469    } elsif ($tot{$key}{'server'} =~ /postgres/i) {
470      if ($key =~ /pg_fast/i) {
471        $tot{$key}{'color'} = $lgreen;
472      } else {
473        $tot{$key}{'color'} = $green;
474      }
475    } elsif ($tot{$key}{'server'} =~ /solid/i) {
476      $tot{$key}{'color'} = $lorange;
477    } elsif ($tot{$key}{'server'} =~ /empress/i) {
478      $tot{$key}{'color'} = $lyellow;
479    } elsif ($tot{$key}{'server'} =~ /oracle/i) {
480      $tot{$key}{'color'} = $magenta;
481    } elsif ($tot{$key}{'server'} =~ /sybase/i) {
482      $tot{$key}{'color'} = $cyan;
483    } elsif ($tot{$key}{'server'} =~ /db2/i) {
484      $tot{$key}{'color'} = $sienna;
485    } elsif ($tot{$key}{'server'} =~ /informix/i) {
486      $tot{$key}{'color'} = $coral;
487    } elsif ($tot{$key}{'server'} =~ /microsoft/i) {
488      $tot{$key}{'color'} = $peach;
489    } elsif ($tot{$key}{'server'} =~ /access/i) {
490      $tot{$key}{'color'} = $lpeach;
491    } elsif ($tot{$key}{'server'} =~ /adabas/i) {
492      $tot{$key}{'color'} = $lorange;
493    }
494  }
495
496  # make the nice little borders
497  # left bar
498  $poly0 = new GD::Polygon;
499  $poly0->addPt(0,0);
500  $poly0->addPt($sm_border,$sm_border);
501  $poly0->addPt($sm_border,($height - $sm_border));
502  $poly0->addPt(0,$height);
503  $im->filledPolygon($poly0,$grey1);
504  $im->polygon($poly0, $grey4);
505  # upper bar
506  $poly3 = new GD::Polygon;
507  $poly3->addPt(0,0);
508  $poly3->addPt($sm_border,$sm_border);
509  $poly3->addPt(($width - $sm_border),$sm_border);
510  $poly3->addPt($width,0);
511  $im->polygon($poly3, $grey4);
512  $tmptime = localtime(time);
513  $im->string(gdSmallFont,($width - $sm_border - (gdSmallFont->width * length($tmptime))),($height - ($sm_border) - gdSmallFont->height), $tmptime, $grey3);
514
515  # right bar
516  $poly1 = new GD::Polygon;
517  $poly1->addPt($width,0);
518  $poly1->addPt(($width - $sm_border),$sm_border);
519  $poly1->addPt(($width - $sm_border),($height - $sm_border));
520  $poly1->addPt($width,$height);
521  $im->filledPolygon($poly1, $grey3);
522  $im->stringUp(gdSmallFont,($width - 10),($height - (2 * $sm_border)), "Made by Luuk de Boer - 1997 (c)", $blue);
523  #below bar
524  $poly2 = new GD::Polygon;
525  $poly2->addPt(0,$height);
526  $poly2->addPt($sm_border,($height - $sm_border));
527  $poly2->addPt(($width - $sm_border),($height - $sm_border));
528  $poly2->addPt($width,$height);
529  $im->filledPolygon($poly2, $grey2);
530
531  # do the black line around where in you will print ... (must be done at last
532  # but is hard to develop with ... but the filled grey must be done first :-)
533  $im->filledRectangle($left_border,$up_border,($width - ($right_border)),($height-$down_border),$grey4);
534
535
536  # print the nice title ...
537  $titlebar = "MySQL Benchmark results"; # head title ...
538  $titlebar1 = "Compare $opt_cmp "; # sub title
539  $header2 = "seconds/test"; # header value
540  $center = ($width / 2) - ((gdLargeFont->width * length($titlebar)) / 2);
541  $center1 = ($width / 2) - ((gdSmallFont->width * length($titlebar1)) / 2);
542  $center2 = ($width_greyfield/2) - ((gdSmallFont->width*length($header2))/2);
543  $bovenkant = $sm_border * 3;
544  $bovenkant1 = $bovenkant + gdLargeFont->height + (.5*$sm_border);
545  $bovenkant2 = $height - $down_border + (1*$sm_border) + (gdSmallFont->width*(length($xhigh)+3));
546  $im->string(gdLargeFont,($center),($bovenkant + 1), $titlebar, $grey3);
547  $im->string(gdLargeFont,($center),($bovenkant), $titlebar, $red);
548  $im->string(gdSmallFont,($center1),($bovenkant1), $titlebar1, $black);
549  $im->string(gdSmallFont,($left_border + $center2),($bovenkant2), $header2, $black);
550
551  $xlength = $width - $left_border - $right_border;
552  $lines = 10; # hard coded number of dashed lines
553  $xverh = $xlength / $xhigh;
554#  print " de verhouding ===> $xverh --- $xlength -- $xhigh \n";
555
556  $xstep = ($xhigh / $lines) * $xverh;
557  $teller = 0;
558  # make the nice dashed lines and print the values ...
559  for ($i = 0; $i <= $lines; $i++) {
560    $st2 = ($left_border) + ($i * $xstep);
561    $im->dashedLine($st2,($height-$down_border),$st2,($up_border), $grey3);
562    if (($i != 0) && ($teller == 2)) {
563      $st3 = sprintf("%.2f", $i*($xhigh/$lines));
564      $im->stringUp(gdTinyFont,($st2 - (gdSmallFont->height/2)),($height - $down_border +(.5*$sm_border) + (gdSmallFont->width*(length($xhigh)+3))), $st3, $black);
565      $teller = 0;
566    }
567    $teller++;
568  }
569  $im->rectangle($left_border,$up_border,($width - ($right_border)),($height-$down_border),$black);
570}
571
572sub legend {
573  # make the legend ...
574  $legxbegin = $left_border;
575
576  $legybegin = $height - $down_border + (2*$sm_border) + (gdSmallFont->width * (length($xhigh) + 3)) + gdSmallFont->height;
577  $legxend = $legxbegin + $max_len_le + (4*$legend_block);
578  $legxend = $legxbegin + $width_greyfield;
579  $legyend = $legybegin + $max_high_le;
580  $im->filledRectangle($legxbegin,$legybegin,$legxend,$legyend,$grey4);
581  $im->rectangle($legxbegin,$legybegin,$legxend,$legyend,$black);
582  # calculate the space for the legend .....
583  $c = 0; $i = 1;
584  $legybegin += $legend_block;
585  foreach $key (@key_order) {
586    $xtmp = $legxbegin + $legend_block;
587    $ytmp = $legybegin + ($c * (gdSmallFont->height +2));
588    $xtmp1 = $xtmp + $legend_block;
589    $ytmp1 = $ytmp + gdSmallFont->height;
590    $im->filledRectangle($xtmp,$ytmp,$xtmp1,$ytmp1,$tot{$key}{'color'});
591    $im->rectangle($xtmp,$ytmp,$xtmp1,$ytmp1,$black);
592    $tmp = $key;
593    $tmp =~ s/-cmp-$opt_cmp//i;
594    $giflegend = sprintf "%-24.24s: %-40.40s",$tmp,$tot{$key}{'server'};
595    $xtmp2 = $xtmp1 + $legend_block;
596    $im->string(gdSmallFont,$xtmp2,$ytmp,"$giflegend",$black);
597    $c++;
598    $i++;
599#    print "$c $i -> $giflegend\n";
600  }
601
602}
603
604sub lines {
605
606  $g = 0;
607  $i = 0;
608  $ybegin = $up_border + ((($#key_order + 2)/2)*$step);
609  $xbegin = $left_border;
610  foreach $key (sort {$a cmp $b} keys %op) {
611    next if ($key =~ /TOTALS/i);
612    $c = 0;
613#    print "key - $key\n";
614    foreach $server (@key_order) {
615      $tot1{$server}{$key}->[1] = 1 if ($tot1{$server}{$key}->[1] == 0);
616      $entry = $tot1{$server}{$key}->[0]/$tot1{$server}{$key}->[1];
617      $ytmp = $ybegin + ($i * $step) ;
618      $xtmp = $xbegin + ($entry * $xverh) ;
619      $ytmp1 = $ytmp + $step;
620#      print "$server -- $entry --x $xtmp -- y $ytmp - $c\n";
621      $entry1 = sprintf("%.2f", $entry);
622      if ($entry < $xhigh) {
623        $im->filledRectangle($xbegin, $ytmp, $xtmp, $ytmp1, $tot{$server}{'color'});
624        $im->rectangle($xbegin, $ytmp, $xtmp, $ytmp1, $black);
625# print the seconds behind the bar (look below for another entry)
626# this entry is for the bars that are not greater then the max width
627# of the grey field ...
628#        $im->string(gdTinyFont,(($xtmp+3),($ytmp),"$entry1",$black));
629# if you want the seconds in the color of the bar just uncomment it (below)
630#        $im->string(gdTinyFont,(($xtmp+3),($ytmp),"$entry1",$tot{$server}{'color'}));
631      } else {
632        $im->filledRectangle($xbegin, $ytmp, ($xbegin + ($xhigh*$xverh)), $ytmp1, $tot{$server}{'color'});
633        $im->rectangle($xbegin, $ytmp, ($xbegin + ($xhigh*$xverh)), $ytmp1, $black);
634
635# print the seconds behind the bar (look below for another entry)
636# here is the seconds printed behind the bar is the bar is too big for
637# the graph ... (seconds is greater then xhigh ...)
638        $im->string(gdTinyFont, ($xbegin + ($xhigh*$xverh)+3),($ytmp),"$entry1",$black);
639# if you want the seconds in the color of the bar just uncomment it (below)
640#        $im->string(gdTinyFont, ($xbegin + ($xhigh*$xverh)+3),($ytmp),"$entry1",$colors[$c]);
641      }
642      $c++;
643      $i++;
644    }
645    # see if we can center the text between the bars ...
646    $ytmp2 = $ytmp1 - (((($c)*$step) + gdSmallFont->height)/2);
647    $im->string(gdSmallFont,($sm_border*2),$ytmp2,$key, $black);
648    $i++;
649  }
650}
651
652
653sub gif {
654  my ($name) = @_;
655  $name_gif = $name . ".gif";
656  print "name --> $name_gif\n";
657  open (GIF, "> $name_gif") || die "Can't open $name_gif: $!\n";
658  print GIF $im->gif;
659  close (GIF);
660}
661
662