MCE/Core/Input/Handle.pm

filter: Statementstmt 59.4% 82 / 138 Branchbran 41.4% 29 / 70 Conditioncond 25.0% 5 / 20 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 66.6% 6 / 9 Podpod n/a totaltotal 48.8% 122 / 250 CC 47 SCAR 55.3
CC
47
Cov
51%
_worker_read_handle
314.2
__ANON__
3.3
__ANON__
2.1
CRAP 251.7
« MCE/Core/Manager.pm ↑ Summary MCE.pm »
1 ###############################################################################
2 ## ----------------------------------------------------------------------------
3 ## File path and Scalar reference input reader.
4 ##
5 ## This package provides the read handle method used internally by the worker
6 ## process. Distribution follows a bank-queuing model.
7 ##
8 ## There is no public API.
9 ##
10 ###############################################################################
11  
12 package MCE::Core::Input::Handle;
13  
14 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 13 our $VERSION = '1.904';
18  
19 ## Items below are folded into MCE.
20  
21 package # hide from rpm
22 MCE;
23  
24 13 ▶no warnings qw( threads recursion uninitialized );
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 13 my $_que_read_size = $MCE::_que_read_size;
27 13 my $_que_template = $MCE::_que_template;
28  
29 ###############################################################################
30 ## ----------------------------------------------------------------------------
31 ## Worker process -- Read handle.
32 ##
33 ###############################################################################
34  
35 0 ▶sub _systell {
Subroutine _systell: not called CC=1 SCAR=6.9
36 # To minimize memory consumption, SEEK_CUR equals 1 on most platforms.
37 # e.g. use Fcntl qw(SEEK_CUR);
38  
39 0 sysseek($_[0], 0, 1);
40 }
41  
42 14 ▶sub _worker_read_handle {
Subroutine _worker_read_handle: called CC=44 SCAR=57.5
43  
44 14 my ($self, $_proc_type, $_input_data) = @_;
45  
46 14 @_ = ();
47  
48 _croak('MCE::_worker_read_handle: (user_func) is not specified')
49 14 ▶ unless (defined $self->{user_func});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"user_func"} 0 14 14
50  
51 14 ▶ my $_is_MSWin32 = ($^O eq 'MSWin32') ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$^O eq 'MSWin32' ? : 0 14 14
52 14 my $_QUE_R_SOCK = $self->{_que_r_sock};
53 14 my $_QUE_W_SOCK = $self->{_que_w_sock};
54 14 my $_chunk_size = $self->{chunk_size};
55 14 my $_use_slurpio = $self->{use_slurpio};
56 14 my $_parallel_io = $self->{parallel_io};
57 14 ▶ my $_RS = $self->{RS} || $/;
Condition33%1/3
$self->{'RS'} || $/
l!l&&r!l&&!r
0140
MC/DC0%0/2
$self->{'RS'} || $/
$self->{'RS'} $/
Truth table33%1/3
A || B
A= $self->{'RS'}B= $/
ABresult
1X1
011
000
58 14 my $_wuf = $self->{_wuf};
59  
60 14 my ($_data_size, $_next, $_chunk_id, $_offset_pos, $_IN_FILE, $_tmp_cs);
61 14 my ($_DAT_LOCK, $_dat_ex, $_dat_un, $_pid, $_chop_len, $_chop_str, $_p);
62  
63 14 ▶ $_pid = $INC{'threads.pm'} ? $$ .'.'. threads->tid() : $$;
Branch: 1 branch
BranchTrueFalseTotal
$INC{'threads.pm'} ? : 0 14 14
64  
65 # inlined for performance
66 14 $_DAT_LOCK = $self->{'_mutex_'.( $self->{_wid} % 2 + 10 )};
67 65 ▶ $_dat_ex = sub {
Subroutine __ANON__: called CC=3 SCAR=12.0
68 CORE::lock($_DAT_LOCK->{_t_lock}), MCE::Util::_sock_ready($_DAT_LOCK->{_r_sock})
69 65 ▶ if $_is_MSWin32;
Branch: 1 branch
BranchTrueFalseTotal
if $_is_MSWin32 0 65 65
70 MCE::Util::_sysread($_DAT_LOCK->{_r_sock}, my($b), 1), $_DAT_LOCK->{ $_pid } = 1
71 65 ▶ unless $_DAT_LOCK->{ $_pid };
Branch: 1 branch
BranchTrueFalseTotal
unless $_DAT_LOCK->{$_pid} 65 0 65
72 14 };
73 65 ▶ $_dat_un = sub {
Subroutine __ANON__: called CC=2 SCAR=7.6
74 syswrite($_DAT_LOCK->{_w_sock}, '0'), $_DAT_LOCK->{ $_pid } = 0
75 65 ▶ if $_DAT_LOCK->{ $_pid };
Branch: 1 branch
BranchTrueFalseTotal
if $_DAT_LOCK->{$_pid} 65 0 65
76 14 };
77  
78 14 ▶ if (length $_RS > 1 && substr($_RS, 0, 1) eq "\n") {
Branch: 1 branch
BranchTrueFalseTotal
if (length $_RS > 1 and substr($_RS, 0, 1) eq "\n") { } 0 14 14
Condition33%1/3
length $_RS > 1 and substr($_RS, 0, 1) eq "\n"
!ll&&!rl&&r
1400
MC/DC0%0/2
length $_RS > 1 and substr($_RS, 0, 1) eq "\n"
length $_RS > 1 substr($_RS, 0, 1) eq "\n"
Truth table33%1/3
A and B
A= length $_RS > 1B= substr($_RS, 0, 1) eq "\n"
ABresult
0X0
100
111
79 0 $_chop_str = substr($_RS, 1);
80 0 $_chop_len = length $_chop_str;
81 } else {
82 14 $_chop_str = '';
83 14 $_chop_len = 0;
84 }
85  
86 $_data_size = ($_proc_type == READ_MEMORY)
87 0 ▶ ? length ${ $_input_data } : -s $_input_data;
Branch: 1 branch
BranchTrueFalseTotal
$_proc_type == 1 ? : 0 14 14
88  
89 14 $_chunk_id = $_offset_pos = 0;
90  
91 14 ▶ open $_IN_FILE, '<', $_input_data or die "$_input_data: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open $_IN_FILE, "<", $_input_data or die "${_input_data}: $!\n" 14 0 14
92 14 binmode $_IN_FILE;
93  
94 ## -------------------------------------------------------------------------
95  
96 0 ▶ $self->{_next_jmp} = sub { goto _WORKER_READ_HANDLE__NEXT; };
Subroutine __ANON__: not called CC=1 SCAR=1.2
97 0 ▶ $self->{_last_jmp} = sub { goto _WORKER_READ_HANDLE__LAST; };
Subroutine __ANON__: not called CC=1 SCAR=1.2
98  
99 14 local $_;
100  
101 _WORKER_READ_HANDLE__NEXT:
102  
103 14 while (1) {
104 65 ▶ my @_recs; undef $_ if (length > MAX_GC_SIZE);
Branch: 1 branch
BranchTrueFalseTotal
if length $_ > 67108864 0 65 65
105  
106 65 $_ = '';
107  
108 ## Obtain the next chunk_id and offset position.
109 65 $_dat_ex->();
110 65 ▶ MCE::Util::_sock_ready($_QUE_R_SOCK) if $_is_MSWin32;
Branch: 1 branch
BranchTrueFalseTotal
if $_is_MSWin32 0 65 65
111 65 MCE::Util::_sysread($_QUE_R_SOCK, $_next, $_que_read_size);
112  
113 65 ($_chunk_id, $_offset_pos) = unpack($_que_template, $_next);
114  
115 65 ▶ if ($_offset_pos >= $_data_size) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_offset_pos >= $_data_size) 14 51 65
116 14 syswrite($_QUE_W_SOCK, pack($_que_template, 0, $_offset_pos));
117 14 $_dat_un->();
118 14 close $_IN_FILE; undef $_IN_FILE;
119 14 return;
120 }
121  
122 51 ▶ if (++$_chunk_id > 1 && $_chop_len) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$_chunk_id > 1 and $_chop_len) { } 0 51 51
Condition66%2/3
++$_chunk_id > 1 and $_chop_len
!ll&&!rl&&r
7440
MC/DC0%0/2
++$_chunk_id > 1 and $_chop_len
++$_chunk_id > 1 $_chop_len
Truth table66%2/3
A and B
A= ++$_chunk_id > 1B= $_chop_len
ABresult
0X0
100
111
123 0 $_p = $_chop_len; $_ = $_chop_str;
124 } else {
125 51 $_p = 0;
126 }
127  
128 ## Read data.
129 51 ▶ if ($_chunk_size <= MAX_RECS_SIZE) { # One or many records.
Branch: 1 branch
BranchTrueFalseTotal
if ($_chunk_size <= 8192) { } 51 0 51
130 51 ▶ local $/ = $_RS if ($/ ne $_RS);
Branch: 1 branch
BranchTrueFalseTotal
if $/ ne $_RS 0 51 51
131 51 seek $_IN_FILE, $_offset_pos, 0;
132  
133 51 ▶ if ($_chunk_size == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_chunk_size == 1) { } 36 15 51
134 36 ▶ if ($_p) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_p) { } 0 36 36
135 0 $_ .= <$_IN_FILE>;
136 } else {
137 36 $_ = <$_IN_FILE>;
138 }
139 }
140 else {
141 15 ▶ if ($_use_slurpio) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_use_slurpio) { } 0 15 15
142 0 for my $i (0 .. $_chunk_size - 1) {
143 0 $_ .= <$_IN_FILE>;
144 }
145 }
146 else {
147 15 ▶ if ($_chop_len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_chop_len) { } 0 15 15
148 0 ▶ $_recs[0] = ($_chunk_id > 1) ? $_chop_str : '';
Branch: 1 branch
BranchTrueFalseTotal
$_chunk_id > 1 ? : 0 0 0
149 0 $_recs[0] .= <$_IN_FILE>;
150 0 for my $i (1 .. $_chunk_size - 1) {
151 0 $_recs[$i] = $_chop_str;
152 0 $_recs[$i] .= <$_IN_FILE>;
153 0 ▶ if (length $_recs[$i] == $_chop_len) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $_recs[$i] == $_chop_len) 0 0 0
154 0 delete $_recs[$i];
155 0 last;
156 }
157 }
158 }
159 else {
160 15 for my $i (0 .. $_chunk_size - 1) {
161 30 $_recs[$i] = <$_IN_FILE>;
162 30 ▶ unless (defined $_recs[$i]) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $_recs[$i]) 3 27 30
163 3 delete $_recs[$i];
164 3 last;
165 }
166 }
167 }
168 }
169 }
170  
171 51 syswrite(
172 $_QUE_W_SOCK, pack($_que_template, $_chunk_id, tell $_IN_FILE)
173 );
174 51 $_dat_un->();
175 }
176 else { # Large chunk.
177 0 ▶ local $/ = $_RS if ($/ ne $_RS);
Branch: 1 branch
BranchTrueFalseTotal
if $/ ne $_RS 0 0 0
178  
179 0 ▶ if ($_parallel_io && $_RS eq $LF) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_parallel_io and $_RS eq $MCE::LF) { } 0 0 0
Condition0%0/3
$_parallel_io and $_RS eq $MCE::LF
!ll&&!rl&&r
000
MC/DC0%0/2
$_parallel_io and $_RS eq $MCE::LF
$_parallel_io $_RS eq $MCE::LF
Truth table0%0/3
A and B
A= $_parallel_ioB= $_RS eq $MCE::LF
ABresult
0X0
100
111
180 0 syswrite(
181 $_QUE_W_SOCK,
182 pack($_que_template, $_chunk_id, $_offset_pos + $_chunk_size)
183 );
184 0 $_dat_un->();
185  
186 0 $_tmp_cs = $_chunk_size;
187 0 seek $_IN_FILE, $_offset_pos, 0;
188  
189 0 ▶ if ($_offset_pos) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_offset_pos) 0 0 0
190 0 ▶ $_tmp_cs -= length <$_IN_FILE> || 0;
Condition0%0/2
length readline $_IN_FILE || 0
l!l
00
MC/DC0%0/1
length readline $_IN_FILE || 0
length readline $_IN_FILE
Truth table0%0/2
A
A= length readline $_IN_FILE
Aresult
11
00
191 }
192  
193 0 ▶ if ($_proc_type == READ_FILE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_proc_type == 0) { } 0 0 0
194 0 sysseek($_IN_FILE, tell( $_IN_FILE ), 0);
195 0 sysread($_IN_FILE, $_, $_tmp_cs, $_p);
196 0 seek $_IN_FILE, _systell($_IN_FILE), 0;
197 }
198 else {
199 0 read $_IN_FILE, $_, $_tmp_cs, $_p;
200 }
201  
202 0 $_ .= <$_IN_FILE>;
203 }
204 else {
205 0 ▶ if ($_proc_type == READ_FILE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_proc_type == 0) { } 0 0 0
206 0 sysseek($_IN_FILE, $_offset_pos, 0);
207 0 sysread($_IN_FILE, $_, $_chunk_size, $_p);
208 0 seek $_IN_FILE, _systell($_IN_FILE), 0;
209 }
210 else {
211 0 seek $_IN_FILE, $_offset_pos, 0;
212 0 read $_IN_FILE, $_, $_chunk_size, $_p;
213 }
214  
215 0 $_ .= <$_IN_FILE>;
216  
217 0 syswrite(
218 $_QUE_W_SOCK, pack($_que_template, $_chunk_id, tell $_IN_FILE)
219 );
220 0 $_dat_un->();
221 }
222 }
223  
224 ## Call user function.
225 51 ▶ if ($_use_slurpio) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_use_slurpio) { } 0 51 51
226 0 ▶ if ($_chop_len && substr($_, -$_chop_len) eq $_chop_str) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_chop_len and substr($_, -$_chop_len) eq $_chop_str) 0 0 0
Condition0%0/3
$_chop_len and substr($_, -$_chop_len) eq $_chop_str
!ll&&!rl&&r
000
MC/DC0%0/2
$_chop_len and substr($_, -$_chop_len) eq $_chop_str
$_chop_len substr($_, -$_chop_len) eq $_chop_str
Truth table0%0/3
A and B
A= $_chop_lenB= substr($_, -$_chop_len) eq $_chop_str
ABresult
0X0
100
111
227 0 substr($_, -$_chop_len, $_chop_len, '');
228 }
229 0 local $_ = \$_;
230 0 $_wuf->($self, $_, $_chunk_id);
231 }
232 else {
233 51 ▶ if ($_chunk_size == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_chunk_size == 1) { } 36 15 51
234 36 ▶ if ($_chop_len && substr($_, -$_chop_len) eq $_chop_str) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_chop_len and substr($_, -$_chop_len) eq $_chop_str) 0 36 36
Condition33%1/3
$_chop_len and substr($_, -$_chop_len) eq $_chop_str
!ll&&!rl&&r
3600
MC/DC0%0/2
$_chop_len and substr($_, -$_chop_len) eq $_chop_str
$_chop_len substr($_, -$_chop_len) eq $_chop_str
Truth table33%1/3
A and B
A= $_chop_lenB= substr($_, -$_chop_len) eq $_chop_str
ABresult
0X0
100
111
235 0 substr($_, -$_chop_len, $_chop_len, '');
236 }
237 36 $_wuf->($self, [ $_ ], $_chunk_id);
238 }
239 else {
240 15 ▶ if ($_chunk_size > MAX_RECS_SIZE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_chunk_size > 8192) 0 15 15
241 0 ▶ local $/ = $_RS if ($/ ne $_RS);
Branch: 1 branch
BranchTrueFalseTotal
if $/ ne $_RS 0 0 0
242 0 _sync_buffer_to_array(\$_, \@_recs, $_chop_str);
243 0 undef $_;
244 }
245 15 ▶ if ($_chop_len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_chop_len) 0 15 15
246 0 for my $i (0 .. @_recs - 1) {
247 0 ▶ if (substr($_recs[$i], -$_chop_len) eq $_chop_str) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($_recs[$i], -$_chop_len) eq $_chop_str) 0 0 0
248 0 substr($_recs[$i], -$_chop_len, $_chop_len, '');
249 }
250 }
251 }
252 15 local $_ = \@_recs;
253 15 $_wuf->($self, \@_recs, $_chunk_id);
254 }
255 }
256 }
257  
258 _WORKER_READ_HANDLE__LAST:
259  
260 0 close $_IN_FILE; undef $_IN_FILE;
261  
262 0 return;
263 }
264  
265 13 1;
266  
267 __END__
« MCE/Core/Manager.pm ↑ Summary MCE.pm »