-
Notifications
You must be signed in to change notification settings - Fork 3
/
iperf-post-process
executable file
·446 lines (400 loc) · 18.6 KB
/
iperf-post-process
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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
#!/usr/bin/perl
## -*- mode: perl; indent-tabs-mode: nil; perl-indent-level: 4 -*-
## vim: autoindent tabstop=4 shiftwidth=4 expandtab softtabstop=4 filetype=perl
use strict;
use warnings;
use JSON::XS;
use Data::Dumper;
use Getopt::Long;
BEGIN {
if (!(exists $ENV{'TOOLBOX_HOME'} && -d "$ENV{'TOOLBOX_HOME'}/perl")) {
print "This script requires libraries that are provided by the toolbox project.\n";
print "Toolbox can be acquired from https://github.com/perftool-incubator/toolbox and\n";
print "then use 'export TOOLBOX_HOME=/path/to/toolbox' so that it can be located.\n";
exit 1;
}
}
use lib "$ENV{'TOOLBOX_HOME'}/perl";
use toolbox::json;
use toolbox::metrics;
my $protocol;
my $remotehost;
my $ignore;
# rx throughput is our primary_metric, but the unit is configureable
# by the "passthru" option which we donot know ahead of time.
# So we will init primary_metric when we examine the outputs.
my $primary_metric;
my $result_file = "iperf-client-result.txt";
my $final_hunt_result = "hunt-temp-result.txt";
my %names = ('cmd' => 'write');
my %desc;
my %s;
my $ts;
my $ts_end;
my %times;
my $duration;
my $hunting_mode=0;
# omit is a utility feature for re post-process and ignore a number of first second drops.
my $omit=0;
my $max_loss_pct=0;
use constant SEC_TO_MSEC => 1000;
use constant KBPS_TO_GBPS => 1000000;
my $debug;
sub debug_print {
if ( defined $debug ) {
print "$_[0]";
}
}
print "@ARGV\n";
GetOptions ("remotehost=s" => \$remotehost,
"length=s" => \$ignore,
"passthru=s" => \$ignore,
"protocol=s" => \$protocol,
"time=i" => \$duration,
"bitrate=s" => \$ignore,
"max-loss-pct=s" => \$max_loss_pct,
"ifname=s" => \$ignore,
"cpu-pin=s" => \$ignore,
"bitrate-range=s" => \$hunting_mode,
"omit=s" => \$omit
);
#
# process_proto - supports TCP and UDP.
# UDP stats: tx-UNIT/s, rx-UNITs, rx-lost/sec, rx-pps
# TCP stats: tx-UNIT/s, tx-retry/s, rx-Gbps
# Where UNIT: Gbits, Mbits, Kbits, GBytes, Mbytes, Kbytes per CLI "--format" option.
# Note: if the user flips direction with "--reverse" option, the display context is still
# correct b/c we derive direction from outputs, not from "client" vs "server" clue.
# Note: the unit(s) are influenced by "--format" so we need to treat them dynamically.
# Note: the interval of time-series is configurable by "--interval" option. So we compute it.
#
sub process_proto {
my $data_file = $_[0];
my $bitrate;
my $bitrate_div;
my $interval;
print "process_proto: enter\n";
my $rateunit='none';
my $sample_count=0;
(my $rc, my $fh) = open_read_text_file($data_file);
if ($rc == 0 and defined $fh) {
$ts=$times{'begin'};
while (<$fh>) {
if ( /sender/ or /receiver/ ) {
# No use for entries in the summary section, after "- - - - "
debug_print("Skip line: $_");
$ts=$times{'begin'}; # Reset because we are about to process the Server section
$rateunit = 'none'; # reset rate unit can change in the Server section.
next;
}
# skip this special entry - HN it reports OOO
if ( /SUM/ ) {
next;
}
if ( /omitted/ ) {
# Skip warm up entries from iperf "--omit" option.
#
# [ ID] Interval Transfer Bitrate Jitter Lost/Total Datagrams
# [ 5] 0.00-1.00 sec 572 MBytes 4800330 Kbits/sec 0.001 ms 1357/587336 (0.23%) (omitted)
# [ 5] 1.00-2.00 sec 580 MBytes 4867703 Kbits/sec 0.001 ms 0/594202 (0%) (omitted)
next;
}
if ( $protocol eq "udp") {
# Its output is as follows:
# [ ID] Interval Transfer Bitrate Total Datagrams
# [ 5] 0.00-1.00 sec 596 MBytes 5.00 Gbits/sec 38144
# < more similar entries >
# - - - - - - - - - - - - - - - - - - - - - - - - -
# [ ID] Interval Transfer Bitrate Jitter Lost/Total Datagrams
# [ 5] 0.00-30.00 sec 17.5 GBytes 5.00 Gbits/sec 0.000 ms 0/1144389 (0%) sender
# [ 5] 0.00-30.00 sec 17.5 GBytes 5.00 Gbits/sec 0.012 ms 148/1144389 (0.013%) receiver
#
# Server output:
#
# [ ID] Interval Transfer Bitrate Jitter Lost/Total Datagrams
# [ 5] 0.00-1.00 sec 596 MBytes 5.00 Gbits/sec 0.012 ms 8/38128 (0.021%)
# < more >
# - - - - - - - - - - - - - - - - - - - - - - - - -
# [ ID] Interval Transfer Bitrate Jitter Lost/Total Datagrams
# [ 5] 0.00-30.00 sec 17.5 GBytes 5.00 Gbits/sec 0.012 ms 148/1144389 (0.013%) receiver
if ( / sec / ) {
debug_print("Proc line: $_");
my $lost_total;
my @columns = split(/\s+/, $_);
# passthru CLI option "--interval nn" can change interval. So compute it.
my @tuble = split /-/, $columns[2];
my $start = $tuble[0];
my $end = $tuble[1];
my $sec_delta = $end - $start;
if ( $sec_delta == 0 ) {
# A nuissance. The last entry could be odd as below - Throw it away
# [ 5] 10.00-10.00 sec 352 KBytes 7.99 Gbits/sec 0.012 ms 0/22 (0%)
next;
}
$interval = $sec_delta*SEC_TO_MSEC;
debug_print("interval=$interval\n");
$bitrate = $columns[6];
debug_print("bitrate $bitrate\n");
if ( $rateunit eq 'none' ) {
$rateunit = $columns[7];
if ( $rateunit eq "Kbits/sec" ) {
$bitrate_div = 1000000;
} elsif ( $rateunit eq "Mbits/sec" ) {
$bitrate_div = 1000;
} elsif ( $rateunit eq "Gbits/sec" ) {
$bitrate_div = 1;
} else {
printf "Error: Did not recongnize rate unit: %s\n", $rateunit;
exit 1;
}
}
$ts_end=$ts + $interval -1;
my $num_fields = scalar @columns;
if ( $num_fields > 10 ) {
$lost_total = $columns[10];
my @tuble = split /\//, $lost_total;
my $lost = $tuble[0];
my $total = $tuble[1];
debug_print("Lost:$lost Total:$total\n");
%desc = ('source' => 'iperf', 'class' => 'throughput', 'type' => 'rx-lost/sec');
if ( $omit != 0 ) {
# Special handling for reruning "crucible postprocess" and wanting to
# skip the first few second drops as though we have run with --omit option
# This is a hack for times when we do not have the testbed to rerun, and just use the
# existing results, but altering the postprocessing to ignore drops of the first few intervals.
if ( $end <= $omit) {
debug_print("fudge lost value due to on-demand omit, line: $_");
$lost=0;
}
}
%s = ('begin' => int $ts, 'end' => int $ts_end, 'value' => $lost);
debug_print("log_sample: lost=$lost\n");
log_sample("0", \%desc, \%names, \%s);
%desc = ('source' => 'iperf', 'class' => 'throughput', 'type' => 'rx-pps');
%s = ('begin' => int $ts, 'end' => int $ts_end, 'value' => $total);
log_sample("0", \%desc, \%names, \%s);
if ( ! defined $primary_metric ) {
# rx throughput is our primary_metric.
$primary_metric = "rx-Gbps";
debug_print("primary_metric $primary_metric\n");
}
debug_print("log_sample: primary_metric=$primary_metric\n");
%desc = ('source' => 'iperf', 'class' => 'throughput', 'type' => $primary_metric);
} else {
# no "Lost/Total" column implies tx section
%desc = ('source' => 'iperf', 'class' => 'throughput', 'type' => "tx-Gbps");
}
# log rx "bitrate" sample
%s = ('begin' => int $ts, 'end' => int $ts_end, 'value' => ($bitrate / $bitrate_div));
debug_print ("begin: int $ts, end: int $ts_end\n");
log_sample("0", \%desc, \%names, \%s);
$sample_count++;
$ts=$ts+$interval;
} else {
debug_print("Skip line: $_");
}
} else {
# TCP outputs look as follows:
# [ ID] Interval Transfer Bitrate Retr Cwnd
# [ 5] 0.00-1.00 sec 596 MBytes 5.00 Gbits/sec 0 428 KBytes
# < more>
# [ ID] Interval Transfer Bitrate Retr
# [ 5] 0.00-30.00 sec 17.5 GBytes 5.00 Gbits/sec 0 sender
# [ 5] 0.00-30.00 sec 17.5 GBytes 5.00 Gbits/sec receiver
#
# Server output:
# [ ID] Interval Transfer Bitrate
# [ 5] 0.00-1.00 sec 596 MBytes 5.00 Gbits/sec
# < more >
# - - - - - - - - - - - - - - - - - - - - - - - - -
# [ ID] Interval Transfer Bitrate
# [ 5] 0.00-30.00 sec 17.5 GBytes 5.00 Gbits/sec receiver
if ( /sec\s/ ) {
debug_print("Proc line: $_");
my $retry;
my @columns = split(/\s+/, $_);
# passthru CLI option "--interval nn" can change interval. So compute it.
my @tuble = split /-/, $columns[2];
my $start = $tuble[0];
my $end = $tuble[1];
my $sec_delta = $end - $start;
$interval = $sec_delta*SEC_TO_MSEC;
debug_print("interval=$interval\n");
if ( $sec_delta == 0 ) {
# Exception. Last entry could be odd as below. Throw it away
# [ 5] 10.00-10.00 sec 352 KBytes 7.99 Gbits/sec 0.012 ms 0/22 (0%)
next;
}
$bitrate = $columns[6];
debug_print("bitrate $bitrate\n");
if ( $rateunit eq 'none' ) {
$rateunit = $columns[7];
if ( $rateunit eq "Kbits/sec" ) {
$bitrate_div = 1000000;
} elsif ( $rateunit eq "Mbits/sec" ) {
$bitrate_div = 1000;
} elsif ( $rateunit eq "Gbits/sec" ) {
$bitrate_div = 1;
} else {
printf "Error: Did not recongnize rate unit: %s\n", $rateunit;
exit 1;
}
}
my $num_fields = scalar @columns;
debug_print("num_fields: $num_fields\n");
$ts_end=$ts + $interval -1;
if ( $num_fields > 8 ) {
$retry = $columns[8];
# log "Retr" sample
debug_print("Retry: $retry\n");
%desc = ('source' => 'iperf', 'class' => 'count', 'type' => 'tx-retry/sec');
%s = ('begin' => int $ts, 'end' => int $ts_end, 'value' => $retry);
log_sample("0", \%desc, \%names, \%s);
%desc = ('source' => 'iperf', 'class' => 'throughput', 'type' => "tx-Gbps");
} else {
# no "Retr" column implies rx side
if ( ! defined $primary_metric ) {
$primary_metric = "rx-Gbps";
debug_print("primary_metric $primary_metric\n");
}
%desc = ('source' => 'iperf', 'class' => 'throughput', 'type' => $primary_metric);
}
# log rx "bitrate" sample
%s = ('begin' => int $ts, 'end' => int $ts_end, 'value' => ($bitrate / $bitrate_div));
log_sample("0", \%desc, \%names, \%s);
$sample_count++;;
$ts=$ts+$interval;
} else {
debug_print("Skip line: $_");
}
} # TCP
} # while
if ($sample_count == 0 ) {
# If the run failed to produce any sample (could fail), generate a '0 value' sample to make the rest happier.
$primary_metric = "rx-Gbps";
%desc = ('source' => 'iperf', 'class' => 'throughput', 'type' => $primary_metric);
%s = ('begin' => int $times{'begin'}, 'end' => int $times{'end'}, 'value' => 0);
log_sample("0", \%desc, \%names, \%s);
}
close($fh);
my $metric_data_name = finish_samples(1);
# Associate the metrics with a benchmark-period (in this case "measurement")
my %sample;
my @periods;
my %period = ('name' => 'measurement');
$sample{'rickshaw-bench-metric'}{'schema'}{'version'} = "2021.04.12";
my @metric_files = ( $metric_data_name );
$period{'metric-files'} = \@metric_files;
push(@periods, \%period);
$sample{'periods'} = \@periods;
$sample{'benchmark'} = 'iperf';
$sample{'primary-period'} = 'measurement';
$sample{'primary-metric'} = $primary_metric;
$rc = put_json_file("post-process-data.json", \%sample);
if ($rc > 0) {
printf "iperf-post-process(): Could not write file post-process-data.json\n";
exit 1
}
} else {
printf "iperf-post-process(): open_read_text_file() failed with return code %d for file %s\n", $rc, $result_file;
printf "Is the current directory for a iperf server (no result file)?\n";
}
}
#
# dup_one_run - Copy a section of a file to a new file
#
# Argument $_[0]: filehandle, pointing to start position for copying.
# Argument $_[1]: a line that the caller wants to be put on top of the new file.
# Argument $_[3]: the name of the new file.
#
sub dup_one_run {
my $ifh = $_[0];
my $first_line = $_[1];
my $outfile = $_[2];
open my $ofh, '>', $outfile or die "$outfile: $!";
print $ofh $first_line;
while (<$ifh>) {
#printf("extraxt line: $_");
print $ofh $_;
last if /END-TS/;
}
close $ofh;
}
#
# pre_process_hunting_results - Isolates the highest PASS result to a temp file.
#
# Argument $_[0]: the name of the src_file
# Argument $_[1]: the name of the dest_file
#
use POSIX;
sub pre_process_hunting_results {
my $from_file= $_[0];
my $to_file= $_[1];;
my $highest_bitrate=0;
my $bitrate= 0;
my $highest_run_number=0;
my $cur_run_number=0;
debug_print("process_hunting_results: enter\n");
(my $rc, my $fh) = open_read_text_file($from_file);
# scan the big report and find the highest PASS
if ($rc == 0 and defined $fh) {
while (<$fh>) {
if ( /BEGIN-TS/ ) {
$cur_run_number++;
}
debug_print("Proc line: $_");
if ( /PASS/ ) {
# PASS: [ 5] 0.00-10.00 sec 215 MBytes 180272 Kbits/sec 0.001 ms 0/3521093 (0%) receiver
my @columns = split(/\s+/, $_);
$bitrate=$columns[7];
if ($bitrate > $highest_bitrate) {
$highest_bitrate=$bitrate;
$highest_run_number=$cur_run_number;
}
next;
}
}
}
close($fh);
printf ("Highest run num = %d\n", $highest_run_number);
# DUP the highest PASS content to a temp file
($rc, $fh) = open_read_text_file($from_file);
$cur_run_number=0;
while (<$fh>) {
if ( /BEGIN-TS/ ) {
$cur_run_number++;
if ( $highest_run_number == $cur_run_number) {
# This is first line of the highest run
# Include this current line $_ in the temp file also
dup_one_run($fh, $_, $to_file);
last;
}
}
}
close($fh);
}
# Main
# Compatibility issue:
# Older iperf runs generated time stamps in begin.txt and end.txt files.
# Current iperf runs insert time stamps directly into iperf-client-result.txt file.
# Older runs lack individual timestamps per hunter iteration also. Those hunter results were 1-sample.
#
# Hence, to rerun "crucible postprocess" on older results, use older iperf-post-process version.
# commit b7bbbca50e1f4bb395e97b1c62ed2c7226bb3485 (HEAD -> main, upstream/main, origin/main, origin/HEAD)
#
if ( -e "./begin.txt" ) {
printf("Cannot process old results with this version. Please use an older bench-iperf version such as, \n");
printf("commit b7bbbca50e1f4bb395e97b1c62ed2c7226bb3485 (HEAD -> main, upstream/main, origin/main, origin/HEAD)\n");
exit 1;
}
if ($hunting_mode eq 0) {
$times{'begin'} = `grep BEGIN-TS $result_file | awk '{print \$2}'` * SEC_TO_MSEC;
$times{'end'} = `grep END-TS $result_file | awk '{print \$2}'` * SEC_TO_MSEC;
process_proto($result_file);
} else {
pre_process_hunting_results($result_file, $final_hunt_result);
$times{'begin'} = `grep BEGIN-TS $final_hunt_result | awk '{print \$2}'` * SEC_TO_MSEC;
$times{'end'} = `grep END-TS $final_hunt_result | awk '{print \$2}'` * SEC_TO_MSEC;
process_proto($final_hunt_result);
}
# EOF