printTree 2.04 KB
#!/usr/local/bin/perl5 -w
#
# 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. 
#
#
 
if (defined($ENV{'SIMTOOLS'})) { 
    unshift(@INC,"$ENV{'SIMTOOLS'}/apps/scripts");
}

require "tree.prl";

$inputFile  = "cpu.log";
$startNode  = "ROOT";
$targetTree = "modes";
    
$i=0;
while ($i<=$#ARGV) {
    if ($ARGV[$i] eq "-f") {
        $i++;
        $inputFile = $ARGV[$i++];
        
    } elsif ($ARGV[$i] eq "-s") {
        $i++;
        $startNode = $ARGV[$i++];
        
    } elsif ($ARGV[$i] eq "-t") {
        $i++;
        $targetTree = $ARGV[$i++];
        
    } else {
        print "usage: printTree [-f file] [-s node] [-t tree]\n";
        exit;
    }
}


$tree  = ParseTree($inputFile, $targetTree);
$total = TotalTree($tree, $startNode);

printTree($tree);

sub printTree {
    ($tree) = @_;

    foreach $state (keys %$tree) {
        ComputeDerivedFields($tree->{$state});
    }
    printHeader();
    foreach $state (sort bycomp (keys %$tree)) {
        printService($tree->{$state});
    }
}

sub printHeader {
        printf("%s %42s %6s %7s %10s\n", 
               "Name", "%Total", "%Kern", "Count", "Avg.Lat");
        printf("----------------------------------------------");
        printf("---------------------------\n");
}

sub printService {
    my($bucket) = @_;
    my($service) = PhaseName($bucket->{"name"});

    if ($service eq "DESCHED") {
        return;
    }
    
    if ($bucket->{'n'}) {
        $avg = $bucket->{'_cycles'}/$bucket->{'n'};
    } else {
        $avg = 0;
    }
    if ($total->{'_cycles'} != 0) {
        printf "%-40s %5.1f%% %5.1f%% %7d %10.2f\n", 
        $bucket->{"name"}, 
        100.0*$bucket->{'_cycles'}/($total->{'_cycles'}),
        100.0*$bucket->{'_cycles'}/($total->{'_cycles'}-$tree->{'ROOT'}{'_cycles'}),
        $bucket->{'n'}, $avg;
    } else {
        printf "%-40s NO TIME\n", $bucket->{"name"};
    }
}

sub bycomp {
    $tree->{$b}{'_cycles'} <=> $tree->{$a}{'_cycles'};
}