perfex.pl 3.3 KB
#!/usr/local/bin/perl5 
#
# Copyright (C) 1996-1998 by the Board of Trustees
#    of Leland Stanford Junior University.
# 
# This file is part of the SimOS distribution. 
# See LICENSE file for terms of the license. 
#
#
# Parse the output of the "perfex" command.
# 
# Steve Herrod

if (($#ARGV+1) < 1) {
   die "Usage: $0 <file>\n";
}

$FILENAME = shift(@ARGV);

open(FILE, $FILENAME) || die "Can't open $FILENAME: $!\n";

while (<FILE>) {
    if (/ 0 Cycles......................................................\s+(\d+)*/) {
        $cycleCount = $1;
    }
    if (/^ 6 Decoded branches............................................\s+(\d+)*/) {
        $branchCount = $1;
    }
    if (/^ 9 Primary instruction cache misses............................\s+(\d+)*/) {
        $pIMisses = $1;
    }
    if (/^10 Secondary instruction cache misses..........................\s+(\d+)*/) {
        $sIMisses = $1;
    }
    if (/^15 Graduated instructions......................................\s+(\d+)*/) {
        $instCount = $1;
    }
    if (/^18 Graduated loads.............................................\s+(\d+)*/) {
        $loadCount = $1;
    }
    if (/^19 Graduated stores............................................\s+(\d+)*/) {
        $storeCount = $1;
    }
    if (/^21 Graduated floating point instructions.......................\s+(\d+)*/) {
        $fpInstCount = $1;
    }
    if (/^23 TLB misses..................................................\s+(\d+)*/) {
        $tlbCount = $1;
    }
    if (/^24 Mispredicted branches.......................................\s+(\d+)*/) {
        $mispredictedBranches = $1;
    }
    if (/^25 Primary data cache misses...................................\s+(\d+)*/) {
        $pDMisses = $1;
    }
    if (/^26 Secondary data cache misses.................................\s+(\d+)*/) {
        $sDMisses = $1;
    }   
}


$totalDRefs = $loadCount + $storeCount;
$totalIRefs = $instCount;
$totalRefs  = $totalDRefs + $totalIRefs;
$sMisses    = $sDMisses + $sIMisses;

&DO_HEADER_INFO();

&DO_SUMMARY_STATS();

exit(0);


#################################################################
# Procedures that manipulate and print the scanned in numbers
#################################################################

sub numerically { $a <=> $b;}

sub div {
    my $x = shift;
    my $y = shift;

    if ($y == 0) {
        return 0.0;
    } else {
        return $x/$y;
    }
}

sub DO_HEADER_INFO {
    printf("****************************\n");
    printf("* PERFEX SIMULATION RESULTS *\n");
    printf("****************************\n\n");
}

sub DO_SUMMARY_STATS {
    printf("Total Instructions: %12.0lf\n", $instCount);
    printf("(Floating Point):   %12.0lf\n", $fpInstCount);

    printf("Total Cycles:       %12.0lf (%d seconds)\n", $cycleCount, 
           $cycleCount * .000000005);
    printf("CPI:                %12.2lf\n", &div($cycleCount, $instCount));
    printf("Data Cache Miss:    %12.2lf %%\n", 100.0 * &div($pDMisses, $totalDRefs));
    printf("Inst Cache Miss:    %12.2lf %%\n", 100.0 * &div($pIMisses, $totalIRefs));
    printf("L2 Cache Miss:      %12.2lf %%\n", 100.0 * &div($sMisses, $totalRefs));
    printf("Branch prediction:  %12.2lf %%\n", 
           100.0 * &div($mispredictedBranches, $branchCount));
    printf("TLB Miss every:     %12.0lf cycles\n", &div($cycleCount, $tlbCount));
}