Debugging/LowLevelProfiling/PAPI: TestWithPAPI.diff

File TestWithPAPI.diff, 4.4 KB (added by simonmar, 4 years ago)
  • utils/runstdtest/runstdtest.prl

    Thu Dec 21 12:57:09 CET 2006  Alexey Rodriguez <mrchebas@gmail.com>
      * Extension of testing script to parse PAPI results from GHC programs.
    diff -rN -u old-ghc/utils/runstdtest/runstdtest.prl new-ghc/utils/runstdtest/runstdtest.prl
    old new  
    7272$StatsFile = "$TmpPrefix/stats$$"; 
    7373$CachegrindStats = "cachegrind.out.summary"; 
    7474$SysSpecificTiming = ''; 
     75$SysCPUCounting = 0; # Use CPU counters 
    7576$Cachegrind = 'no'; 
     77$Counters = ""; 
    7678 
    7779die "$Pgm: program to run not given as first argument\n" if $#ARGV < 0; 
    7880$ToRun = $ARGV[0]; shift(@ARGV); 
     
    118120                    next arg; }; 
    119121    /^-(ghc|hbc)-timing$/ && do { $SysSpecificTiming = $1; 
    120122                                  next arg; }; 
     123    /^-cpu-counting-(.)$/ && do { $SysCPUCounting = "$1"; 
     124                                  next arg; }; 
    121125    /^-cachegrind$/ && do { $SysSpecificTiming = 'ghc-instrs'; 
    122126                            $Cachegrind = 'yes';  
    123127                            next arg }; 
     
    166170# deal with system-specific timing options 
    167171$TimingMagic = ''; 
    168172if ( $SysSpecificTiming =~ /^ghc/ ) { 
    169     $TimingMagic = "+RTS -S$StatsFile -RTS" 
     173    if ($SysCPUCounting) { 
     174        # Count specified CPU events 
     175        $cpu_counting_ghc = "-a$SysCPUCounting"; 
     176    } else { 
     177        $cpu_counting_ghc = ""; 
     178    } 
     179    $TimingMagic = "+RTS -S$StatsFile $cpu_counting_ghc -RTS" 
    170180} elsif ( $SysSpecificTiming eq 'hbc' ) { 
    171181    $TimingMagic = "-S$StatsFile"; 
    172182} 
     
    300310# print out what we found 
    301311print STDERR "<<$SysSpecificTiming: "; 
    302312if ( $Cachegrind ne 'yes') { 
    303         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)"; 
     313        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"; 
    304314} else { 
    305315        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"; 
    306316}; 
     
    359369        local($max_live)    = 0;  
    360370        local($tot_live)    = 0; # for calculating residency stuff 
    361371        local($tot_samples) = 0; 
     372        local($into_gc_counters) = 0; # once we reach into the GC counters part 
     373        local($counters) = ""; 
     374        local($counter) = ""; 
     375        local($count) = 0; 
    362376 
    363377        $GCWork = 0; 
    364378        while (<STATS>) { 
     
    393407            } elsif ( /^\s*GC\s+time\s*(-*\d+\.\d\d)s\s*\(\s*(-*\d+\.\d\d)s elapsed\)/ ) { 
    394408                $GcTime = $1; $GcElapsed = $2; 
    395409            } 
     410 
     411            if ( /CPU GC counters/ ) { 
     412                # Counters that follow correspond to GC 
     413                $into_gc_counters = 1; 
     414            } 
     415 
     416            if ( /^\s+\(([A-Z_0-9]+)\)\s+:\s+([0-9,]+)/ ) { 
     417                $counter = $1; 
     418                $count   = $2; 
     419                $count =~ s/,//g; # Remove commas in numbers 
     420                # Pretty printing elements of a list with type [(String,[Float])] 
     421                # It's a bit lame for passing values but it works. 
     422                if($into_gc_counters) { 
     423                    $counters = "$counters(\"GC:$counter\",[$count]),"; 
     424                } else { 
     425                    $counters = "$counters(\"$counter\",[$count]),"; 
     426                } 
     427            } 
     428 
     429            if ( /^\s+\(([A-Z_0-9]+)\)\s+\%\s+of\s+\(([A-Z_0-9]+)\)\s+:\s+([0-9.]+)/ ) { 
     430                $counter = "$1/$2"; # Relative quantity 
     431                $count   = $3; 
     432                # Pretty printing elements of a list with type [(String,[Float])] 
     433                # It's a bit lame for passing values but it works. 
     434                if($into_gc_counters) { 
     435                    $counters = "$counters(\"GC:$counter\",[$count]),"; 
     436                } else { 
     437                    $counters = "$counters(\"$counter\",[$count]),"; 
     438                } 
     439            } 
     440 
    396441        } 
    397442        close(STATS) || die "Failed when closing $StatsFile\n"; 
    398443        if ( $tot_samples > 0 ) { 
     
    401446            $AvgResidency = int ($tot_live / $tot_samples) ; 
    402447        } 
    403448 
     449        if ( length($counters) == 0 ) { 
     450            $Counters = ""; 
     451        } else { 
     452            chop($counters); # remove trailing comma from the last entry 
     453            $Counters = " [$counters]"; 
     454        } 
     455 
    404456    } elsif ( $SysSpecificTiming eq 'hbc' ) { 
    405457 
    406458        open(STATS, $StatsFile) || die "Failed when opening $StatsFile\n";