[project @ 2001-05-03 09:01:50 by simonpj]
[ghc-hetmet.git] / glafp-utils / runstdtest / runstdtest.prl
index a1719a3..f53de4f 100644 (file)
@@ -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)
@@ -62,6 +62,9 @@ $DefaultStderrFile = "$TmpPrefix/no_stderr$$";
 $PreScript = '';
 $PostScript = '';
 $TimeCmd = '';
+$Heimdall = 0;
+$HeimdallPrefix = '';
+$HeimdallStats = "heimdall.summary";
 $StatsFile = "$TmpPrefix/stats$$";
 $CacheProfStats = "cacheprof.out.summary";
 $SysSpecificTiming = '';
@@ -70,7 +73,7 @@ $CacheProf = '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);
@@ -114,6 +117,10 @@ arg: while ($_ = $ARGV[0]) {
     /^-cacheprof$/ && do { $SysSpecificTiming = 'ghc-instrs';
                           $CacheProf = 'yes'; 
                           next arg };
+    /^-heimdall$/ && do { $HeimdallPrefix = 'heimdall_cp ';  # must have trailing space!
+                          $SysSpecificTiming = 'ghc-instrs';
+                          $Heimdall = 1;
+                          next arg; };
     /^-t(.*)/  && do { $TimeCmd = &grab_arg_arg('-t', $1); next arg; };
 
     # anything else is taken to be a pgm arg
@@ -192,7 +199,7 @@ cat /dev/null > $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\'
+$TimeCmd /bin/sh -c \'$HeimdallPrefix$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
@@ -230,8 +237,11 @@ 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
+if [ "$Heimdall" = "1" ]; then
+  egrep '^=== HEIMDALL: ' < $TmpPrefix/runtest$$.2 > $HeimdallStats
+fi
+# egrep -v '^=== HEIMDALL: ' < $TmpPrefix/runtest$$.2 > $TmpPrefix/runtest$$.2b
+# mv -f $TmpPrefix/runtest$$.2b $TmpPrefix/runtest$$.2
 
 hit='NO'
 for out_file in @PgmStderrFile ; do
@@ -280,10 +290,11 @@ if ( $SysSpecificTiming eq '' ) {
 
 &process_stats_file();
 &process_cacheprof_files() if $CacheProf eq 'yes';
+&process_heimdall_file() if $Heimdall;
 
 # print out what we found
 print STDERR "<<$SysSpecificTiming: ";
-if ( $CacheProf ne 'yes' ) {
+if ( $CacheProf ne 'yes' && !$Heimdall) {
        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 "$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";
@@ -431,22 +442,36 @@ 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_cacheprof_files {
 
     open(STATS, "< $CacheProfStats") || die("Can't open $CacheProfStats\n");
+
+    # the format of the info in this file is:
+    #    OTHER(intrs,reads,writes,read-misses,write-misses)
+    # where read-misses and write-misses will both be zero if we're
+    # just counting instructions.
+    while (<STATS>) {
+       /OTHER\(\s*([0-9]+),\s*([0-9]+),\s*([0-9]+),\s*([0-9]+),\s*([0-9]+)\)/ && do {
+          $TotInstrs = $1;
+          $TotReads  = $2;
+          $TotWrites = $3;
+      }
+  }
+  close(STATS);
+}
+
+sub process_heimdall_file {
+
+    open(STATS, "< $HeimdallStats") || die("Can't open $HeimdallStats\n");
+
+    # instruction counts from Julian Seward's HEIMDALL:
+    #
+    # === HEIMDALL: instruction counts: 815000 instrs, 230040 reads, 138692 writes
     while (<STATS>) {
-       /OTHER\(\s*([0-9]+),\s*([0-9]+),\s*([0-9]+)\)/ && do {
+       /^=== HEIMDALL: instruction counts: ([0-9]+) instrs, ([0-9]+) reads, ([0-9]+) writes/
+           && do {
           $TotInstrs = $1;
           $TotReads  = $2;
           $TotWrites = $3;
@@ -454,3 +479,4 @@ sub process_cacheprof_files {
   }
   close(STATS);
 }
+