$Verbose = 0;
$SaveStderr = 0;
$SaveStdout = 0;
+$StdoutBinary = 0;
+$StderrBinary = 0;
$Status = 0;
@PgmArgs = ();
$PgmFail=0;
$StatsFile = "$TmpPrefix/stats$$";
$CachegrindStats = "cachegrind.out.summary";
$SysSpecificTiming = '';
+$SysCPUCounting = 0; # Use CPU counters
$Cachegrind = 'no';
+$Counters = "";
die "$Pgm: program to run not given as first argument\n" if $#ARGV < 0;
$ToRun = $ARGV[0]; shift(@ARGV);
/^-accept-output-stdout$/ && do { $SaveStdout = 1; next arg; };
/^-accept-output$/ && do { $SaveStdout = 1; $SaveStderr = 1; next arg; };
+ /^-stdout-binary/ && do { $StdoutBinary=1; next arg; };
+ /^-stdout-binary/ && do { $StderrBinary=1; next arg; };
+
/^-O(.*)/ && do { push(@PgmArgs, &grab_arg_arg('-O',$1)); next arg; };
/^-i(.*)/ && do { $PgmStdinFile = &grab_arg_arg('-i',$1);
$Status++,
next arg; };
/^-(ghc|hbc)-timing$/ && do { $SysSpecificTiming = $1;
next arg; };
+ /^-cpu-counting-(.)$/ && do { $SysCPUCounting = "$1";
+ next arg; };
/^-cachegrind$/ && do { $SysSpecificTiming = 'ghc-instrs';
$Cachegrind = 'yes';
next arg };
# deal with system-specific timing options
$TimingMagic = '';
if ( $SysSpecificTiming =~ /^ghc/ ) {
- $TimingMagic = "+RTS -S$StatsFile -RTS"
+ if ($SysCPUCounting) {
+ # Count specified CPU events
+ $cpu_counting_ghc = "-a$SysCPUCounting";
+ } else {
+ $cpu_counting_ghc = "";
+ }
+ $TimingMagic = "+RTS -S$StatsFile $cpu_counting_ghc -RTS"
} elsif ( $SysSpecificTiming eq 'hbc' ) {
$TimingMagic = "-S$StatsFile";
}
$PreScriptLines
$SpixifyLine1
$TimeCmd /bin/sh -c \'$CachegrindPrefix $ToRun $TimingMagic @PgmArgs < $PgmStdinFile 1> $TmpPrefix/runtest$$.1.raw 2> $TmpPrefix/runtest$$.2.raw 3> $TmpPrefix/runtest$$.3.raw\'
-dos2unix < $TmpPrefix/runtest$$.1.raw > $TmpPrefix/runtest$$.1
-dos2unix < $TmpPrefix/runtest$$.2.raw > $TmpPrefix/runtest$$.2
+if [ "$StdoutBinary" = "0" ]; then
+ dos2unix < $TmpPrefix/runtest$$.1.raw > $TmpPrefix/runtest$$.1
+else
+ cp $TmpPrefix/runtest$$.1.raw $TmpPrefix/runtest$$.1
+fi
+if [ "$StderrBinary" = "0" ]; then
+ dos2unix < $TmpPrefix/runtest$$.2.raw > $TmpPrefix/runtest$$.2
+else
+ cp $TmpPrefix/runtest$$.2.raw $TmpPrefix/runtest$$.2
+fi
dos2unix < $TmpPrefix/runtest$$.3.raw > $TmpPrefix/runtest$$.3
progexit=\$?
if [ \$progexit -eq 0 ] && [ $PgmFail -ne 0 ]; then
cp $TmpPrefix/runtest$$.2 $PgmStderrFile[0]
fi
-${RM} core $ToRunOrig.spix $DefaultStdoutFile $DefaultStderrFile $TmpPrefix/runtest$$.1 $TmpPrefix/runtest$$.2 $TmpPrefix/runtest$$.3
+${RM} core $ToRunOrig.spix $DefaultStdoutFile $DefaultStderrFile $TmpPrefix/runtest$$.1 $TmpPrefix/runtest$$.2 $TmpPrefix/runtest$$.3 $TmpPrefix/runtest$$.1.raw $TmpPrefix/runtest$$.2.raw $TmpPrefix/runtest$$.3.raw
exit \$myexit
EOSCRIPT
# print out what we found
print STDERR "<<$SysSpecificTiming: ";
if ( $Cachegrind ne 'yes') {
- print STDERR "$BytesAlloc bytes, $GCs GCs, $AvgResidency/$MaxResidency avg/max bytes residency ($ResidencySamples samples), $GCWork bytes GC work, ${TotMem}M in use, $InitTime INIT ($InitElapsed elapsed), $MutTime MUT ($MutElapsed elapsed), $GcTime GC ($GcElapsed elapsed)";
+ print STDERR "$BytesAlloc bytes, $GCs GCs, $AvgResidency/$MaxResidency avg/max bytes residency ($ResidencySamples samples), $GCWork bytes GC work, ${TotMem}M in use, $InitTime INIT ($InitElapsed elapsed), $MutTime MUT ($MutElapsed elapsed), $GcTime GC ($GcElapsed elapsed)$Counters";
} else {
print STDERR "$BytesAlloc bytes, $GCs GCs, $AvgResidency/$MaxResidency avg/max bytes residency ($ResidencySamples samples), $GCWork bytes GC work, ${TotMem}M in use, $InitTime INIT ($InitElapsed elapsed), $MutTime MUT ($MutElapsed elapsed), $GcTime GC ($GcElapsed elapsed), $TotInstrs instructions, $TotReads memory reads, $TotWrites memory writes, $TotMisses L2 cache misses";
};
local($max_live) = 0;
local($tot_live) = 0; # for calculating residency stuff
local($tot_samples) = 0;
+ local($into_gc_counters) = 0; # once we reach into the GC counters part
+ local($counters) = "";
+ local($counter) = "";
+ local($count) = 0;
$GCWork = 0;
while (<STATS>) {
} elsif ( /^\s*GC\s+time\s*(-*\d+\.\d\d)s\s*\(\s*(-*\d+\.\d\d)s elapsed\)/ ) {
$GcTime = $1; $GcElapsed = $2;
}
+
+ if ( /CPU GC counters/ ) {
+ # Counters that follow correspond to GC
+ $into_gc_counters = 1;
+ }
+
+ if ( /^\s+\(([A-Z_0-9]+)\)\s+:\s+([0-9,]+)/ ) {
+ $counter = $1;
+ $count = $2;
+ $count =~ s/,//g; # Remove commas in numbers
+ # Pretty printing elements of a list with type [(String,[Float])]
+ # It's a bit lame for passing values but it works.
+ if($into_gc_counters) {
+ $counters = "$counters(\"GC:$counter\",[$count]),";
+ } else {
+ $counters = "$counters(\"$counter\",[$count]),";
+ }
+ }
+
+ if ( /^\s+\(([A-Z_0-9]+)\)\s+\%\s+of\s+\(([A-Z_0-9]+)\)\s+:\s+([0-9.]+)/ ) {
+ $counter = "$1/$2"; # Relative quantity
+ $count = $3;
+ # Pretty printing elements of a list with type [(String,[Float])]
+ # It's a bit lame for passing values but it works.
+ if($into_gc_counters) {
+ $counters = "$counters(\"GC:$counter\",[$count]),";
+ } else {
+ $counters = "$counters(\"$counter\",[$count]),";
+ }
+ }
+
}
close(STATS) || die "Failed when closing $StatsFile\n";
if ( $tot_samples > 0 ) {
$AvgResidency = int ($tot_live / $tot_samples) ;
}
+ if ( length($counters) == 0 ) {
+ $Counters = "";
+ } else {
+ chop($counters); # remove trailing comma from the last entry
+ $Counters = " [$counters]";
+ }
+
} elsif ( $SysSpecificTiming eq 'hbc' ) {
open(STATS, $StatsFile) || die "Failed when opening $StatsFile\n";