X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=glafp-utils%2Frunstdtest%2Frunstdtest.prl;h=e6a3534b1e16f1da67e9ddfcd9b831bfef68dc21;hb=a08aa16ae39b5fc2f4541e9fd33009a5288ba0ae;hp=3c4c7c21b108e46b9693916c0da878b5968552e6;hpb=8a76a6639317f6f3a6a11d0daab3060793d83df7;p=ghc-hetmet.git diff --git a/glafp-utils/runstdtest/runstdtest.prl b/glafp-utils/runstdtest/runstdtest.prl index 3c4c7c2..e6a3534 100644 --- a/glafp-utils/runstdtest/runstdtest.prl +++ b/glafp-utils/runstdtest/runstdtest.prl @@ -2,7 +2,7 @@ # The perl script requires the following variables to be bound # to something meaningful before it will operate correctly: # -# TMPDIR +# DEFAULT_TMPDIR # CONTEXT_DIFF # RM # @@ -51,8 +51,8 @@ $PgmStdinFile = '/dev/null'; if ( $ENV{'TMPDIR'} ) { # where to make tmp file names $TmpPrefix = $ENV{'TMPDIR'}; } else { - $TmpPrefix ="$TMPDIR"; - $ENV{'TMPDIR'} = "$TMPDIR"; # set the env var as well + $TmpPrefix ="$DEFAULT_TMPDIR"; + $ENV{'TMPDIR'} = "$DEFAULT_TMPDIR"; # set the env var as well } $ScriptFile = "$TmpPrefix/run_me$$"; $DefaultStdoutFile = "$TmpPrefix/no_stdout$$"; # can't use /dev/null (e.g. Alphas) @@ -63,13 +63,14 @@ $PreScript = ''; $PostScript = ''; $TimeCmd = ''; $StatsFile = "$TmpPrefix/stats$$"; +$CachegrindStats = "cachegrind.out.summary"; $SysSpecificTiming = ''; -$SpixTiming = 'no'; +$Cachegrind = 'no'; die "$Pgm: program to run not given as first argument\n" if $#ARGV < 0; $ToRun = $ARGV[0]; shift(@ARGV); # avoid picking up same-named thing from somewhere else on $PATH... -$ToRun = "./$ToRun" if $ToRun !~ /^\//; +$ToRun = "./$ToRun" if -e "./$ToRun"; arg: while ($_ = $ARGV[0]) { shift(@ARGV); @@ -110,9 +111,9 @@ arg: while ($_ = $ARGV[0]) { next arg; }; /^-(ghc|hbc)-timing$/ && do { $SysSpecificTiming = $1; next arg; }; - /^-spix-timing$/ && do { $SysSpecificTiming = 'ghcspix'; - $SpixTiming = 'yes'; - next arg; }; + /^-cachegrind$/ && do { $SysSpecificTiming = 'ghc-instrs'; + $Cachegrind = 'yes'; + next arg }; /^-t(.*)/ && do { $TimeCmd = &grab_arg_arg('-t', $1); next arg; }; # anything else is taken to be a pgm arg @@ -163,37 +164,10 @@ if ( $SysSpecificTiming =~ /^ghc/ ) { $TimingMagic = "-S$StatsFile"; } -$ToRunOrig = $ToRun; -if ( $SpixTiming eq 'yes' ) { - $ToRun .= '.spix'; - - # gotta find first/last addresses in the mutator code - $FirstSpix = '_callWrapper'; - $LastSpix = '???'; # usually _mpz_get_si, but can't be sure - - open(SPIXNM, "nm -n $ToRunOrig |") || die "nm -n $ToRunOrig open failed!\n"; - spix: while () { - if ( / T +(_freeForeignObj|_([A-Za-z]+)Hook|_xmalloc|_mpz_get_si)$/ ) { - $LastSpix = $1; - last spix; - } - } - close(SPIXNM); # || die "nm -n $ToRunOrig close failed!\n"; - - $SpixifyLine1 = "spix -o $ToRun -t$FirstSpix,$LastSpix $ToRunOrig"; - $SpixstatsLine1 = "spixstats -b $TmpPrefix/runtest$$.3 $ToRunOrig > $ToRunOrig.spixstats1"; - $SpixifyLine2 = "spix -o $ToRun +t$FirstSpix,$LastSpix $ToRunOrig"; - $SpixstatsLine2 = "spixstats -b $TmpPrefix/runtest$$.3 $ToRunOrig > $ToRunOrig.spixstats2"; -} else { - $SpixifyLine1 = ''; - $SpixstatsLine1 = ''; - $SpixifyLine2 = ''; - $SpixstatsLine2 = ''; -} - if ($PreScript ne '') { local($to_do); $PreScriptLines = `cat $PreScript`; + $PreScriptLines =~ s/\r//g; } else { $PreScriptLines = ''; } @@ -201,6 +175,7 @@ if ($PreScript ne '') { if ($PostScript ne '') { local($to_do); $PostScriptLines = `cat $PostScript`; + $PostScriptLines =~ s/\r//g; $* = 1; $PostScriptLines =~ s#\$o1#$TmpPrefix/runtest$$.1#g; $PostScriptLines =~ s#\$o2#$TmpPrefix/runtest$$.2#g; @@ -210,6 +185,12 @@ if ($PostScript ne '') { # OK, so we're gonna do the normal thing... +if ($Cachegrind eq 'yes') { + $CachegrindPrefix = "cachegrind --logfile-fd=99 99>$CachegrindStats"; +} else { + $CachegrindPrefix = ''; +} + $Script = < $DefaultStdoutFile cat /dev/null > $DefaultStderrFile $PreScriptLines $SpixifyLine1 -$TimeCmd /bin/sh -c \'$ToRun $TimingMagic @PgmArgs < $PgmStdinFile 1> $TmpPrefix/runtest$$.1 2> $TmpPrefix/runtest$$.2 3> $TmpPrefix/runtest$$.3\' +echo $TimeCmd /bin/sh -c \'$CachegrindPrefix $ToRun $TimingMagic @PgmArgs < $PgmStdinFile 1> $TmpPrefix/runtest$$.1 2> $TmpPrefix/runtest$$.2 3> $TmpPrefix/runtest$$.3\' +$TimeCmd /bin/sh -c \'$CachegrindPrefix $ToRun $TimingMagic @PgmArgs < $PgmStdinFile 1> $TmpPrefix/runtest$$.1 2> $TmpPrefix/runtest$$.2 3> $TmpPrefix/runtest$$.3\' progexit=\$? if [ \$progexit -eq 0 ] && [ $PgmFail -ne 0 ]; then echo $ToRun @PgmArgs \\< $PgmStdinFile @@ -247,7 +229,7 @@ else myexit=\$? diffsShown=1 fi - if [ $SaveStdout = 1 ] && [ \$progexit = $PgmExitStatus ] && + if [ $SaveStdout = 1 ] && [ $PgmStdoutFile[0] != $DefaultStdoutFile ] && [ -s $TmpPrefix/runtest$$.1 ]; then echo Saving away stdout output in $PgmStdoutFile[0] ... if [ -f $PgmStdoutFile[0] ]; then @@ -257,8 +239,6 @@ else cp $TmpPrefix/runtest$$.1 $PgmStdoutFile[0] fi fi -egrep -v '^ld\.so:.*has older revision than expected' < $TmpPrefix/runtest$$.2 > $TmpPrefix/runtest$$.2b -mv -f $TmpPrefix/runtest$$.2b $TmpPrefix/runtest$$.2 hit='NO' for out_file in @PgmStderrFile ; do @@ -275,7 +255,7 @@ if [ \$hit = 'NO' ] ; then myexit=\$? diffsShown=1 fi -if [ $SaveStderr = 1 ] && [ \$progexit = $PgmExitStatus ] && +if [ $SaveStderr = 1 ] && [ $PgmStderrFile[0] != $DefaultStderrFile ] && [ -s $TmpPrefix/runtest$$.2 ]; then echo Saving away stderr output in $PgmStderrFile[0] ... if [ -f $PgmStderrFile[0] ]; then @@ -284,13 +264,6 @@ if [ $SaveStderr = 1 ] && [ \$progexit = $PgmExitStatus ] && fi; cp $TmpPrefix/runtest$$.2 $PgmStderrFile[0] fi -$SpixstatsLine1 - -if [ $SpixTiming = 'yes' -a \$myexit = 0 ] ; then - $SpixifyLine2 - $TimeCmd /bin/sh -c \'$ToRun $TimingMagic @PgmArgs < $PgmStdinFile 1> /dev/null 2> /dev/null 3> $TmpPrefix/runtest$$.3\' - $SpixstatsLine2 -fi ${RM} core $ToRunOrig.spix $DefaultStdoutFile $DefaultStderrFile $TmpPrefix/runtest$$.1 $TmpPrefix/runtest$$.2 $TmpPrefix/runtest$$.3 exit \$myexit @@ -313,18 +286,16 @@ if ( $SysSpecificTiming eq '' ) { } &process_stats_file(); -&process_spixstats_files() if $SpixTiming eq 'yes'; +&process_cachegrind_files() if $Cachegrind eq 'yes'; # print out what we found -if ( $SpixTiming ne 'yes' ) { - print STDERR "<<$SysSpecificTiming: ", - "$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)", - " :$SysSpecificTiming>>\n"; +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)"; } else { - print STDERR "<<$SysSpecificTiming: ", - "$BytesAlloc bytes, $GCs GCs, $AvgResidency/$MaxResidency avg/max bytes residency ($ResidencySamples samples), $TotalInsns[1]/$TotalInsns[2] instructions, $LoadInsns[1]/$LoadInsns[2] loads, $StoreInsns[1]/$StoreInsns[2] stores, $BranchInsns[1]/$BranchInsns[2] branches, $OtherInsns[1]/$OtherInsns[2] others", - " :$SysSpecificTiming>>\n"; -} + 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"; +}; +print STDERR " :$SysSpecificTiming>>\n"; # OK, party over unlink $StatsFile; @@ -334,7 +305,7 @@ exit 0; sub grab_arg_arg { local($option, $rest_of_arg) = @_; - if ($rest_of_arg) { + if ($rest_of_arg ne "") { return($rest_of_arg); } elsif ($#ARGV >= 0) { local($temp) = $ARGV[0]; shift(@ARGV); @@ -467,58 +438,30 @@ sub process_stats_file { $MutElapsed =~ s/,//g; $GcTime =~ s/,//g; $GcElapsed =~ s/,//g; - - # if timings are negative (I've seen -0.00s) then set to 0 - $InitTime = 0 unless $InitTime >= 0; - $InitElapsed = 0 unless $InitElapsed >= 0; - $MutTime = 0 unless $MutTime >= 0; - $MutElapsed = 0 unless $MutElapsed >= 0; - $GcTime = 0 unless $GcTime >= 0; - $GcElapsed = 0 unless $GcElapsed >= 0; - } -sub process_spixstats_files { # 2 of them; one for mutator, one for GC - - @TotalInsns = (); - @LoadInsns = (); - @StoreInsns = (); - @BranchInsns= (); - @OtherInsns = (); - - foreach $f (1, 2) { +sub process_cachegrind_files { - open(STATS, "< $ToRunOrig.spixstats$f") || die "Failed when opening $ToRunOrig.spixstats$f\n"; - while () { - last if /^OPCODES \(STATIC\):/; # party over + open(STATS, "< $CachegrindStats") || die("Can't open $CachegrindStats\n"); - next if /^OPCODES \(DYNAMIC\):/; - next if /^$/; - next if /^opcode\s+#executed/; - next if /^SUBTOTAL/; + while () { + /^==\d+==\s+I\s+refs:\s+([0-9,]*)/ && do { + $TotInstrs = $1; + $TotInstrs =~ s/,//g; + }; - if ( /^ld\S*\s+(\d+)/ ) { - $LoadInsns[$f] += $1; + /^==\d+==\s+D\s+refs:\s+[0-9,]+\s+\(([0-9,]+)\s+rd\s+\+\s+([0-9,]+)\s+wr/ && do { + $TotReads = $1; + $TotWrites = $2; + $TotReads =~ s/,//g; + $TotWrites =~ s/,//g; + }; - } elsif ( /^st\S*\s+(\d+)/ ) { - $StoreInsns[$f] += $1; - - } elsif ( /^(jmpl|call|b\S*)\s+(\d+)/ ) { - $BranchInsns[$f] += $2; - - } elsif ( /^TOTAL\s+(\d+)/ ) { - $TotalInsns[$f] = $1; - print STDERR "TotalInsns doesn't match categories total!\n" - if $TotalInsns[$f] != - ($LoadInsns[$f] + $StoreInsns[$f] + $BranchInsns[$f] + $OtherInsns[$f]); - - } elsif ( /^\S+\s+(\d+)/ ) { - $OtherInsns[$f] += $1; - - } else { - die "Funny line?? $_"; - } - } - close(STATS) || die "Failed when closing $ToRunOrig.spixstats\n"; + /^==\d+==\s+L2d\s+misses:\s+([0-9,]+)/ && do { + $TotMisses = $1; + $TotMisses =~ s/,//g; + }; } + close(STATS); } +