Benchmark-Harness-Graph
view release on metacpan or search on metacpan
use strict;
use vars qw($VERSION); $VERSION = sprintf("%d.%02d", q$Revision: 1.2 $ =~ /(\d+)\.(\d+)/);
### ################################################################################################
sub new {
my $cls = shift;
my $self = {
'axislist' => []
# Defaults that will be overridden by parameters given to this new()
,'x_legend' => 'Time - mins', 'x_pixels' => 600, 'y_pixels' => 300
,'y1_legend' => 'Memory | MB', 'y1_min_value' => 0, 'y1_color' => '#ff0000'
,'y2_legend' => 'CPU | %', 'y2_max_value' => 0, 'y2_color' => '#00dd00'
};
my @positionalParameterNames = qw(source x_pixels y_pixels x_max_value y1_max_value y2_max_value);
for ( @_ ) {
if ( ref($_) eq 'HASH' ) {
for my $k ( keys %$_ ) {
$self->{$k} = $_->{$k};
}
} else {
$self->{shift @positionalParameterNames} = $_;
'x_label_skip' => 1,
'y1_label_skip' => 1,
'y2_label_skip' => 1,
'title' => undef,
'x_ticks' => 'true', 'x_tick_number' => 12,
'y1_ticks' => 'true', 'y1_tick_number' => 12,
'y2_ticks' => 'true', 'y2_tick_number' => 10,
'transparent' => 1, 'box_axis' => 0, 'line_width' => 2,
);
my @needsLegends = ( $x_axis, $y1_axis, $y2_axis ); # We'll build legends from this array later.
my @funcDataColors = ($y1_axis->{color}); # $graph->plot() needs this, below.
# Plot the function entries / exits
my @nullAxis; map { push @nullAxis, undef } @{$x_axis->{data}};
my $allAxis = [$x_axis->{data}, \@nullAxis];
for (my $axisIdx = 3; $axisIdx < $#{$axislist}; $axisIdx += 1 ) {
my $axis = $axislist->[$axisIdx];
push @needsLegends, $axis;
my $funcData = $axis->{data};
$self->{outFilename} = "$filnam.htm";
open HTM, ">$self->{outFilename}";
print HTM '<html><head>';
# Print any script (e.g., javascript) into the <head>
print HTM $self->htmlScript();
# Print any style (e.g., css) into the <head>
print HTM $self->htmlStyle();
print HTM '</head><body>';
# print <img> of the graph and the legends surrounding it.
print HTM $self->htmlGraph();
print HTM '<tr><td align=center colspan=5><iframe id=detailview src=benchmarkHarnessGraphNullFrame.htm frameborder=0 height=80 width=500></iframe></td></tr>';
print HTM <<EOT;
<tr><td colspan=5><table width=100% align=center>
<tr>
<td width=60%>Subroutine</td>
<td align=right width=10%>first</td>
<td align=right width=10%>last</td>
<td align=right width=10%>count</td>
for (my $axisIdx = 3; $axisIdx < $#{$axislist}; $axisIdx += 1 ) {
my $axis = $axislist->[$axisIdx];
my $color = $axis->{color} || 'black';
my $countEntry = $axis->{count_entry};
my $firstEntry = int($axis->{first_entry}+0.50);
my $lastEntry = int($axis->{last_entry}+0.50);
my $totalTime = int(($axis->{total_time}*100)+0.50)/100;
print HTM <<EOT;
<tr>
<td><font color='$color'><b>$axis->{legend}</b></font></td>
<td align=right>$firstEntry</td>
<td align=right>$lastEntry</td>
<td align=right>$countEntry</td>
<td align=right>$totalTime</td>
</tr>
EOT
}
print HTM '</table></td></tr></table>';
my $hotspotText = '';
$axis->{min_value} *= $norm;
$axis->{max_value} *= $norm;
}
### ################################################################################################
### Return the <div> representing what gets displayed by hotspot click.
### Put this in a display:none element so it shows only via <script> control.
sub hotspotText {
my ($self, $axislist, $idx) = @_;
return <<EOT;
<div id=hs_$idx style='position:absolute;display:none;top:0;left:0;'>$axislist->[$idx]->{legend}</div>
EOT
}
### ################################################################################################
### Take GD::Graph's hotspot output and project it to the smallest array.
sub collapseArea {
my $self = shift;
my $answer = [];
my $thisSpot = undef;
</script>
EOT
}
### ################################################################################################
### Return the entire <style> element to insert in the html <head>
sub htmlStyle {
<<EOT;
<style>
<!--
.x_legend {
font-weight: bold;
text-align: center;
}
.y1_legend {
font-weight: bold;
font-size: 12;
text-align: center;
vertical-align: middle;
text-color: green;
}
.y2_legend {
font-weight: bold;
font-size: 12;
text-align: center;
vertical-align: middle;
text-color: red;
}
-->
</style>
EOT
}
### ################################################################################################
### Return the entire <table> element, up to end of graph area, to insert in the html <body>
sub htmlGraph {
my $self = shift;
my ($href) = ($self->{graphFilename} =~ m{([^/]*)$});
my $x_legend = $self->{x_legend} || 'Time';
my $y1_legend = $self->{y1_legend} || 'Memory';
$y1_legend =~ s{(.)}{$1<br>}g;
my $y2_legend = $self->{y2_legend} || 'CPU';
$y2_legend =~ s{(.)}{$1<br>}g;
<<EOT;
<table width=700 align=center cellspacing=10>
<tr>
<td width=6% class=y1_legend><font color='$self->{y1_color}'>$y1_legend</font></td>
<td width=4%> </td>
<td align=center><img src="$href" USEMAP="#clientsidemap" border=0></td>
<td width=4%> </td>
<td width=6% class=y2_legend><font color='$self->{y2_color}'>$y2_legend</font></td>
</tr>
<tr><td colspan=3 class=x_legend>$x_legend</td></tr>
EOT
}
### ################################################################################################
### ################################################################################################
### ################################################################################################
package Benchmark::Harness::GraphLineData;
use strict;
### ################################################################################################
# new($legend, $color)
sub new {
return bless
{
'data' => $_[1]
,'legend' => $_[2]
,'color' => $_[3]
,'line_width' => defined($_[4])?$_[4]:1
}
}
### ################################################################################################
sub Max {
my ($data, $max) = ($_[0]->{data}, -999999999);
map { do {$max = ($max > $_)?$max:$_} if defined $_} @$data;
return $max;
eg/GraphIt.pl view on Meta::CPAN
my ($filename, $analysisType, $asSchema) =
( 't/benchmark.Trace.Graph.xml',
'Graph',
'Trace'
);
my $graphType = "Benchmark::Harness::$analysisType";
my $graph = new $graphType($filename, 700, 350,
{
'schema' => $asSchema
,'x_legend' => 'Time - secs', 'x_max_value' => 0.4
,'y1_legend' => 'Memory | MB', 'y1_max_value' => 40
,'y2_legend' => 'CPU | %', 'y2_max_value' => 100
});
die $@ if $@;
print "$analysisType in $graph->{outFilename}\n";
$graph->{outFilename} =~ s{/}{\\}g if $^O eq 'MSWin32'; # Damn DOS!
system($graph->{outFilename});
my ($filename, $analysisType, $asSchema) =
( 't/benchmark.Trace.Graph.xml',
'Graph',
'Trace'
);
my $graphType = "Benchmark::Harness::$analysisType";
my $graph = new $graphType($filename, 700, 350,
{
'schema' => $asSchema
,'x_legend' => 'Time - mins', 'x_max_value' => 36
,'y1_legend' => 'Memory | MB', 'y1_max_value' => 6000
,'y2_legend' => 'CPU | %', 'y2_max_value' => 100
});
die $@ if $@;
print "$analysisType in $graph->{outFilename}\n";
$graph->{outFilename} =~ s{/}{\\}g if $^O eq 'MSWin32'; # Damn DOS!
system($graph->{outFilename});
( run in 0.992 second using v1.01-cache-2.11-cpan-49f99fa48dc )