| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Net::Iperf::Parser; |
|
2
|
|
|
|
|
|
|
$Net::Iperf::Parser::VERSION = '0.03'; |
|
3
|
2
|
|
|
2
|
|
148991
|
use Moose; |
|
|
2
|
|
|
|
|
931106
|
|
|
|
2
|
|
|
|
|
14
|
|
|
4
|
2
|
|
|
2
|
|
16983
|
use namespace::autoclean; |
|
|
2
|
|
|
|
|
16395
|
|
|
|
2
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: Parse a single iperf line result |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has start => ( is => 'ro', isa => 'Int', default => 0 ); |
|
10
|
|
|
|
|
|
|
has end => ( is => 'ro', isa => 'Int', default => 0 ); |
|
11
|
|
|
|
|
|
|
has is_valid => ( is => 'ro', isa => 'Bool', default => 1 ); |
|
12
|
|
|
|
|
|
|
has is_process_avg => ( is => 'ro', isa => 'Bool', default => 1 ); |
|
13
|
|
|
|
|
|
|
has speed => ( is => 'ro', isa => 'Num', default => 0 ); |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub duration { |
|
17
|
2
|
|
|
2
|
0
|
4
|
my $s = shift; |
|
18
|
2
|
|
|
|
|
66
|
return $s->end - $s->start; |
|
19
|
|
|
|
|
|
|
} |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub is_global_avg { |
|
22
|
6
|
|
|
6
|
1
|
12
|
my $s = shift; |
|
23
|
6
|
|
100
|
|
|
207
|
return ($s->is_process_avg && $s->start == 0 && $s->end > 5) || 0; |
|
24
|
|
|
|
|
|
|
} |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub speedk { |
|
27
|
0
|
|
|
0
|
1
|
0
|
return shift->speed / 1024; |
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub speedm { |
|
31
|
0
|
|
|
0
|
1
|
0
|
return shift->speed / (1024 * 1024); |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub dump { |
|
35
|
0
|
|
|
0
|
1
|
0
|
my $s = shift; |
|
36
|
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
0
|
my @fld = qw/is_valid start end duration speed speedk speedm |
|
38
|
|
|
|
|
|
|
is_process_avg is_global_avg/; |
|
39
|
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
0
|
my $ret = "{\n"; |
|
41
|
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
0
|
foreach(@fld) { |
|
43
|
0
|
|
|
|
|
0
|
$ret .= "\t$_ => " . $s->$_ . ",\n"; |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
0
|
$ret .= '}'; |
|
47
|
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
0
|
return $ret; |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub parsecsv { |
|
54
|
5
|
|
|
5
|
1
|
11
|
my $s = shift; |
|
55
|
5
|
|
100
|
|
|
21
|
my $row = shift || ''; |
|
56
|
5
|
100
|
|
|
|
19
|
if ($row =~ /\,/) { |
|
57
|
3
|
|
|
|
|
6
|
$s->{is_valid} = 1; |
|
58
|
3
|
|
|
|
|
15
|
my @itms = split(/,/,$row); |
|
59
|
|
|
|
|
|
|
|
|
60
|
3
|
|
|
|
|
6
|
my $t_range = $itms[6]; |
|
61
|
3
|
|
|
|
|
23
|
($s->{start},$s->{end}) = map $_+0, split(/-/, $t_range); |
|
62
|
|
|
|
|
|
|
|
|
63
|
3
|
|
100
|
|
|
16
|
$s->{is_process_avg} = ($itms[5] == -1 || 0); |
|
64
|
|
|
|
|
|
|
#$s->{speed} = ($itms[-1] / $s->duration); |
|
65
|
3
|
|
|
|
|
13
|
$s->{speed} = $itms[-1] + 0; |
|
66
|
|
|
|
|
|
|
} else { |
|
67
|
2
|
|
|
|
|
5
|
$s->{is_valid} = 0; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub parse { |
|
72
|
5
|
|
|
5
|
1
|
16
|
my $s = shift; |
|
73
|
5
|
|
100
|
|
|
15
|
my $row = shift || ''; |
|
74
|
5
|
100
|
|
|
|
33
|
if ($row =~ /^\[((\s*\d+)|SUM)\]\s+\d/) { |
|
75
|
3
|
|
|
|
|
7
|
$s->{is_valid} = 1; |
|
76
|
3
|
|
|
|
|
5
|
my @itms; |
|
77
|
3
|
|
|
|
|
14
|
$row =~ /([\d\.]+-\s*[\d\.]+)\s+sec/; |
|
78
|
3
|
|
|
|
|
8
|
my $t_range = $1; |
|
79
|
3
|
|
|
|
|
25
|
($s->{start},$s->{end}) = map $_+0, split(/-/, $t_range); |
|
80
|
|
|
|
|
|
|
|
|
81
|
3
|
|
100
|
|
|
15
|
$s->{is_process_avg} = ($row =~ /^\[SUM\]/ || 0); |
|
82
|
3
|
|
|
|
|
23
|
$row =~/\s+([\d\.]+)\s+(\w+)\/sec/; |
|
83
|
3
|
50
|
|
|
|
10
|
if ($2 eq 'Mbits') { |
|
84
|
3
|
|
|
|
|
25
|
$s->{speed} = ($1+0) * 1024 * 1024; |
|
85
|
|
|
|
|
|
|
} else { |
|
86
|
0
|
|
|
|
|
0
|
$s->{speed} = ($1+0) * 1024; |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
} else { |
|
89
|
2
|
|
|
|
|
6
|
$s->{is_valid} = 0; |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
1; |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
__END__ |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=pod |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=encoding UTF-8 |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 NAME |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Net::Iperf::Parser - Parse a single iperf line result |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 VERSION |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
version 0.03 |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
use Net::Iperf::Parser; |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
my $p = new Net::Iperf::Parser; |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
my @rows = `iperf -c iperf.volia.net -P 2`; |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
foreach (@rows) { |
|
121
|
|
|
|
|
|
|
$p->parse($_); |
|
122
|
|
|
|
|
|
|
print $p->dump if ($p->is_valid && $p->is_global_avg); |
|
123
|
|
|
|
|
|
|
} |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
and result is something like this |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
{ |
|
128
|
|
|
|
|
|
|
is_valid => 1, |
|
129
|
|
|
|
|
|
|
start => 0, |
|
130
|
|
|
|
|
|
|
end => 10, |
|
131
|
|
|
|
|
|
|
duration => 10, |
|
132
|
|
|
|
|
|
|
speed => 129024, |
|
133
|
|
|
|
|
|
|
speedk => 126, |
|
134
|
|
|
|
|
|
|
speedm => 0.123046875, |
|
135
|
|
|
|
|
|
|
is_process_avg => 1, |
|
136
|
|
|
|
|
|
|
is_global_avg => 1, |
|
137
|
|
|
|
|
|
|
} |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Parse a single iperf line result in default or CSV mode |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 METHODS |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head2 start |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Return the start time |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head2 end |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Return the end time |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head2 is_valid |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Return if the parsed row is a valid iperf row |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head2 is_process_avg |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Return if the row is a process average value |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head2 is_global_avg |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Return if the row is the last summary value |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head2 speed |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Return the speed calculated in bps |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head2 speedk |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Return the speed calculated in Kbps |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head2 speedm |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
Return the speed calculated in Mbps |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head2 dump |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
Return a to_string version of the object (like a Data::Dumper::dumper) |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head2 parse($row) |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
Parse a single iperf line result |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head2 parsecsv($row) |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
Parse a single iperf line result in CSV mode (-y C) |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
L<iperf|https://iperf.fr/> |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=head1 AUTHOR |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
Emiliano Bruni <info@ebruni.it> |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
This software is copyright (c) 2019 by Emiliano Bruni. |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
202
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=cut |