semastats.prl
3.08 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/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.
#
%semaInfo = ();
$inputFile = "cpu.log";
$numsemas = -1;
$found = 0;
$i=0;
while ($i<=$#ARGV) {
if ($ARGV[$i] eq "-f") {
$i++;
$inputFile = $ARGV[$i];
} elsif ($ARGV[$i] eq "-l") {
$i++;
$showSema{$ARGV[$i]} = 1;
} elsif ($ARGV[$i] eq "-n") {
$i++;
$numsemas = $ARGV[$i];
} else {
print "usage: semastats [-f file] [-l sema] [-n numsemas]\n";
exit;
}
$i++;
}
open(LOGFILE, $inputFile);
while (<LOGFILE>) {
if (/^SEMASTATS: \s+ start/x) {
undef %semaInfo;
$total = 0;
$found++;
} elsif (/^SEMASTATS:\s+sema\s+(\S+)\s+n\s+(\d+)\s+sumX\s+(\S+)\s+sumY\s+\S+\s+sumXX\s+(\S+)\s+sumYY\s+\S+\s+sumXY\s+\S+\s+minX\s+(\S+)\s+maxX\s+(\S+)\s+minY\s+\S+\s+maxY\s+\S+\s+/) {
$sema = $1;
$total += $3;
$semaInfo{$sema}{'name'} = $sema;
$semaInfo{$sema}{'nwait'} = $2;
$semaInfo{$sema}{'totwait'} = $3;
$semaInfo{$sema}{'sqwait'} = $4;
$semaInfo{$sema}{'minwait'} = $5;
$semaInfo{$sema}{'maxwait'} = $6;
if (!defined($semaInfo{$sema}{'iname'})) {
$semaInfo{$sema}{'iname'} = "";
$semaInfo{$sema}{'caller'} = "";
}
} elsif (/^SEMAINIT:\s+(\S+)\s+\S+\s+\S+\s+(\S+)\s+(\S+)/) {
$sema = $1;
$semaInfo{$sema}{'iname'} = $2;
$semaInfo{$sema}{'caller'} = $3;
$semaInfo{$sema}{'name'} = $sema;
$semaInfo{$sema}{'nwait'} = 0;
$semaInfo{$sema}{'totwait'} = 0;
$semaInfo{$sema}{'sqwait'} = 0;
$semaInfo{$sema}{'minwait'} = 0;
$semaInfo{$sema}{'maxwait'} = 0;
}
}
close(LOGFILE);
if (!$found) {
print "FATAL ERROR: no semastats stuff found, you must not have source'd sema_stats.tcl\n";
}
$num = 0;
printHeader();
foreach $sema (sort bywait (keys %semaInfo)) {
if ($semaInfo{$sema}{'nwait'} == 0) {
next;
}
$num++;
if (($numsemas != -1) && defined(%showSema)) {
if (($num > $numsemas) && !defined($showSema{$sema})) {
next;
}
} elsif (($numsemas != -1) && ($num > $numsemas)) {
next;
} elsif (defined(%showSema) && !defined($showSema{$sema})) {
next;
}
printSema($semaInfo{$sema}, $num, "");
}
sub bywait {
$semaInfo{$b}{'totwait'} <=> $semaInfo{$a}{'totwait'};
}
sub printHeader {
printf "%-4s %-15s %6s %7s %-15s %-10s %-15s\n",
"num", "sema",
"% of sema", "count", "wait", "Name", "Init";
print "-----------------------------------------------------------------------------\n";
}
sub printSema {
my($bucket, $num, $prefix) = @_;
printf "%-4s %-15s %6.2f %7d %15.2f %-10s %-15s\n",
$num,
"$bucket->{'name'}", (100.0 * $bucket->{'totwait'}) / $total, $bucket->{'nwait'},
$bucket->{'totwait'} / $bucket->{'nwait'}, $bucket->{'iname'}, $bucket->{'caller'};
}