2002-11-19 19:32:32 +00:00
#!/usr/local/bin/perl
2002-12-06 01:40:42 +00:00
# ********************************************************************
# * COPYRIGHT:
# * Copyright (c) 2002, International Business Machines Corporation and
# * others. All Rights Reserved.
# ********************************************************************
2002-11-19 19:32:32 +00:00
use strict ;
2002-11-21 07:08:14 +00:00
use Dataset ;
2002-11-19 19:32:32 +00:00
my $ TABLEATTR = 'BORDER="1" CELLPADDING="4" CELLSPACING="0"' ;
my $ outType = "HTML" ;
my $ html = "noName" ;
my $ inTable ;
my @ headers ;
2002-11-21 07:08:14 +00:00
my @ timetypes = ( "mean per op" , "error per op" , "events" , "per event" ) ;
2002-11-19 19:32:32 +00:00
my % raw ;
2002-11-21 07:08:14 +00:00
my $ current = "" ;
2002-11-19 19:32:32 +00:00
my $ exp = 0 ;
2002-11-21 07:08:14 +00:00
my $ mult = 1e9 ; #use nanoseconds
my $ perc = 100 ; #for percent
my $ printEvents = 0 ;
my $ legend = "<a name=\"Legend\">\n<h2>Table legend</h2></a><ul>" ;
my $ legendDone = 0 ;
my % options ;
my $ operationIs = "operation" ;
my $ eventIs = "event" ;
2002-11-19 19:32:32 +00:00
sub startTest {
$ current = shift ;
$ exp = 0 ;
outputData ( $ current ) ;
}
2002-11-21 07:08:14 +00:00
sub printLeg {
if ( ! $ legendDone ) {
my $ message ;
foreach $ message ( @ _ ) {
$ legend . = "<li>" . $ message . "</li>\n" ;
}
}
}
2002-12-18 08:41:00 +00:00
sub outputDist {
my $ value = shift ;
my $ percent = shift ;
my $ mean = $ value - > getMean ;
my $ error = $ value - > getError ;
print HTML "<td class=\"" ;
if ( $ mean > 0 ) {
print HTML "value" ;
} else {
print HTML "worse" ;
}
print HTML "\">" ;
if ( $ percent ) {
print HTML formatPercent ( 2 , $ mean ) ;
} else {
print HTML formatNumber ( 2 , $ mult , $ mean ) ;
}
print HTML "</td>\n" ;
print HTML "<td class=\"" ;
if ( ( ( $ error * $ mult < 10 ) && ! $ percent ) || ( ( $ error < 10 ) && $ percent ) ) {
print HTML "error" ;
} else {
print HTML "errorLarge" ;
}
print HTML "\">±" ;
if ( $ percent ) {
print HTML formatPercent ( 2 , $ error ) ;
} else {
print HTML formatNumber ( 2 , $ mult , $ error ) ;
}
print HTML "</td>\n" ;
}
sub outputValue {
my $ value = shift ;
print HTML "<td class=\"sepvalue\">" ;
print HTML $ value ;
#print HTML formatNumber(2, 1, $value);
print HTML "</td>\n" ;
}
2002-11-19 19:32:32 +00:00
sub startTable {
2002-11-21 07:08:14 +00:00
#my $printEvents = shift;
2002-11-19 19:32:32 +00:00
$ inTable = 1 ;
2002-11-21 07:08:14 +00:00
my $ i ;
2002-11-19 19:32:32 +00:00
print HTML "<table $TABLEATTR>\n" ;
2002-12-18 08:41:00 +00:00
print HTML "<tbody>\n" ;
2002-11-19 19:32:32 +00:00
if ( $# headers >= 0 ) {
my ( $ header , $ i ) ;
2002-12-18 08:41:00 +00:00
print HTML "<tr>\n" ;
print HTML "<th rowspan=\"2\" class=\"testNameHeader\"><a href=\"#TestName\">Test Name</a></th>\n" ;
print HTML "<th rowspan=\"2\" class=\"testNameHeader\"><a href=\"#Ops\">Ops</a></th>\n" ;
printLeg ( "<a name=\"Test Name\">TestName</a> - name of the test as set by the test writer\n" , "<a name=\"Ops\">Ops</a> - number of " . $ operationIs . "s per iteration\n" ) ;
if ( ! $ printEvents ) {
print HTML "<th colspan=" . ( ( 4 * ( $# headers + 1 ) ) - 2 ) . " class=\"sourceType\">Per Operation</th>\n" ;
} else {
print HTML "<th colspan=" . ( ( 2 * ( $# headers + 1 ) ) - 2 ) . " class=\"sourceType\">Per Operation</th>\n" ;
print HTML "<th colspan=" . ( ( 5 * ( $# headers + 1 ) ) - 2 ) . " class=\"sourceType\">Per Event</th>\n" ;
}
print HTML "</tr>\n<tr>\n" ;
2002-11-21 07:08:14 +00:00
if ( ! $ printEvents ) {
2002-11-19 19:32:32 +00:00
foreach $ header ( @ headers ) {
2002-12-18 08:41:00 +00:00
print HTML "<th class=\"source\" colspan=2><a href=\"#meanop_$header\">$header<br>/op</a></th>\n" ;
printLeg ( "<a name=\"meanop_$header\">$header /op</a> - mean time and error for $header per $operationIs" ) ;
2002-11-19 19:32:32 +00:00
}
}
2002-11-21 07:08:14 +00:00
for $ i ( 1 .. $# headers ) {
2002-12-18 08:41:00 +00:00
print HTML "<th class=\"source\" colspan=2><a href=\"#mean_op_$i\">ratio $i<br>/op</a></th>\n" ;
printLeg ( "<a name=\"mean_op_$i\">ratio $i /op</a> - ratio and error of per $operationIs time, calculated as: (($headers[0] - $headers[$i])/$headers[$i])*100%, mean value" ) ;
2002-11-21 07:08:14 +00:00
}
if ( $ printEvents ) {
foreach $ header ( @ headers ) {
2002-12-18 08:41:00 +00:00
print HTML "<th class=\"source\"><a href=\"#events_$header\">$header<br>events</a></th>\n" ;
printLeg ( "<a name=\"events_$header\">$header events</a> - number of " . $ eventIs . "s for $header per iteration" ) ;
2002-11-21 07:08:14 +00:00
}
foreach $ header ( @ headers ) {
2002-12-18 08:41:00 +00:00
print HTML "<th class=\"source\" colspan=2><a href=\"#mean_ev_$header\">$header<br>/ev</a></th>\n" ;
printLeg ( "<a name=\"mean_ev_$header\">$header /ev</a> - mean time and error for $header per $eventIs" ) ;
2002-11-21 07:08:14 +00:00
}
for $ i ( 1 .. $# headers ) {
2002-12-18 08:41:00 +00:00
print HTML "<th class=\"source\" colspan=2><a href=\"#mean_ev_$i\">ratio $i<br>/ev</a></th>\n" ;
printLeg ( "<a name=\"mean_ev_$i\">ratio $i /ev</a> - ratio and error of per $eventIs time, calculated as: (($headers[0] - $headers[$i])/$headers[$i])*100%, mean value" ) ;
2002-11-21 07:08:14 +00:00
}
}
2002-11-19 19:32:32 +00:00
print HTML "</tr>\n" ;
}
2002-11-21 07:08:14 +00:00
$ legendDone = 1 ;
2002-11-19 19:32:32 +00:00
}
sub closeTable {
if ( $ inTable ) {
undef $ inTable ;
print HTML "</tr>\n" ;
2002-12-18 08:41:00 +00:00
print HTML "</tbody>" ;
2002-11-19 19:32:32 +00:00
print HTML "</table>\n" ;
}
}
sub newRow {
if ( ! $ inTable ) {
startTable ;
} else {
print HTML "</tr>\n" ;
}
print HTML "<tr>" ;
}
sub outputData {
if ( $ inTable ) {
2002-11-21 07:08:14 +00:00
my $ msg = shift ;
my $ align = shift ;
print HTML "<td" ;
if ( $ align ) {
print HTML " align = $align>" ;
} else {
print HTML ">" ;
2002-11-19 19:32:32 +00:00
}
2002-11-21 07:08:14 +00:00
print HTML "$msg" ;
2002-11-19 19:32:32 +00:00
print HTML "</td>" ;
} else {
2002-11-21 07:08:14 +00:00
my $ message ;
2002-11-19 19:32:32 +00:00
foreach $ message ( @ _ ) {
print HTML "$message" ;
}
}
}
sub setupOutput {
my $ date = localtime ;
my $ options = shift ;
2002-11-21 07:08:14 +00:00
% options = % { $ options } ;
2002-11-19 19:32:32 +00:00
my $ title = $ options { "title" } ;
my $ headers = $ options { "headers" } ;
2002-11-21 07:08:14 +00:00
if ( $ options { "operationIs" } ) {
$ operationIs = $ options { "operationIs" } ;
}
if ( $ options { "eventIs" } ) {
$ eventIs = $ options { "eventIs" } ;
}
2002-11-19 19:32:32 +00:00
@ headers = split ( / / , $ headers ) ;
my ( $ t , $ rest ) ;
( $ t , $ rest ) = split ( /\.\w+/ , $ 0 ) ;
$ t =~ /^.*\W(\w+)$/ ;
$ t = $ 1 ;
if ( $ outType eq 'HTML' ) {
$ html = $ date ;
$ html =~ s/://g ; # ':' illegal
$ html =~ s/\s*\d+$// ; # delete year
$ html =~ s/^\w+\s*// ; # delete dow
$ html = "$t $html.html" ;
if ( $ options { "outputDir" } ) {
$ html = $ options { "outputDir" } . "/" . $ html ;
}
2002-12-18 08:41:00 +00:00
$ html =~ s/ /_/g ;
2002-11-19 19:32:32 +00:00
open ( HTML , ">$html" ) or die "Can't write to $html: $!" ;
2002-12-18 08:41:00 +00:00
#<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2002-11-19 19:32:32 +00:00
print HTML << EOF ;
<HTML>
<HEAD>
2002-12-18 08:41:00 +00:00
< meta http - equiv = "Content-Type" content = "text/html; charset=utf-8" >
2002-11-19 19:32:32 +00:00
<TITLE> $ title </TITLE>
2002-11-21 07:08:14 +00:00
<style>
< ! - -
2002-12-18 08:41:00 +00:00
body { font - size: 10 pt ; font - family: sans - serif }
th { font - size: 10 pt ; border: 0 solid #000080; padding: 5 }
th . testNameHeader { border - width: 1 }
th . testName { text - align: left ; border - left - width: 1 ; border - right - width: 1 ;
border - bottom - width: 1 }
th . source { border - right - width: 1 ; border - bottom - width: 1 }
th . sourceType { border - right - width: 1 ; border - top - width: 1 ; border - bottom - width: 1 }
td { font - size: 10 pt ; text - align: Right ; border: 0 solid #000080; padding: 5 }
td . string { text - align: Left ; border - bottom - width:1 ; border - right - width:1 }
td . sepvalue { border - bottom - width: 1 ; border - right - width: 1 }
td . value { border - bottom - width: 1 }
td . worse { color: #FF0000; font-weight: bold; border-bottom-width: 1 }
td . error { font - size: 75 % ; border - right - width: 1 ; border - bottom - width: 1 }
td . errorLarge { font - size: 75 % ; color: #FF0000; font-weight: bold; border-right-width: 1;
border - bottom - width: 1 }
A:link { color: black ; font - weight: normal ; text - decoration: none } /* unvisited links */
A:visited { color: blue ; font - weight: normal ; text - decoration: none } /* visited links */
A:hover { color: red ; font - weight: normal ; text - decoration: none } /* user hovers */
A:active { color: lime ; font - weight: normal ; text - decoration: none } /* active links */
2002-11-21 07:08:14 +00:00
- - >
</style>
2002-11-19 19:32:32 +00:00
</HEAD>
2002-12-18 08:41:00 +00:00
< BODY bgcolor = "#FFFFFF" LINK = "#006666" VLINK = "#000000" >
2002-11-19 19:32:32 +00:00
EOF
print HTML "<H1>$title</H1>\n" ;
#print HTML "<H2>$TESTCLASS</H2>\n";
}
}
sub closeOutput {
if ( $ outType eq 'HTML' ) {
if ( $ inTable ) {
closeTable ;
}
2002-11-21 07:08:14 +00:00
$ legend . = "</ul>\n" ;
print HTML $ legend ;
2002-12-18 08:41:00 +00:00
outputRaw ( ) ;
2002-11-19 19:32:32 +00:00
print HTML << EOF ;
</BODY>
</HTML>
EOF
close ( HTML ) or die "Can't close $html: $!" ;
}
}
2002-12-18 08:41:00 +00:00
sub outputRaw {
2002-11-19 19:32:32 +00:00
print HTML "<h2>Raw data</h2>" ;
my $ key ;
my $ i ;
2002-11-21 07:08:14 +00:00
my $ j ;
my $ k ;
print HTML "<table $TABLEATTR>\n" ;
2002-11-19 19:32:32 +00:00
for $ key ( sort keys % raw ) {
2002-11-21 07:08:14 +00:00
my $ printkey = $ key ;
2002-12-18 08:41:00 +00:00
$ printkey =~ s/\<br\>/ /g ;
2002-11-21 07:08:14 +00:00
if ( $ printEvents ) {
2002-12-18 08:41:00 +00:00
if ( $ key ne "" ) {
print HTML "<tr><th class=\"testNameHeader\" colspan = 7>$printkey</td></tr>\n" ; # locale and data file
}
print HTML "<tr><th class=\"testName\">test name</th><th class=\"testName\">interesting arguments</th><th class=\"testName\">iterations</th><th class=\"testName\">operations</th><th class=\"testName\">mean time (ns)</th><th class=\"testName\">error (ns)</th><th class=\"testName\">events</th></tr>\n" ;
2002-11-21 07:08:14 +00:00
} else {
2002-12-18 08:41:00 +00:00
if ( $ key ne "" ) {
print HTML "<tr><th class=\"testName\" colspan = 6>$printkey</td></tr>\n" ; # locale and data file
}
print HTML "<tr><th class=\"testName\">test name</th><th class=\"testName\">interesting arguments</th><th class=\"testName\">iterations</th><th class=\"testName\">operations</th><th class=\"testName\">mean time (ns)</th><th class=\"testName\">error (ns)</th></tr>\n" ;
2002-11-21 07:08:14 +00:00
}
2002-12-18 08:41:00 +00:00
$ printkey =~ s/[\<\>\/ ]//g ;
2002-11-21 07:08:14 +00:00
2002-12-18 08:41:00 +00:00
my % done ;
2002-11-21 07:08:14 +00:00
for $ i ( $ raw { $ key } ) {
print HTML "<tr>" ;
for $ j ( @$ i ) {
my ( $ test , $ args ) ;
( $ test , $ args ) = split ( /,/ , shift ( @$ j ) ) ;
2002-12-18 08:41:00 +00:00
print HTML "<th class=\"testName\">" ;
if ( ! $ done { $ test } ) {
print HTML "<a name=\"" . $ printkey . "_" . $ test . "\">" . $ test . "</a>" ;
$ done { $ test } = 1 ;
} else {
print HTML $ test ;
}
print HTML "</th>" ;
print HTML "<td class=\"string\">" . $ args . "</td>" ;
2002-11-21 07:08:14 +00:00
2002-12-18 08:41:00 +00:00
print HTML "<td class=\"sepvalue\">" . shift ( @$ j ) . "</td>" ;
print HTML "<td class=\"sepvalue\">" . shift ( @$ j ) . "</td>" ;
2002-11-21 07:08:14 +00:00
my @ data = @ { shift ( @$ j ) } ;
my $ ds = Dataset - > new ( @ data ) ;
2002-12-18 08:41:00 +00:00
print HTML "<td class=\"sepvalue\">" . formatNumber ( 4 , $ mult , $ ds - > getMean ) . "</td><td class=\"sepvalue\">" . formatNumber ( 4 , $ mult , $ ds - > getError ) . "</td>" ;
2002-11-21 07:08:14 +00:00
if ( $# { $ j } >= 0 ) {
2002-12-18 08:41:00 +00:00
print HTML "<td class=\"sepvalue\">" . shift ( @$ j ) . "</td>" ;
2002-11-21 07:08:14 +00:00
}
print HTML "</tr>\n" ;
}
}
2002-11-19 19:32:32 +00:00
}
2002-11-21 07:08:14 +00:00
}
sub store {
$ raw { $ current } [ $ exp + + ] = [ @ _ ] ;
2002-11-19 19:32:32 +00:00
}
sub outputRow {
2002-11-21 07:08:14 +00:00
#$raw{$current}[$exp++] = [@_];
2002-11-19 19:32:32 +00:00
my $ testName = shift ;
my @ iterPerPass = @ { shift ( @ _ ) } ;
my @ noopers = @ { shift ( @ _ ) } ;
2002-11-21 07:08:14 +00:00
my @ timedata = @ { shift ( @ _ ) } ;
2002-11-19 19:32:32 +00:00
my @ noevents ;
if ( $# _ >= 0 ) {
@ noevents = @ { shift ( @ _ ) } ;
}
if ( ! $ inTable ) {
if ( @ noevents ) {
2002-11-21 07:08:14 +00:00
$ printEvents = 1 ;
startTable ;
2002-11-19 19:32:32 +00:00
} else {
startTable ;
}
}
debug ( "No events: @noevents, $#noevents\n" ) ;
my $ j ;
2002-12-18 08:41:00 +00:00
my $ loc = $ current ;
$ loc =~ s/\<br\>/ /g ;
$ loc =~ s/[\<\>\/ ]//g ;
2002-11-19 19:32:32 +00:00
# Finished one row of results. Outputting
newRow ;
2002-12-18 08:41:00 +00:00
#outputData($testName, "LEFT");
print HTML "<th class=\"testName\"><a href=\"#" . $ loc . "_" . $ testName . "\">$testName</a></th>\n" ;
2002-11-19 19:32:32 +00:00
#outputData($iterCount);
2002-12-18 08:41:00 +00:00
#outputData($noopers[0], "RIGHT");
outputValue ( $ noopers [ 0 ] ) ;
2002-11-21 07:08:14 +00:00
if ( ! $ printEvents ) {
for $ j ( 0 .. $# timedata ) {
my $ perOperation = $ timedata [ $ j ] - > divideByScalar ( $ iterPerPass [ $ j ] * $ noopers [ $ j ] ) ; # time per operation
#debug("Time per operation: ".formatSeconds(4, $perOperation->getMean, $perOperation->getError)."\n");
2002-12-18 08:41:00 +00:00
outputDist ( $ perOperation ) ;
2002-11-21 07:08:14 +00:00
}
2002-11-19 19:32:32 +00:00
}
2002-11-21 07:08:14 +00:00
my $ baseLinePO = $ timedata [ 0 ] - > divideByScalar ( $ iterPerPass [ 0 ] * $ noopers [ 0 ] ) ;
for $ j ( 1 .. $# timedata ) {
2002-11-19 19:32:32 +00:00
my $ perOperation = $ timedata [ $ j ] - > divideByScalar ( $ iterPerPass [ $ j ] * $ noopers [ $ j ] ) ; # time per operation
2002-11-21 07:08:14 +00:00
my $ ratio = $ baseLinePO - > subtract ( $ perOperation ) ;
$ ratio = $ ratio - > divide ( $ perOperation ) ;
2002-12-18 08:41:00 +00:00
outputDist ( $ ratio , "%" ) ;
2002-11-21 07:08:14 +00:00
}
if ( @ noevents ) {
2002-11-19 19:32:32 +00:00
for $ j ( 0 .. $# timedata ) {
2002-12-18 08:41:00 +00:00
#outputData($noevents[$j], "RIGHT");
outputValue ( $ noevents [ $ j ] ) ;
2002-11-19 19:32:32 +00:00
}
for $ j ( 0 .. $# timedata ) {
my $ perEvent = $ timedata [ $ j ] - > divideByScalar ( $ iterPerPass [ $ j ] * $ noevents [ $ j ] ) ; # time per event
#debug("Time per operation: ".formatSeconds(4, $perEvent->getMean, $perEvent->getError)."\n");
2002-12-18 08:41:00 +00:00
outputDist ( $ perEvent ) ;
2002-11-21 07:08:14 +00:00
}
my $ baseLinePO = $ timedata [ 0 ] - > divideByScalar ( $ iterPerPass [ 0 ] * $ noevents [ 0 ] ) ;
for $ j ( 1 .. $# timedata ) {
my $ perOperation = $ timedata [ $ j ] - > divideByScalar ( $ iterPerPass [ $ j ] * $ noevents [ $ j ] ) ; # time per operation
my $ ratio = $ baseLinePO - > subtract ( $ perOperation ) ;
$ ratio = $ ratio - > divide ( $ perOperation ) ;
2002-12-18 08:41:00 +00:00
outputDist ( $ ratio , "%" ) ;
2002-11-19 19:32:32 +00:00
}
}
}
1 ;
#eof