printTree
2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/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'};
}