-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgenerate_graph_inputs.pl
More file actions
executable file
·285 lines (244 loc) · 8.7 KB
/
generate_graph_inputs.pl
File metadata and controls
executable file
·285 lines (244 loc) · 8.7 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
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
#!/usr/bin/perl -w
if ($#ARGV!=6) {
print "usage: generate_graph_inputs.pl benchmark factors hw2kern kern2user callwrap baseline fpvm\n";
print <<ENDL
benchmark - name of benchmark
factors - string giving the factor combination
hw2kern - time in cycles for exception/trap to kernel
kern2user - time in cycles for kernel to user
callwrap - time in cycles for call wrapper overhead
(foreign call, magic trap)
baseline - output from fpvm_time.sh of original program
fpvm - output from fpvm_run.sh of patched program
You will see the following files. All files start with
a #-delimited comment that describes the columns. The files
are in tab-delimited column, newline-delimited row format.
benchmark.factors.timing.txt
a view of the overall execution time slowdowns and how
they decompose into user, sys, and realtime
benchmark.factors.amortcount.txt
a breakdown of the number of different events per emulated instruction
produced if telemetry is available (telemetry must be available)
benchmark.factors.amortcost.txt
a breakdown of the number of cycles spent on different events
per emulated instruction
produced if telemetry and perf data is available
The above three files are intended to be concatenatable to be
able to produce data for charts showing multiple benchmarks.
benchmark.factors.tracerank.txt
rank-popularity graph data for instruction sequence length
produced if trace data is available
benchmark.factors.tracehist.txt
histogram of instruction sequence length
produced if trace data is available
ENDL
;
exit -1;
}
$benchmark=shift;
$factors=shift;
$hw_to_kernel=shift;
$kernel_to_user=shift;
$call_wrap=shift;
$baseout=shift;
$out=shift;
$stem = "$benchmark.$factors";
$timing = "$stem.timing.txt";
$amortcost = "$stem.amortcost.txt";
$amortcount = "$stem.amortcount.txt";
$tracehist = "$stem.tracehist.txt";
$tracerank = "$stem.tracerank.txt";
my $have_timing=0;
my $have_telem=0;
my $have_perf=0;
my $have_trace=0;
(-e $out) or die "cannot find $out\n";
# must have timing
open(B,$baseout) or die "cannot open $baseout\n";
@basedata=<B>; print STDERR "Loaded ".($#basedata+1)." base data lines\n";
close(B);
open(O,$out) or die "cannot open $out\n";
@data=<O>; print STDERR "Loaded ".($#data+1)." fpvm data lines\n";
close(O);
%time_base = get_timing(\@basedata);
%time_fpvm = get_timing(\@data);
$have_timing = 1;
open(G,">$timing") or die "cannot open $timing\n";
print G "".join("\t","benchmark", "factors", "base_real","base_user","base_sys","base_sum","fpvm_real","fpvm_user","fpvm_sys","fpvm_sum","slowdown_real","slowdown_user","slowdown_sys", "slowdown_sum")."\n";
print G join("\t", $benchmark, $factors, $time_base{real}, $time_base{user}, $time_base{sys},$time_base{sum},$time_fpvm{real},$time_fpvm{user},$time_fpvm{sys},$time_fpvm{sum},div_clamp($time_fpvm{real},$time_base{real}),div_clamp($time_fpvm{user},$time_base{user}),div_clamp($time_fpvm{sys},$time_base{sys}),div_clamp($time_fpvm{sum},$time_base{sum})),"\n";
close(G);
print STDERR "Generating overall timing comparison in $timing\n";
%tel_fpvm = get_telemetry(\@data);
$have_telem=1;
if ($have_telem) {
print STDERR "Found telemetry data\n";
#print STDERR join("\n",map { " $_ => $tel_fpvm{$_}" } keys %tel_fpvm),"\n";
}
if ($have_telem) {
print STDERR "Generating overall amortized counts in $amortcount\n";
open(G,">$amortcount") or die "cannot open $amortcount\n";
print G "".join("\t","benchmark", "factors", "fptraps", "promotions", "clobbers", "demotions", "correctnesstraps", "foreigncalls", "correctnessdemotions"),"\n";
$numinst=$tel_fpvm{instructionsemulated};
print G join("\t",
$benchmark,
$factors,
div_clamp($tel_fpvm{fptraps},$numinst),
div_clamp($tel_fpvm{promotions},$numinst),
div_clamp($tel_fpvm{clobbers},$numinst),
div_clamp($tel_fpvm{demotions},$numinst),
div_clamp($tel_fpvm{correctnesstraps},$numinst),
div_clamp($tel_fpvm{correctnessforeigncalls},$numinst),
div_clamp($tel_fpvm{correctnessdemotions},$numinst)
), "\n";
close(G);
}
eval { %perf_fpvm = get_performance(\@data); };
$have_perf=1 if !$@;
if ($have_perf) {
print STDERR "Found performance data\n";
# foreach $c (keys %perf_fpvm) {
# print STDERR " $c:\n".join("\n",map { " $_ => $perf_fpvm{$c}{$_}" } keys %{$perf_fpvm{$c}}),"\n";
# }
} else {
print STDERR "No performance data available\n";
}
if ($have_perf) {
# generate performance breakdown data
print STDERR "Generating overall amortized costs in $amortcost\n";
open(G,">$amortcost") or die "cannot open $amortcost\n";
print G "".join("\t","benchmark", "factors", "hardware", "kernel", "decodecache", "decoder", "binder", "emulator", "garbage", "foreigncall", "correcttrap","total")."\n";
print G join("\t", $benchmark, $factors)."\t";
$numfpe=$tel_fpvm{fptraps};
$numcor=$tel_fpvm{correctnesstraps};
$numfor=$tel_fpvm{correctnessforeigncalls};
$numinst=$tel_fpvm{instructionsemulated};
$hw = div_clamp($hw_to_kernel*$numfpe,$numinst);
$kern = div_clamp($kernel_to_user*$numfpe,$numinst);
$decache = div_clamp($perf_fpvm{decodecache}{sum},$numinst);
$decode = div_clamp($perf_fpvm{decoder}{sum},$numinst);
$bind = div_clamp($perf_fpvm{bind}{sum},$numinst);
$emul = div_clamp($perf_fpvm{emulate}{sum},$numinst);
$gc = div_clamp($perf_fpvm{garbagecollector}{sum},$numinst);
$fcall = div_clamp($perf_fpvm{foreigncall}{sum}+$call_wrap*$numfor,$numinst);
$corr = div_clamp($perf_fpvm{correctness}{sum}+($hw_to_kernel+$kernel_to_user)*$numcor,$numinst);
$total = $hw+$kern+$decache+$decode+$bind+$emul+$gc+$fcall+$corr;
print G join("\t",$hw,$kern,$decache,$decode,$bind,$emul,$gc,$fcall,$corr,$total)."\n";
close(G);
}
$have_trace = check_for_trace(\@data);
if ($have_trace) {
print STDERR "Found trace data\n";
print STDERR "Generating trace histogram and ranks\n";
handle_trace(\@data,$benchmark,$factors,$tracerank,$tracehist);
}
print "Done.\n";
sub div_clamp {
my ($a,$b)=@_;
if ($b!=0) {
return $a/$b;
} else {
return 0;
}
}
sub get_timing {
my ($dr)=@_;
foreach my $l (@{$dr}) {
# print $l if $l=~/^fpvm\s+time"/;
if ($l=~/^fpvm\s+time:\s+real\s+(\S+)\s+user\s+(\S+)\s+sys\s+(\S+)$/) {
return (real => $1, user => $2, sys => $3, sum => ($2 + $3));
}
}
die "cannot find timing info\n";
}
sub get_telemetry {
my ($dr)=@_;
my %h;
foreach my $l (@{$dr}) {
if ($l=~/^fpvm\s+info\(.*\):\s+telemetry:\s+(\S.*)$/) {
my @pieces = split(/,/,$1);
foreach my $p (@pieces) {
$p=~/\s*(\S+)\s+(\S.*)/;
my $n = $1;
my $field=$2;
$field=~s/\s//g;
$field=~s/\(.*\)//g;
$h{$field}=$n;
}
return %h;
}
}
die "cannot find telemetry\n";
}
sub get_performance {
my ($dr)=@_;
my %h;
my $found=0;
foreach my $l (@{$dr}) {
if ($l=~/^fpvm\s+info\(.*\):\s+perf:\s+(\S.*) :\s+(\S.*)$/) {
my $comp=$1;
my @pieces = split(/\s+/,$2);
$comp=~s/\s+//g;
foreach my $p (@pieces) {
my ($field, $val) = split(/=/,$p);
$h{$comp}{$field}=$val;
}
# compute avg, stddev ourselves just in case
if ($h{$comp}{count}==0) {
$h{$comp}{avg} = 0.0;
$h{$comp}{std} = 0.0;
$h{$comp}{min} = 0;
$h{$comp}{max} = 0;
} else {
$h{$comp}{avg} = $h{$comp}{sum}/$h{$comp}{count};
$h{$comp}{std} = sqrt($h{$comp}{sum2}/$h{$comp}{count}
- $h{$comp}{avg}*$h{$comp}{avg});
}
$found=1;
}
}
die "cannot find telemetry\n" if !$found;
return %h;
}
sub check_for_trace {
my ($dr)=@_;
foreach my $l (@{$dr}) {
if ($l=~/^fpvm\s+info\(.*\):\s+trace:\s+TRACE STATS BEGIN$/) {
return 1;
}
}
return 0;
}
sub handle_trace {
my ($dr, $bm, $fa, $tr, $tl) = @_;
my $i;
for ($i=0;$i<=$#{$dr};$i++) {
last if ($dr->[$i]=~/^fpvm\s+info\(.*\):\s+trace:\s+trace rank popularity:$/);
}
$i++;
open(G,">$tr") or die "cannot open $tr\n";
print G "benchmark\tfactors\trank\tcumprob\tprob\tcount\tlength\n";
for (;$i<=$#{$dr};$i++) {
if ($dr->[$i]=~/rank\s+(\d+)\s+->\s+(\d+)\s\((\S+)\%\s+(\S+)\%\)\s+\[length\s+(\d+)\]/) {
my ($r,$n,$p,$cp,$len) = ($1,$2,$3,$4,$5);
print G join("\t", $bm, $fa, $r, $cp, $p, $n, $len),"\n";
} else {
last;
}
}
close(G);
for (;$i<=$#{$dr};$i++) {
last if ($dr->[$i]=~/^fpvm\s+info\(.*\):\s+trace:\s+trace length popularity:$/);
}
$i++;
open(G,">$tl") or die "cannot open $tl\n";
print G "benchmark\tfactors\tlength\tcumprob\tprob\tcount\n";
for (;$i<=$#{$dr};$i++) {
if ($dr->[$i]=~/length\s+(\d+)\s+->\s+(\d+)\s\((\S+)\%\s+(\S+)\%\)/) {
my ($len,$n,$p,$cp) = ($1,$2,$3,$4);
print G join("\t", $bm, $fa, $len, $cp, $p, $n),"\n";
} else {
last;
}
}
close(G);
}