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