lathist.prl
3.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
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.
#
#
# Generate a simple autoscaling histogram of the length of an
# interval between two log annotation labels.
#
# args start_label end_label [matchsymbol] [logfile name]
#
# The labels can be anywhere on the LOG line.
# If the matchsymbol is present, it chucks out any lines which
# don't match. I use this to restrict to a single process.
#
die if $#ARGV < 1;
$startsymbol = $ARGV[0];
$endsymbol = $ARGV[1];
if ($#ARGV > 1) {
$matchsymbol = $ARGV[2];
} else {
$matchsymbol = "";
}
if ($#ARGV > 2) {
$fname = $ARGV[3];
} else {
$fname = "./cpu.log";
}
open (CPULOG, $fname);
$expectingstart = 1;
$callnum = 0;
$totlat = 0;
while (<CPULOG>) {
$line = $_;
next if ! /^LOG/o;
if ($matchsymbol) { next if ! /$matchsymbol/o; }
if (/$startsymbol/o) {
if (! $expectingstart) {
print "Warning unexpected function start at line ", $., "\n";
}
$line =~ /^LOG (\d+)/;
$startcycle = $1;
$expectingstart = 0;
} elsif (/$endsymbol/o) {
if ($expectingstart) {
print "Warning unexpected function end at line ", $., "\n";
} else {
$line =~ /^LOG (\d+)/;
$expectingstart = 1;
$latency[$callnum] = $1 - $startcycle;
$totlat += $latency[$callnum];
$callnum++;
}
}
}
sub bynumber {$a <=> $b; }
@sortedlats = sort bynumber @latency;
print "range from $startsymbol to $endsymbol";
if ($matchsymbol) {print " when line includes $matchsymbol";}
print "\n";
print "num ranges = ", $#sortedlats+1, "\n";
printf "average latency = %.2f cycles\n", $totlat / $callnum;
$nbuckets = 30;
$minval = $sortedlats[0];
$maxval = $sortedlats[$#sortedlats];
print "min = ", $minval, "\n";
print "max = ", $maxval, "\n";
$ival = ($maxval - $minval) / $nbuckets;
# round ival up to nearest x * 10^n value where x in 1..9
$logten = int(log($ival) / log(10));
$base = exp($logten * log(10));
$ival = $base * (int($ival/$base)+1);
# initial bucket always empty
$cbucket = $ival * int($minval/$ival);
$j = 0;
$maxsize = 0;
for ($i=0; $i<$nbuckets && $j <= $#sortedlats; $i++) {
$count = 0;
while ($sortedlats[$j] < $cbucket) {
$count++;
$j++;
last if ($j > $#sortedlats);
}
$bucketsize[$i] = $count;
$bucketlabel[$i] = $cbucket;
if ($bucketsize[$i] > $maxsize) {
$maxsize = $bucketsize[$i];
}
$cbucket += $ival;
}
$lastbucket = $i-1;
$ovflwsize = $#sortedlats - $j + 1;
if ($ovflwsize > $maxsize) {
$maxsize = $ovflwsize;
}
$xscale = int($maxsize/60)+1;
print "Each * represents up to $xscale occurrences\n\n";
for ($i=0; $i<=$lastbucket; $i++) {
printf "%8d %s\n", $bucketlabel[$i], "*" x (1+(($bucketsize[$i]-1)/$xscale));
}
printf "%8s %s\n", "ovflw", "*" x (1+(($ovflwsize - 1)/$xscale));
print "\n";
# print join(' ', @sortedlats);