-
Notifications
You must be signed in to change notification settings - Fork 1
/
s370_perf_sum
executable file
·359 lines (325 loc) · 10.4 KB
/
s370_perf_sum
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
#!/usr/bin/perl -w
# $Id: s370_perf_sum 1195 2019-07-20 08:05:15Z mueller $
# SPDX-License-Identifier: GPL-3.0-or-later
# Copyright 2017-2018 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
#
# Revision History:
# Date Rev Version Comment
# 2018-10-27 1061 1.1.2 add and use bailout()
# 2018-05-10 1018 1.1.1 use median rather average for w50 summary
# 2018-04-28 1013 1.1 drop -ins; add -k, -r, -i;
# 2018-04-22 1012 1.0.9 allow 3 digit nt count
# 2018-03-29 1002 1.0.8 add -ins (instruction name sorted output)
# 2018-03-10 999 1.0.7 print essential options; print file stats, w50 ect
# 2018-03-03 996 1.0.6 add -rat option
# 2018-02-23 994 1.0.5 add -fmis and -fsig options
# 2018-01-28 991 1.0.4 allow extra columns in input files (e.g. from -cp)
# 2018-01-13 989 1.0.3 handle negative times (even though they are faulty!)
# 2018-01-06 986 1.0.2 rename to s370_perf_sum
# 2017-12-02 967 1.0.1 fix 'overwrite' message
# 2017-11-18 963 1.0 Initial version
# 2017-11-16 962 0.1 First draft
#
use 5.14.0; # require Perl 5.14 or higher
use strict; # require strict checking
use Getopt::Long;
my %opts = ();
my %tags;
my %ftbl;
my $nfile = 0;
GetOptions(\%opts,
'help', 'nrr', 'nrx', 'min', 'w50', 'rel','rat',
'fsig:1','fmis:1',
'k=s','r','i'
)
or bailout("bad command options");
# handle help
if (defined $opts{help}) { do_help(); exit 0; }
# check key validity
my $key = $opts{k} || 'tag';
if ($key eq 'tag' || $key eq 'ins') {
if ($opts{r}) {
printf "s370_perf_sum-E -r only supported for -k vN or -k RN\n";
exit 1;
}
} else {
if ($key =~ m/([vr])(\d+)/) {
my $typ = $1;
my $num = $2;
$key = sprintf '%s%02d',$typ,$num;
if ($typ eq 'r' and not $opts{rat}) {
printf "s370_perf_sum-E bad key '%s', works only with -rat\n", $opts{k};
exit 1;
}
if ($num > scalar @ARGV) {
printf "s370_perf_sum-E bad key '%s', only %d files\n",
$opts{k}, scalar @ARGV;
exit 1;
}
if ($typ eq 'r' && $num == 1) {
printf "s370_perf_sum-E bad key '%s', must be 'r2' or higher\n",$opts{k};
exit 1;
}
} else {
printf "s370_perf_sum-E bad key '%s', use tag,ins,vN,rN (N=integer)\n",
$opts{k};
exit 1;
}
}
#
# print essential options
#
my $opttxt;
$opttxt .= ' -nrr' if exists $opts{nrr};
$opttxt .= ' -nrx' if exists $opts{nrx};
$opttxt .= ' -min' if exists $opts{min};
$opttxt .= ' -w50' if exists $opts{w50};
$opttxt .= ' -rel' if exists $opts{rel};
$opttxt .= ' -rat' if exists $opts{rat};
$opttxt .= ' -k ' . $opts{k} if exists $opts{k};
$opttxt .= ' -r ' if exists $opts{r};
$opttxt .= ' -i ' if exists $opts{i};
$opttxt .= ' -fsig ' . $opts{fsig} if exists $opts{fsig};
$opttxt .= ' -fmis ' . $opts{fmis} if exists $opts{fmis};
printf "s370_perf_sum%s\n\n",$opttxt if defined $opttxt;
#
# handle input files
#
foreach my $fname (@ARGV) {
$nfile += 1;
my $fnum = sprintf '%02d',$nfile;
$ftbl{$fnum}{fname} = $fname;
do_file($fnum, $fname);
}
my @fnums = sort keys %ftbl;
do_anal();
do_show();
exit 0;
#
# -- bailout : end with fatal error ------------------------------------------
#
sub bailout {
my ($msg) = @_;
print STDERR "s370_perf_sum-F: $msg\n";
exit 1;
}
#
# -- do_help: print help text ------------------------------------------------
#
sub do_help {
print "usage: s370_perf_sum [OPTIONS] [FILE]...\n";
print " -nrr use n-rr (T100 normalized)\n";
print " -nrx use n-rx (T102 normalized)\n";
print " -min use min (minimal time)\n";
print " -w50 use w50 (50% distribution width)\n";
print " -rel show relative speed for each tag\n";
print " -rat show in addition ratios relative to 1st file\n";
print " -fmis[=n] drop test line when n values missing\n";
print " -fsig[=n] show test line only when differing by n percent\n";
print " -k key select sort criterion\n";
print " -r reverse sorting order\n";
print " -i select instruction time lines\n";
print " -help help text\n";
print "supported keys:\n";
print " tag test tag, usually the input order of files\n";
print " ins instruction code\n";
print " vN value of N'th file, e.g. v1,v2,...\n";
print " rN ratio for N'th file, e.g. r2,...\n";
return;
}
#
# -- do_file: handle input file ----------------------------------------------
#
sub do_file {
my ($fnum,$fname) = @_;
open IFILE,"<$fname" or bailout("failed to open $fname: $!");
my $ntest = 0;
my $tpisum = 0.;
my @w50df;
while (<IFILE>) {
chomp;
if (m/^([DT]\d\d\d)\s+ # tag
(.*?)\s+:\s* # txt
(\d+)\s+ # nt
(-|[0-9.]+)\s+ # min
(-|[0-9.]+)\s+ # max
(-?[0-9.]+)\s+ # tpi
([0-9.]+)%\s+ # w50
(-?[0-9.]+)\s+ # nrr
(-?[0-9.]+)/x) { # nrx
my $tag = $1;
my $txt = $2;
my $nt = $3;
my $min = ($4 ne '-') ? $4 : undef;
my $max = ($5 ne '-') ? $5 : undef;
my $tpi = $6;
my $w50 = $7;
my $nrr = $8;
my $nrx = $9;
## printf "%s %-22s : %8.2f\n",$tag,$txt,$tpi;
my $val = $tpi;
$val = $nrr if $opts{nrr};
$val = $nrx if $opts{nrx};
$val = $min if $opts{min};
$val = $w50 if $opts{w50};
$ntest += 1;
$tpisum += $tpi;
push @w50df, $w50;
#
if (exists $tags{$tag}{txt} && $tags{$tag}{txt} ne $txt) {
printf STDERR "s370_perf_sum-W file '%s' overwrites text for tag '%s'\n",
$fnum, $tag;
printf STDERR " old: %s\n", $tags{$tag}{txt};
printf STDERR " new: %s\n", $txt;
}
$tags{$tag}{tag} = $tag;
$tags{$tag}{txt} = $txt;
$tags{$tag}{'v'.$fnum} = $val;
if (($tag !~ m/^T9\d\d/ && $txt !~ m/;/) && $txt =~ m/(^[A-Z]+)/) {
$tags{$tag}{ins} = $1;
}
}
}
$ftbl{$fnum}{ntest} = $ntest;
$ftbl{$fnum}{w50max} = 0.;
$ftbl{$fnum}{w50med} = 0.;
if (scalar @w50df) {
my @dfsort = sort {$a <=> $b} @w50df;
$ftbl{$fnum}{w50med} = df_lookup(\@dfsort, 0.50);
$ftbl{$fnum}{w50max} = $dfsort[-1];
}
close IFILE;
return;
}
#
# -- do_anal: analyse data ---------------------------------------------------
#
sub do_anal {
foreach my $tag (keys %tags) {
my @vals;
foreach my $fnum (@fnums) {
push @vals, $tags{$tag}{'v'.$fnum};
}
# determine minimal value
my $vmin = 1.e20;
foreach my $fnum (@fnums) {
my $val = $tags{$tag}{'v'.$fnum};
$vmin = $val if defined $val && $val > 0. && $val < $vmin;
}
# normalized (if -rel); check fsig
my $nmis = 0;
my $nsig = 0;
my $vtxt = '';
foreach my $fnum (@fnums) {
my $val = $tags{$tag}{'v'.$fnum};
if (defined $val) {
if ($val > 0.) {
my $vnor = $val/$vmin;
$nsig += 1 if defined $opts{fsig} && $vnor >= 1. + 0.01 * $opts{fsig};
$vtxt .= sprintf ' %9.2f', ($opts{rel} ? $vnor : $val);
} else {
$vtxt .= ' <=0';
}
} else {
$nmis += 1;
$vtxt .= ' -';
}
}
$tags{$tag}{vtxt} = $vtxt;
$tags{$tag}{nmis} = $nmis;
$tags{$tag}{nsig} = $nsig;
# determine ratios (if -rat)
if ($opts{rat}) {
my $rtxt = '';
my $val0 = $tags{$tag}{'v'.$fnums[0]};
foreach my $fnum (@fnums[1..$#fnums]) {
my $val = $tags{$tag}{'v'.$fnum};
if (defined $val0 && defined $val) {
if ($val0 > 0. && $val > 0.) {
my $rat = $val/$val0;
$tags{$tag}{'r'.$fnum} = $rat;
$rtxt .= sprintf ' %8.3f', $rat;
} else {
$rtxt .= ' <=0';
}
} else {
$rtxt .= ' -';
}
}
$tags{$tag}{rtxt} = $rtxt;
}
}
}
#
# -- do_show: print output ---------------------------------------------------
#
sub do_show {
print "File num: name ----------------------------------- ".
"#test w50-med w50-max\n";
foreach my $fnum (@fnums) {
printf " %s: %-40s %4d %6.2f%% %6.1f%%\n",
$fnum,
$ftbl{$fnum}{fname},
$ftbl{$fnum}{ntest},
$ftbl{$fnum}{w50med},
$ftbl{$fnum}{w50max};
}
printf "\n";
my $vnam = ' tpi';
$vnam = ' nrr' if $opts{nrr};
$vnam = ' nrx' if $opts{nrx};
$vnam = ' min' if $opts{min};
$vnam = 'w50_' if $opts{w50};
printf "Tag Comment :";
foreach my $fnum (@fnums) {
printf ' %s%s%s', ($opts{rel}?'r-':' '),$vnam,$fnum;
}
if ($opts{rat}) {
printf ' :';
foreach my $fnum (@fnums[1..$#fnums]) {
printf ' t%s/t01',$fnum;
}
}
printf "\n";
# ensure sort key present and presort in tag
my @tlist = map {s/^Z/D/;$_} sort map {s/^D/Z/;$_}
grep {defined $tags{$_}{$key}} keys %tags;
# select instruction time lines if -i given
@tlist = grep {defined $tags{$_}{ins}} @tlist if $opts{i};
# handle -k=ins
if ($key eq 'ins') {
@tlist = sort { $tags{$a}{$key} cmp $tags{$b}{$key} } @tlist;
# handle -k=vnn or -k=rnn
} elsif (defined $opts{k} && $opts{k} =~ m/[vr]\d+/) {
unless ($opts{r}) {
@tlist = sort { $tags{$a}{$key} <=> $tags{$b}{$key} ||
$tags{$a}{tag} cmp $tags{$b}{tag} } @tlist;
} else {
@tlist = sort { $tags{$b}{$key} <=> $tags{$a}{$key} ||
$tags{$a}{tag} cmp $tags{$b}{tag} } @tlist;
}
}
foreach my $tag (@tlist) {
next if defined $opts{fmis} && $tags{$tag}{nmis} >= $opts{fmis};
next if defined $opts{fsig} && $tags{$tag}{nsig} == 0;
printf '%s %-22s :%s', $tag,$tags{$tag}{txt},$tags{$tag}{vtxt};
printf ' :%s',$tags{$tag}{rtxt} if defined $tags{$tag}{rtxt};
print "\n";
}
return;
}
#
# -- df_lookup: lookup df ----------------------------------------------------
#
sub df_lookup {
my ($df,$frac) = @_;
my $nval = scalar(@{$df});
return 0. if $nval == 0;
return $df->[0] if $nval == 1;
my $imax = $nval - 1;
my $rind = $frac * $imax;
my $ind = int $rind;
return $df->[$ind] if $ind == $imax;
my $find = $rind - $ind;
return (1.-$find)*$df->[$ind] + $find*$df->[$ind+1];
}