#!/usr/bin/perl -w
use strict;
use GD::Graph::hbars;
my @empty = ();
my @labels_cpu = ();
my @Integer = ();
my @Float = ();
my @labels_video = ();
my @cpu = ();
my @Rectangle = ();
my @Text = ();
my @Ellipse = ();
my @BitBlt = ();
my @labels_hdd = ();
my @bus = ();
my @Read = ();
my @Write = ();
my @RRead = ();
my @RWrite = ();
plot_graph( 'mycpu.gif', 'mycpu.txt',
[(\@labels_cpu, \@Integer, \@Float, \@empty, \@empty, \@empty)],
[( 'Integer','Float' )],
\&rule_cpu );
plot_graph( 'myvideo.gif', 'myvideo.txt',
[(\@labels_video, \@Rectangle, \@Text, \@Ellipse, \@BitBlt, \@empty)],
[( 'Rectangle', 'Text', 'Ellipse', 'BitBlt' )],
\&rule_video );
plot_graph( 'myhdd.gif', 'C:\\home\\hdbench\\myhdd.txt',
[(\@labels_hdd, \@Read, \@Write, \@RRead, \@RWrite, \@empty)],
[( 'Read', 'Write', 'Randome Read', 'Randome Write' )],
\&rule_hdd );
sub plot_graph
{
my $outfile = shift;
my $infile = shift;
my $data = shift;
my $legend = shift;
my $rule = shift;
my $pt = 100;
my $margin = 3;
my $ent = 0;
open my $rfh, '<' , $infile or die "$!: $outfile";
my @lines = <$rfh>;
@lines = map { chomp; $_ } @lines;
while ( @lines )
{
$ent ++;
&$rule( \@lines );
}
close $rfh;
my $graph = GD::Graph::hbars->new( 800 , 64 + $pt / 12 * $ent )
or die GD::Graph::Data->error;
$graph->set(
title => "$infile",
y_label => 'point',
cumulate => 1,
bar_spacing => 2,
x_labels_vertical => 0,
y_long_ticks => 1,
l_margin => $margin, b_margin => $margin,
r_margin => $margin, t_margin => $margin,
);
$graph->set_legend( @$legend );
my $image = $graph->plot( \@$data )
or die $graph->error;
open my $wfh, '>', $outfile or die "$!: $outfile";
binmode $wfh;
print $wfh $image->gif();
close $wfh;
}
sub rule_cpu
{
my $ref = shift;
push @labels_cpu, shift @$ref;
push @Integer, shift @$ref;
push @Float, shift @$ref;
}
sub rule_video
{
my $ref = shift;
push @labels_video, shift @$ref;
push @cpu, shift @$ref;
push @Rectangle, shift @$ref;
push @Text, shift @$ref;
push @Ellipse, shift @$ref;
push @BitBlt, shift @$ref;
}
sub rule_hdd{
my $ref = shift;
push @labels_hdd, shift @$ref;
push @bus, shift @$ref;
push @Read, shift @$ref;
push @Write, shift @$ref;
push @RRead, shift @$ref;
push @RWrite, shift @$ref;
}