Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | ################################################################################ |
2 | # returns the cycles per second of a cmp simulation run | |
3 | # usage: perf [directory] | |
4 | # | |
5 | # perf - expect one sim.log in the current directory | |
6 | # perf dir - expect a regression to have been run in dir | |
7 | # and average out all the sim.logs | |
8 | # perf dir -group=<GROUP> - only select the diags from <GROUP> | |
9 | # in the run directory | |
10 | ################################################################################ | |
11 | ||
12 | use Getopt::Long ; | |
13 | use Cwd; | |
14 | use Cwd 'chdir'; | |
15 | ||
16 | my $reg_dir ; | |
17 | my $force = 0 ; | |
18 | my $group ; | |
19 | my $total_cycles = 0 ; | |
20 | my $total_delta = 0 ; | |
21 | my $total_cps = 0 ; | |
22 | my $total_cpu_cps = 0 ; | |
23 | my $total_diags = 0 ; | |
24 | ||
25 | foreach my $argv (@ARGV) | |
26 | { | |
27 | if ($argv =~ /-force/) | |
28 | { | |
29 | $force = 1 ; | |
30 | } | |
31 | elsif ($argv =~ /-group/) | |
32 | { | |
33 | $group = $argv ; | |
34 | $group =~ s/-group=(.*)/$1/ ; | |
35 | } | |
36 | elsif (($argv =~ /-h/) or ($argv =~ /-help/)) | |
37 | { | |
38 | &usage ; | |
39 | exit (0) ; | |
40 | } | |
41 | else | |
42 | { | |
43 | $reg_dir = $argv ; | |
44 | } | |
45 | } | |
46 | ||
47 | # open the directory where the diags are | |
48 | ||
49 | if (defined $reg_dir) | |
50 | { | |
51 | opendir (DIR, "$reg_dir") ; | |
52 | my @dir = readdir (DIR) ; | |
53 | close (DIR) ; | |
54 | ||
55 | chdir $reg_dir ; | |
56 | ||
57 | foreach my $dir (@dir) | |
58 | { | |
59 | next if (($dir eq ".") or ($dir eq "..")) ; | |
60 | next if ((defined $group) and ($dir !~ /:$group:/)) ; | |
61 | next if (! -d $dir) ; | |
62 | ||
63 | chdir "$dir" ; | |
64 | ||
65 | if (((-f "perf.log") or (-f "perf.log.gz")) and (!$force)) | |
66 | { | |
67 | print "Accumulating in $dir\n" ; | |
68 | $total_diags++ if (&accumulate (\$total_cycles, \$total_delta, \$total_cps, \$total_cpu_cps, $dir)) ; | |
69 | } | |
70 | elsif ((-f "sim.log") or ( -f "sim.log.gz")) | |
71 | { | |
72 | print "Calculating in $dir\n" ; | |
73 | $total_diags++ if (&calculate (\$total_cycles, \$total_delta, \$total_cps, \$total_cpu_cps, $dir)) ; | |
74 | } | |
75 | ||
76 | chdir ".." ; | |
77 | } | |
78 | ||
79 | chdir ".." ; | |
80 | ||
81 | print "Total Cycles = $total_cycles\tTotal Seconds = $total_delta\n" ; | |
82 | # my $hz = $total_cycles / $total_delta ; | |
83 | # print "Hz=$hz\n" ; | |
84 | print "Total Cycles per Second= $total_cps\tTotal CPU Cycles per Second= $total_cpu_cps\t\tTotal Diags = $total_diags\n" ; | |
85 | my $cps = 0 ; | |
86 | $cps = $total_cps / $total_diags if ($total_diags != 0) ; | |
87 | printf ("Wall Time CPS=%.2f\n", $cps) ; | |
88 | my $cpu_cps = 0 ; | |
89 | $cpu_cps = $total_cpu_cps / $total_diags if ($total_diags != 0) ; | |
90 | printf ("CPU Time CPS=%.2f\n", $cpu_cps) ; | |
91 | } | |
92 | else | |
93 | { | |
94 | my $dir = $ENV{PWD} ; | |
95 | $dir =~ s/.*\/// ; | |
96 | ||
97 | $total_diags++ if (&calculate (\$total_cycles, \$total_delta, \$total_cps, \$total_cpu_cps, $dir)) ; | |
98 | } | |
99 | ||
100 | exit (0) ; | |
101 | ||
102 | sub usage | |
103 | { | |
104 | print <<EOF; | |
105 | ||
106 | Calculates the cycles per second of a simulation run from the wall | |
107 | time of a simulation run and the simulation cycles reported by simulation. | |
108 | ||
109 | perf | |
110 | report the performance of diag run in current directory | |
111 | ||
112 | perf <DIR> | |
113 | report average performance of diags run in regression directory <DIR> | |
114 | ||
115 | perf -group=<GROUP> <DIR> | |
116 | report average performance of diags from group <GROUP> | |
117 | run in regression directory <DIR> | |
118 | ||
119 | perf -force <DIR> | |
120 | force recalculation of perf for each diag of a regression directory <DIR> | |
121 | even if perf.log is present. | |
122 | ||
123 | perf -help | |
124 | this | |
125 | ||
126 | EOF | |
127 | } | |
128 | ||
129 | sub accumulate | |
130 | { | |
131 | my $total_cycles = shift ; | |
132 | my $total_delta = shift ; | |
133 | my $total_cps = shift ; | |
134 | my $total_cpu_cps = shift ; | |
135 | my $dir = shift ; | |
136 | ||
137 | open (IN, "perf.log") or open (IN, "gzcat perf.log.gz |") or die "Could not open perf.log" ; | |
138 | $log = <IN> ; | |
139 | close (IN) ; | |
140 | ||
141 | return 0 if (! defined $log) ; | |
142 | ||
143 | my ($dummy, $start, $stop, $num_cycles, $delta, $cps, $cpu_cps, $cpu_freq) = ($log =~ /^(\S*)\s+(\S*)\s+(\S*)\s+(\S*)\s+(\S*)\s+(\S*)\s+(\S*)\s+(\S*)\s+/) ; | |
144 | ||
145 | if ( (defined $dir) and (defined $start) | |
146 | and (defined $stop) and (defined $num_cycles) | |
147 | and (defined $delta) and (defined $cps) and (defined $cpu_cps)) | |
148 | { | |
149 | print "$dir\t$start\t$stop\t$num_cycles\t$delta\t$cps\t$cpu_cps\t$cpu_freq\n" ; | |
150 | ${$total_cycles} += $num_cycles ; | |
151 | ${$total_delta} += $delta ; | |
152 | ${$total_cps} += $cps ; | |
153 | ${$total_cpu_cps} += $cpu_cps ; | |
154 | return 1 ; | |
155 | } | |
156 | ||
157 | return 0 ; | |
158 | } | |
159 | ||
160 | sub calculate | |
161 | { | |
162 | my $total_cycles = shift ; | |
163 | my $total_delta = shift ; | |
164 | my $total_cps = shift ; | |
165 | my $total_cpu_cps = shift ; | |
166 | my $dir = shift ; | |
167 | ||
168 | if (-e "sims.log") { open (IN, "sims.log") ; } | |
169 | elsif (-e "sims.log.gz") { open (IN, "gzcat sims.log.gz |") ; } | |
170 | elsif (-e "sim.perf.log") { open (IN, "sim.perf.log") ; } | |
171 | elsif (-e "sim.perf.log.gz") { open (IN, "gzcat sim.perf.log.gz |") ; } | |
172 | else { return 0 ; } | |
173 | ||
174 | my @log = <IN> ; | |
175 | close (IN) ; | |
176 | ||
177 | my ($start) = grep (/\ssim_start\s/, @log) ; | |
178 | my ($stop) = grep (/\ssim_stop\s/, @log) ; | |
179 | ||
180 | if (-e "sim.log") {open (IN, "head -500 sim.log |") or die "Could not open sim.log" ;} | |
181 | elsif (-e "sim.log.gz") {open (IN, "gzcat sim.log.gz | head -500 |") or die "Could not open sim.log.gz" ;} | |
182 | else {return 0 ;} | |
183 | @log = <IN> ; | |
184 | close (IN) ; | |
185 | ||
186 | my ($freq) = grep (/Selected\sCore\sClock\sFrequency\s\d+\sMHz/, @log) ; | |
187 | ||
188 | if (-e "sim.log") {open (IN, "tail -500 sim.log |") or die "Could not open sim.log" ;} | |
189 | elsif (-e "sim.log.gz") {open (IN, "gzcat sim.log.gz | tail -500 |") or die "Could not open sim.log.gz" ;} | |
190 | else {return 0 ;} | |
191 | @log = <IN> ; | |
192 | close (IN) ; | |
193 | ||
194 | my ($cycles) = grep (/Time:\s\d+\sps/, @log) ; | |
195 | my ($cpu_time) = grep (/CPU\sTime:\s+[.\d]+\sseconds/, @log) ; | |
196 | ||
197 | if ($start && $stop && $cycles && $freq && $cpu_time) | |
198 | { | |
199 | $start =~ s/.*?(\d+:\d+:\d+).*/$1/ ; | |
200 | $stop =~ s/.*?(\d+:\d+:\d+).*/$1/ ; | |
201 | $cycles =~ s/Time:\s(\d+)\sps/$1/ ; | |
202 | $freq =~ s/.*?(\d+).*/$1/ ; | |
203 | $cpu_time =~ s/CPU\sTime:\s+([.\d]+)\sseconds.*/$1/ ; | |
204 | $period = (1000000/$freq) ; | |
205 | $num_cycles = $cycles / $period ; | |
206 | chomp ($start) ; | |
207 | chomp ($stop) ; | |
208 | chomp ($cycles) ; | |
209 | chomp ($freq) ; | |
210 | chomp ($cpu_time) ; | |
211 | my ($hr, $min, $sec) = $start =~ /(\d+):(\d+):(\d+)/ ; | |
212 | my $start_sec = $hr * 60 * 60 + $min * 60 + $sec ; | |
213 | ($hr, $min, $sec) = $stop =~ /(\d+):(\d+):(\d+)/ ; | |
214 | my $stop_sec = $hr * 60 * 60 + $min * 60 + $sec ; | |
215 | my $delta ; | |
216 | ||
217 | if ($stop_sec >= $start_sec) | |
218 | { | |
219 | $delta = $stop_sec - $start_sec ; | |
220 | } | |
221 | else | |
222 | { | |
223 | $delta = $stop_sec + (86400 - $start_sec) ; | |
224 | } | |
225 | ||
226 | { | |
227 | use integer ; | |
228 | $hr = $delta / (60 * 60) ; | |
229 | $min = ($delta - ($hr * 60 * 60)) / 60 ; | |
230 | $sec = ($delta - ($hr * 60 * 60) - ($min * 60)) ; | |
231 | } | |
232 | ||
233 | my $cps = $num_cycles / $delta ; | |
234 | my $cpu_cps = $num_cycles / $cpu_time ; | |
235 | my $cpu_freq = cpuFreq () ; | |
236 | print "$dir\t$start\t$stop\t$num_cycles\t$delta\t$cps\t$cpu_cps\t$cpu_freq\n" ; | |
237 | ${$total_cycles} += $num_cycles ; | |
238 | ${$total_delta} += $delta ; | |
239 | ${$total_cps} += $cps ; | |
240 | ${$total_cpu_cps} += $cpu_cps ; | |
241 | return 1 ; | |
242 | } | |
243 | ||
244 | return 0 ; | |
245 | } | |
246 | ||
247 | sub cpuFreq { | |
248 | my @psrinfo = `psrinfo -v` ; | |
249 | my $val = 0 ; | |
250 | ||
251 | foreach my $x (@psrinfo) | |
252 | { | |
253 | if ($x =~ /processor\soperates\sat/) | |
254 | { | |
255 | $val = $x ; | |
256 | $val =~ s/.*?\sat\s(\d+)\sMHz,/$1/ ; | |
257 | chomp $val ; | |
258 | last ; | |
259 | } | |
260 | } | |
261 | ||
262 | return $val ; | |
263 | } | |
264 | ||
265 | ||
266 | sub cpuFreq2 { | |
267 | ||
268 | my $PRTDIAG_CMD = '/usr/platform/sun4u/sbin/prtdiag'; | |
269 | ||
270 | if ( ! -x $PRTDIAG_CMD ) { | |
271 | return -1; | |
272 | } | |
273 | my @lines = `$PRTDIAG_CMD`; | |
274 | my $inCpu = 0; | |
275 | my $fpos = -1; | |
276 | my $cpos = -1; | |
277 | my $parse = 0; | |
278 | my $freq = 0; | |
279 | my $cpu = ""; | |
280 | foreach my $line ( @lines ) { | |
281 | ||
282 | if ( $line =~ /== CPUs ===/ ) { | |
283 | $inCpu = 1; | |
284 | next; | |
285 | } | |
286 | ||
287 | if ( $inCpu && $line =~ /MHz/ ) { | |
288 | # find position of frequency | |
289 | my @words = split /\s+/, $line; | |
290 | for ( my $i = 0; $i < scalar @words; $i++ ) { | |
291 | if ( $words[$i] eq "MHz" ) { | |
292 | $fpos = $i; | |
293 | } elsif ( $words[$i] =~ /Impl/ ) { | |
294 | $cpos = $i; | |
295 | } | |
296 | } | |
297 | # fix case of a well-known multi-word title | |
298 | if ( $words[0] eq "FRU" && $words[1] eq "Name" ) { | |
299 | $fpos--; | |
300 | $cpos--; | |
301 | } | |
302 | next; | |
303 | } | |
304 | ||
305 | if ( $inCpu && ( $line =~ /^---/ ) ) { | |
306 | $parse = 1; | |
307 | next; | |
308 | } | |
309 | ||
310 | if ( $parse && ( $line =~ /\S+\s*\d+\s+(\d+)\s+\S+\s+(\S+)\s+\S+/ ) ) { | |
311 | $line =~ s/^\s*//; # skip any leading space | |
312 | my @words = split /\s+/, $line; | |
313 | $freq = $words[$fpos] if $fpos >= 0; | |
314 | $cpu = $words[$cpos] if $cpos >= 0; | |
315 | last; | |
316 | } | |
317 | } | |
318 | ||
319 | # printf "CPU: %s, frequency = %d MHz\n", $cpu, $freq; | |
320 | return $freq; | |
321 | ||
322 | } # cpuFreq | |
323 |