blib/lib/Net/Iperf/Parser.pm

filter: Statementstmt 78.7% 37 / 47 Branchbran 83.3% 5 / 6 Conditioncond 93.7% 15 / 16 MC/DCmcdc 85.7% 6 / 7 Subroutinesub 62.5% 5 / 8 Podpod 85.7% 6 / 7 totaltotal 81.3% 74 / 91 CC 12 SCAR 13.8
CC
12
Cov
83%
dump
6.0
parse
5.0
is_global_avg
4.0
CRAP 4.0
↑ Summary
1 package Net::Iperf::Parser;
2 1 $Net::Iperf::Parser::VERSION = '0.04';
3 1 ▶use Mojo::Base::Tiny -base;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 has start => 0;
6 1 has end => 0;
7 1 has is_valid => 1;
8 1 has is_process_avg => 1;
9 1 has speed => 0;
10  
11 2 ▶sub duration {
Subroutine duration: called CC=1 SCAR=0.0
Pod undocumented
12 2 my $s = shift;
13 2 return $s->end - $s->start;
14 }
15  
16 6 ▶sub is_global_avg {
Subroutine is_global_avg: called CC=4 SCAR=13.9
Pod documented
17 6 my $s = shift;
18 6 ▶ return ( $s->is_process_avg && $s->start == 0 && $s->end > 5 ) || 0;
Condition87%7/8
$s->is_process_avg && $s->start == 0 && $s->end > 5 || 0
l!l
24
$s->is_process_avg and $s->start == 0 and $s->end > 5
!ll&&!rl&&r
222
$s->is_process_avg and $s->start == 0
!ll&&!rl&&r
204
MC/DC66%2/3
$s->is_process_avg && $s->start == 0 && $s->end > 5 || 0
$s->is_process_avg $s->start == 0 $s->end > 5
Truth table75%3/4
A and B and C
A= $s->is_process_avgB= $s->start == 0C= $s->end > 5
ABCresult
1111
0XX0
10X0
1100
19 }
20  
21 0 ▶sub speedk {
Subroutine speedk: not called CC=1 SCAR=6.9
Pod documented
22 0 return shift->speed / 1024;
23 }
24  
25 0 ▶sub speedm {
Subroutine speedm: not called CC=1 SCAR=6.9
Pod documented
26 0 return shift->speed / ( 1024 * 1024 );
27 }
28  
29 0 ▶sub dump {
Subroutine dump: not called CC=2 SCAR=17.9
Pod documented
30 0 my $s = shift;
31  
32 0 my @fld = qw/is_valid start end duration speed speedk speedm
33 is_process_avg is_global_avg/;
34  
35 0 my $ret = "{\n";
36  
37 0 foreach (@fld) {
38 0 $ret .= "\t$_ => " . $s->$_ . ",\n";
39 }
40  
41 0 $ret .= '}';
42  
43 0 return $ret;
44  
45 }
46  
47 5 ▶sub parsecsv {
Subroutine parsecsv: called CC=4 SCAR=13.9
Pod documented
48 5 my $s = shift;
49 5 ▶ my $row = shift || '';
Condition100%2/2
shift() || ''
l!l
32
MC/DC100%1/1
shift() || ''
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
50 5 ▶ if ( $row =~ /\,/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($row =~ /\,/u) { } 3 2 5
51 3 $s->{is_valid} = 1;
52 3 my @itms = split( /,/, $row );
53  
54 3 my $t_range = $itms[6];
55 3 ( $s->{start}, $s->{end} ) = map $_ + 0, split( /-/, $t_range );
56  
57 3 ▶ $s->{is_process_avg} = ( $itms[5] == -1 || 0 );
Condition100%2/2
$itms[5] == -1 || 0
l!l
21
MC/DC100%1/1
$itms[5] == -1 || 0
$itms[5] == -1
Truth table100%2/2
A
A= $itms[5] == -1
Aresult
11
00
58  
59 #$s->{speed} = ($itms[-1] / $s->duration);
60 3 $s->{speed} = $itms[-1] + 0;
61 } else {
62 2 $s->{is_valid} = 0;
63 }
64 }
65  
66 5 ▶sub parse {
Subroutine parse: called CC=5 SCAR=16.1
Pod documented
67 5 my $s = shift;
68 5 ▶ my $row = shift || '';
Condition100%2/2
shift() || ''
l!l
41
MC/DC100%1/1
shift() || ''
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
69 5 ▶ if ( $row =~ /^\[((\s*\d+)|SUM)\]\s+\d/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($row =~ /^\[((\s*\d+)|SUM)\]\s+\d/u) { } 3 2 5
70 3 $s->{is_valid} = 1;
71 3 my @itms;
72 3 $row =~ /([\d\.]+-\s*[\d\.]+)\s+sec/;
73 3 my $t_range = $1;
74 3 ( $s->{start}, $s->{end} ) = map $_ + 0, split( /-/, $t_range );
75  
76 3 ▶ $s->{is_process_avg} = ( $row =~ /^\[SUM\]/ || 0 );
Condition100%2/2
$row =~ /^\[SUM\]/u || 0
l!l
21
MC/DC100%1/1
$row =~ /^\[SUM\]/u || 0
$row =~ /^\[SUM\]/u
Truth table100%2/2
A
A= $row =~ /^\[SUM\]/u
Aresult
11
00
77 3 $row =~ /\s+([\d\.]+)\s+(\w+)\/sec/;
78 3 ▶ if ( $2 eq 'Mbits' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($2 eq 'Mbits') { } 3 0 3
79 3 $s->{speed} = ( $1 + 0 ) * 1024 * 1024;
80 } else {
81 0 $s->{speed} = ( $1 + 0 ) * 1024;
82 }
83 } else {
84 2 $s->{is_valid} = 0;
85 }
86 }
87  
88 1 1;
89  
90 =pod
91  
92 =head1 NAME
93  
94 Net::Iperf::Parser - Parse a single iperf line result
95  
96 =for html <p>
97 <a href="https://github.com/emilianobruni/net-iperf-parser/actions/workflows/test.yml">
98 <img alt="github workflow tests" src="https://github.com/emilianobruni/net-iperf-parser/actions/workflows/test.yml/badge.svg">
99 </a>
100 <img alt="Top language: " src="https://img.shields.io/github/languages/top/emilianobruni/net-iperf-parser">
101 <img alt="github last commit" src="https://img.shields.io/github/last-commit/emilianobruni/net-iperf-parser">
102 </p>
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<iperf|https://iperf.fr/>
190  
191 =head1 AUTHOR
192  
193 Emiliano Bruni <info@ebruni.it>
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__
↑ Summary