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