-
Notifications
You must be signed in to change notification settings - Fork 4
/
uperf-post-process
executable file
·154 lines (147 loc) · 6.71 KB
/
uperf-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
#!/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 $test_type;
my $nthreads = 1;
my $remotehost;
my $ignore;
my $hostname;
GetOptions ("test-type=s" => \$test_type,
"nthreads=i" => \$nthreads,
"remotehost=s" => \$remotehost,
"wsize=i" => \$ignore,
"rsize=i" => \$ignore,
"think=f" => \$ignore,
"protocol=s" => \$ignore,
"duration=i" => \$ignore,
"ifname=s" => \$ignore,
"cpu-pin=s" => \$ignore,
);
if (! defined $test_type) {
print "uperf-post-process(): test-type not defined, assuming this is server and exiting\n";
exit 0;
}
my $primary_metric;
if ($test_type eq "rr" or $test_type eq "ping-pong") {
$primary_metric = 'transactions-sec';
} elsif ($test_type eq "crr") {
$primary_metric = 'connections-sec';
} else {
$primary_metric = 'Gbps';
}
my $result_file = "uperf-client-result.txt";
my %desc = ('source' => 'uperf', 'class' => 'throughput');
(my $rc, my $fh) = open_read_text_file($result_file);
if ($rc == 0 and defined $fh) {
my $ts, my $prev_ts, my $start_ts, my $bytes, my $prev_bytes, my $ops, my $prev_ops;;
my %names = ();
while (<$fh>) {
if ( $test_type eq "crr") {
if ( /^timestamp_ms:(\d+)\.\d+\s+name:Txn1\s+nr_bytes:(\d+)\s+nr_ops:(\d+)/ ) {
$ts = $1, $bytes = $2, $ops = $3;
if (defined $prev_ts and ((my $ts_diff = ($ts - $prev_ts) / 1000) > 0)) {
{
my %desc = ('source' => 'uperf', 'class' => 'throughput', 'type' => 'Gbps');
my %names = ('cmd' => 'readandwrite');
my %s = ('end' => int $ts,
'value' => 8.0 * ($bytes - $prev_bytes) / 1000000000 / $ts_diff);
log_sample("0", \%desc, \%names, \%s);
}
# CPS transactions are five operations: connect, write, think, read, disconnect
my $cps = ($ops - $prev_ops) / $ts_diff / 5;
{
my %desc = ('source' => 'uperf', 'class' => 'throughput', 'type' => 'connections-sec');
my %s = ('end' => int $ts, 'value' => 0.0 + $cps);
log_sample("0", \%desc, \%names, \%s);
}
if ($cps > 0) {
my %desc = ('source' => 'uperf', 'class' => 'count', 'type' => 'round-trip-usec');
my %s = ('end' => int $ts, 'value' => 0.0 + $nthreads / $cps *1000000);
log_sample("0", \%desc, \%names, \%s);
}
}
$prev_ts = $ts;
$prev_bytes = $bytes;
$prev_ops = $ops;
}
} else {
# Extract % stats from lines Time Data Throughput Operations Errors
# "Difference(%) -0.99% 52.34% 52.81% 52.34% 0.00% "
if ( /^Difference\(%\) \s+(-?\d+\.\d+)% \s+(-?\d+\.\d+)% \s+(-?\d+\.\d+)% \s+(-?\d+\.\d+)% \s+(-?\d+\.\d+)%/ ) {
my $Tput_val = $3;
my %desc = ('source' => 'uperf', 'class' => 'count', 'type' => 'throughput-delta-pct');
my %s = ('begin' => int $start_ts, 'end' => int $ts, 'value' => $Tput_val);
log_sample("0", \%desc, \%names, \%s);
}
if ( /^timestamp_ms:(\d+)\.\d+\s+name:Txn2\s+nr_bytes:(\d+)\s+nr_ops:(\d+)/ ) {
$ts = $1, $bytes = $2, $ops = $3;
if (defined $prev_ts and ((my $ts_diff = ($ts - $prev_ts) / 1000) > 0)) {
{
my %desc = ('source' => 'uperf', 'class' => 'throughput', 'type' => 'Gbps');
my %names = ('cmd' => 'readandwrite');
my %s = ('end' => int $ts,
'value' => 8.0 * ($bytes - $prev_bytes) / 1000000000 / $ts_diff);
log_sample("0", \%desc, \%names, \%s);
}
if ($test_type eq "rr" or $test_type eq "ping-pong" ) {
# RR transactions are two operations
my $tps = ($ops - $prev_ops) / $ts_diff / 2;
{
my %desc = ('source' => 'uperf', 'class' => 'throughput', 'type' => 'transactions-sec');
my %s = ('end' => int $ts, 'value' => 0.0 + $tps);
log_sample("0", \%desc, \%names, \%s);
}
if ($tps > 0) {
my %desc = ('source' => 'uperf', 'class' => 'count', 'type' => 'round-trip-usec');
my %s = ('end' => int $ts, 'value' => 0.0 + $nthreads / $tps *1000000);
log_sample("0", \%desc, \%names, \%s);
}
}
} else {
$start_ts = $ts;
}
$prev_ts = $ts;
$prev_bytes = $bytes;
$prev_ops = $ops;
}
}
}
close($fh);
my $metric_data_name = finish_samples();
# 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'} = 'uperf';
$sample{'primary-period'} = 'measurement';
$sample{'primary-metric'} = $primary_metric;
$rc = put_json_file("post-process-data.json", \%sample);
if ($rc > 0) {
printf "uperf-post-process(): Could not write file post-process-data.json\n";
exit 1
}
} else {
printf "uperf-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 uperf server (no result file)?\n";
}