blib/lib/Linux/Event/Loop/Introspection.pm

filter: Statementstmt 95.0% 114 / 120 Branchbran 77.6% 87 / 112 Conditioncond 64.0% 16 / 25 MC/DCmcdc 40.0% 6 / 15 Subroutinesub 100% 19 / 19 Podpod 0.0% 0 / 8 totaltotal 80.9% 242 / 299 CC 69 SCAR 25.7
CC
69
Cov
84%
_inspect_object
25.3
_owner_of
18.0
_type_of
13.0
CRAP 13.0
« blib/lib/Linux/Event/Kernel/Inotify.pm ↑ Summary blib/lib/Linux/Event/Kernel/Event.pm »
1 package Linux::Event::Loop::Introspection;
2 181 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 181 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 181 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 181 ▶use Scalar::Util qw(blessed refaddr);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 181 my @CENSUS_TYPES = qw(pipe tty stream listener dgram timer signal event inotify process);
8  
9 798 ▶sub _type_of ($object) {
Subroutine _type_of: called CC=13 SCAR=25.7
10 798 ▶ return 'unknown'
Branch: 1 branch
BranchTrueFalseTotal
if $object->isa("Linux::Event::_ByteStream::_Deadline") or $object->isa("Linux::Event::_Socket::Dgram::_ReadyTimer") 28 770 798
Condition66%2/3
$object->isa("Linux::Event::_ByteStream::_Deadline") or $object->isa("Linux::Event::_Socket::Dgram::_ReadyTimer")
l!l&&r!l&&!r
028770
MC/DC50%1/2
$object->isa("Linux::Event::_ByteStream::_Deadline") or $object->isa("Linux::Event::_Socket::Dgram::_ReadyTimer")
$object->isa("Linux::Event::_ByteStream::_Deadline") $object->isa("Linux::Event::_Socket::Dgram::_ReadyTimer")
Truth table66%2/3
A or B
A= $object->isa("Linux::Event::_ByteStream::_Deadline")B= $object->isa("Linux::Event::_Socket::Dgram::_ReadyTimer")
ABresult
1X1
011
000
11 if $object->isa('Linux::Event::_ByteStream::_Deadline')
12 || $object->isa('Linux::Event::_Socket::Dgram::_ReadyTimer');
13 770 ▶ return 'pipe' if $object->isa('Linux::Event::IO::Pipe');
Branch: 1 branch
BranchTrueFalseTotal
if $object->isa("Linux::Event::IO::Pipe") 62 708 770
14 708 ▶ return 'tty' if $object->isa('Linux::Event::IO::TTY');
Branch: 1 branch
BranchTrueFalseTotal
if $object->isa("Linux::Event::IO::TTY") 5 703 708
15 703 ▶ return 'stream' if $object->isa('Linux::Event::IO::Sock::Stream');
Branch: 1 branch
BranchTrueFalseTotal
if $object->isa("Linux::Event::IO::Sock::Stream") 103 600 703
16 600 ▶ return 'listener' if $object->isa('Linux::Event::IO::Sock::Listener');
Branch: 1 branch
BranchTrueFalseTotal
if $object->isa("Linux::Event::IO::Sock::Listener") 68 532 600
17 532 ▶ return 'dgram' if $object->isa('Linux::Event::IO::Sock::Dgram');
Branch: 1 branch
BranchTrueFalseTotal
if $object->isa("Linux::Event::IO::Sock::Dgram") 58 474 532
18 474 ▶ return 'timer' if $object->isa('Linux::Event::Kernel::Timer');
Branch: 1 branch
BranchTrueFalseTotal
if $object->isa("Linux::Event::Kernel::Timer") 115 359 474
19 359 ▶ return 'signal' if $object->isa('Linux::Event::Kernel::Signal');
Branch: 1 branch
BranchTrueFalseTotal
if $object->isa("Linux::Event::Kernel::Signal") 58 301 359
20 301 ▶ return 'event' if $object->isa('Linux::Event::Kernel::Event');
Branch: 1 branch
BranchTrueFalseTotal
if $object->isa("Linux::Event::Kernel::Event") 56 245 301
21 245 ▶ return 'inotify' if $object->isa('Linux::Event::Kernel::Inotify');
Branch: 1 branch
BranchTrueFalseTotal
if $object->isa("Linux::Event::Kernel::Inotify") 117 128 245
22 128 ▶ return 'process' if $object->isa('Linux::Event::Kernel::Process');
Branch: 1 branch
BranchTrueFalseTotal
if $object->isa("Linux::Event::Kernel::Process") 58 70 128
23 70 return 'unknown';
24 }
25  
26 335 ▶sub _is_current ($self, $object) {
Subroutine _is_current: called CC=7 SCAR=20.8
27 335 ▶ return 0 if !blessed($object) || _type_of($object) eq 'unknown';
Branch: 1 branch
BranchTrueFalseTotal
if not builtin::blessed($object) or _type_of($object) eq "unknown" 0 335 335
Condition33%1/3
not builtin::blessed($object) or _type_of($object) eq "unknown"
l!l&&r!l&&!r
00335
MC/DC0%0/2
not builtin::blessed($object) or _type_of($object) eq "unknown"
not builtin::blessed($object) _type_of($object) eq "unknown"
Truth table33%1/3
not(A) or B
A= not builtin::blessed($object)B= _type_of($object) eq "unknown"
ABresult
1X1
011
000
28 335 my $loop = eval { $object->loop };
29 335 ▶ return 0 if !$loop || refaddr($loop) != refaddr($self);
Branch: 1 branch
BranchTrueFalseTotal
if not $loop or builtin::refaddr($loop) != builtin::refaddr($self) 5 330 335
Condition100%3/3
not $loop or builtin::refaddr($loop) != builtin::refaddr($self)
l!l&&r!l&&!r
32330
MC/DC100%2/2
not $loop or builtin::refaddr($loop) != builtin::refaddr($self)
not $loop builtin::refaddr($loop) != builtin::refaddr($self)
Truth table100%3/3
not(A) or B
A= not $loopB= builtin::refaddr($loop) != builtin::refaddr($self)
ABresult
1X1
011
000
30 return 0 if $object->can('is_terminal')
31 330 ▶ && eval { $object->is_terminal };
Branch: 1 branch
BranchTrueFalseTotal
if $object->can("is_terminal") and eval { do { $object->is_terminal } } 0 330 330
Condition33%1/3
$object->can("is_terminal") and eval { do { $object->is_terminal } }
!ll&&!rl&&r
03300
MC/DC0%0/2
$object->can("is_terminal") and eval { do { $object->is_terminal } }
$object->can("is_terminal") eval { do { $object->is_terminal } }
Truth table33%1/3
A and B
A= $object->can("is_terminal")B= eval { do { $object->is_terminal } }
ABresult
0X0
100
111
32 330 return 1;
33 }
34  
35 83 ▶sub _object_snapshot ($self) {
Subroutine _object_snapshot: called CC=9 SCAR=22.0
36 83 my @candidate = @{ $self->_object_candidates_native };
37 83 ▶ push @candidate, @{ Linux::Event::Kernel::Signal->_objects_for_loop($self) }
Branch: 1 branch
BranchTrueFalseTotal
if "Linux::Event::Kernel::Signal"->can("_objects_for_loop") 28 55 83
38 if Linux::Event::Kernel::Signal->can('_objects_for_loop');
39 83 ▶ push @candidate, @{ Linux::Event::Kernel::Event->_objects_for_loop($self) }
Branch: 1 branch
BranchTrueFalseTotal
if "Linux::Event::Kernel::Event"->can("_objects_for_loop") 69 14 83
40 if Linux::Event::Kernel::Event->can('_objects_for_loop');
41 83 ▶ push @candidate, @{ Linux::Event::Kernel::Inotify->_objects_for_loop($self) }
Branch: 1 branch
BranchTrueFalseTotal
if "Linux::Event::Kernel::Inotify"->can("_objects_for_loop") 55 28 83
42 if Linux::Event::Kernel::Inotify->can('_objects_for_loop');
43 83 ▶ push @candidate, @{ Linux::Event::_Resolver->_objects_for_loop($self) }
Branch: 1 branch
BranchTrueFalseTotal
if "Linux::Event::_Resolver"->can("_objects_for_loop") 81 2 83
44 if Linux::Event::_Resolver->can('_objects_for_loop');
45  
46 83 my %seen;
47 my @result;
48 83 for my $candidate (@candidate) {
49 348 ▶ my $object = _owner_of($candidate) // next;
Condition100%2/2
_owner_of($candidate) // (next)
l!l
32028
MC/DC100%1/1
_owner_of($candidate) // (next)
_owner_of($candidate)
Truth table100%2/2
A
A= _owner_of($candidate)
Aresult
11
00
50 320 ▶ next if $seen{ refaddr($object) }++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen{builtin::refaddr($object)}++ 35 285 320
51 285 ▶ next if !$self->_is_current($object);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_current($object) 0 285 285
52 285 push @result, $object;
53 }
54 83 return \@result;
55 }
56  
57 6 ▶sub count ($self) { scalar @{ $self->_object_snapshot } }
Subroutine count: called CC=1 SCAR=0.0
Pod undocumented
58  
59 50 ▶sub has ($self, $object) {
Subroutine has: called CC=3 SCAR=11.0
Pod undocumented
60 50 ▶ return 0 if !blessed($object);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($object) 0 50 50
61 50 ▶ return 0 if !$self->_is_current($object);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_current($object) 5 45 50
62 45 my $id = refaddr($object);
63 45 return !!grep { refaddr($_) == $id } @{ $self->_object_snapshot };
64 }
65  
66 25 ▶sub objects ($self) { [ @{ $self->_object_snapshot } ] }
Subroutine objects: called CC=1 SCAR=0.0
Pod undocumented
67  
68 2 ▶sub census ($self) {
Subroutine census: called CC=2 SCAR=6.9
Pod undocumented
69 2 my %count = map { $_ => 0 } @CENSUS_TYPES;
70 2 $count{ _type_of($_) }++ for @{ $self->_object_snapshot };
71 2 return \%count;
72 }
73  
74 221 ▶sub _value ($object, $method) {
Subroutine _value: called CC=2 SCAR=7.1
75 221 ▶ return undef if !$object->can($method);
Branch: 1 branch
BranchTrueFalseTotal
unless $object->can($method) 0 221 221
76 221 return eval { $object->$method() };
77 }
78  
79 418 ▶sub _owner_of ($candidate) {
Subroutine _owner_of: called CC=9 SCAR=28.9
80 418 ▶ return undef if !ref($candidate);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $candidate 0 418 418
81 418 ▶ if (blessed($candidate)) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($candidate)) 418 0 418
82 418 ▶ return $candidate if _type_of($candidate) ne 'unknown';
Branch: 1 branch
BranchTrueFalseTotal
if _type_of($candidate) ne "unknown" 320 98 418
83 98 ▶ return _owner_of(scalar eval { $candidate->object })
Branch: 1 branch
BranchTrueFalseTotal
if $candidate->isa("Linux::Event::_ByteStream::State") 70 28 98
84 if $candidate->isa('Linux::Event::_ByteStream::State');
85 0 ▶ return _owner_of(scalar eval { $candidate->_introspection_owner })
Branch: 1 branch
BranchTrueFalseTotal
if $candidate->can("_introspection_owner") 0 28 28
86 if $candidate->can('_introspection_owner');
87 28 return undef;
88 }
89 0 ▶ if (ref($candidate) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $candidate eq "HASH") 0 0 0
90 0 for my $key (qw(stream recipient owner object request)) {
91 0 my $owner = _owner_of($candidate->{$key});
92 0 ▶ return $owner if $owner;
Branch: 1 branch
BranchTrueFalseTotal
if $owner 0 0 0
93 }
94 }
95 0 return undef;
96 }
97  
98 17 ▶sub _fd ($object) {
Subroutine _fd: called CC=3 SCAR=11.1
99 17 ▶ return _value($object, 'fd') if $object->can('fd');
Branch: 1 branch
BranchTrueFalseTotal
if $object->can("fd") 12 5 17
100 5 my $fh = _value($object, 'fh');
101 5 ▶ return defined($fh) ? fileno($fh) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $fh ? : 0 5 5
102 }
103  
104 25 ▶sub inspect ($self, $object) {
Subroutine inspect: called CC=1 SCAR=0.0
Pod undocumented
105 25 return $self->_inspect_object($object, $self->has($object));
106 }
107  
108 35 ▶sub _inspect_object ($self, $object, $registered) {
Subroutine _inspect_object: called CC=23 SCAR=32.3
109 35 ▶ my $type = blessed($object) ? _type_of($object) : 'unknown';
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($object) ? : 35 0 35
110 35 ▶ my $result = {
Branch: 1 branch
BranchTrueFalseTotal
$registered ? : 33 2 35
Condition50%1/2
builtin::blessed($object) || undef
l!l
350
MC/DC0%0/1
builtin::blessed($object) || undef
builtin::blessed($object)
Truth table50%1/2
A
A= builtin::blessed($object)
Aresult
11
00
111 type => $type,
112 class => blessed($object) || undef,
113 registered => $registered ? 1 : 0,
114 };
115 35 ▶ return $result if !$registered;
Branch: 1 branch
BranchTrueFalseTotal
unless $registered 2 33 35
116  
117 33 $result->{state} = _value($object, 'state');
118 33 ▶ if ($type eq 'pipe' || $type eq 'tty' || $type eq 'stream') {
Branch: 7 branches
BranchTrueFalseTotal
if ($type eq 'pipe' or $type eq 'tty' or $type eq 'stream') { } 11 22 33
elsif ($type eq 'listener') { } 3 19 22
elsif ($type eq 'dgram') { } 3 16 19
elsif ($type eq 'timer') { } 4 12 16
elsif ($type eq 'signal') { } 3 9 12
elsif ($type eq 'inotify') { } 4 5 9
elsif ($type eq 'process') { } 3 2 5
Condition83%5/6
$type eq "pipe" or $type eq "tty" or $type eq "stream"
l!l&&r!l&&!r
5622
$type eq "pipe" or $type eq "tty"
l!l&&r!l&&!r
5028
MC/DC66%2/3
$type eq "pipe" or $type eq "tty" or $type eq "stream"
$type eq "pipe" $type eq "tty" $type eq "stream"
Truth table75%3/4
A or B or C
A= $type eq "pipe"B= $type eq "tty"C= $type eq "stream"
ABCresult
1XX1
01X1
0011
0000
119 11 ▶ @$result{qw(fd read_fd write_fd pending_bytes read_paused read_eof
Branch: 5 branches
BranchTrueFalseTotal
_value($object, 'is_read_paused') ? : 0 11 11
_value($object, 'is_read_eof') ? : 0 11 11
_value($object, 'is_read_closed') ? : 0 11 11
_value($object, 'is_write_ended') ? : 5 6 11
_value($object, 'is_write_blocked') ? : 0 11 11
120 read_closed write_ended write_blocked)} = (
121 _fd($object), _value($object, 'read_fd'),
122 _value($object, 'write_fd'),
123 _value($object, 'pending_bytes'),
124 _value($object, 'is_read_paused') ? 1 : 0,
125 _value($object, 'is_read_eof') ? 1 : 0,
126 _value($object, 'is_read_closed') ? 1 : 0,
127 _value($object, 'is_write_ended') ? 1 : 0,
128 _value($object, 'is_write_blocked') ? 1 : 0,
129 );
130 11 ▶ if ($type eq 'stream') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "stream") 6 5 11
131 6 @$result{qw(local peer transport)} = (
132 _value($object, 'local'), _value($object, 'peer'),
133 _value($object, 'transport_name'),
134 );
135 }
136 }
137 elsif ($type eq 'listener') {
138 3 ▶ @$result{qw(fd host port path family paused accepted)} = (
Branch: 1 branch
BranchTrueFalseTotal
_value($object, 'is_paused') ? : 0 3 3
139 _fd($object), _value($object, 'host'), _value($object, 'port'),
140 _value($object, 'path'), _value($object, 'family'),
141 _value($object, 'is_paused') ? 1 : 0,
142 _value($object, 'accepted'),
143 );
144 }
145 elsif ($type eq 'dgram') {
146 3 ▶ @$result{qw(fd local peer connected pending_bytes pending_datagrams
Branch: 2 branches
BranchTrueFalseTotal
_value($object, 'is_connected') ? : 0 3 3
_value($object, 'is_read_paused') ? : 0 3 3
147 read_paused)} = (
148 _fd($object), _value($object, 'local'),
149 _value($object, 'peer'),
150 _value($object, 'is_connected') ? 1 : 0,
151 _value($object, 'pending_bytes'),
152 _value($object, 'pending_datagrams'),
153 _value($object, 'is_read_paused') ? 1 : 0,
154 );
155 }
156 elsif ($type eq 'timer') {
157 4 @$result{qw(deadline interval expirations)} = (
158 _value($object, 'deadline'), _value($object, 'interval'),
159 _value($object, 'expirations'),
160 );
161 }
162 elsif ($type eq 'signal') {
163 3 $result->{signals} = _value($object, 'signals');
164 }
165 elsif ($type eq 'inotify') {
166 4 @$result{qw(fd watches)} = (
167 _value($object, 'fd'), _value($object, 'watch_count'),
168 );
169 }
170 elsif ($type eq 'process') {
171 3 @$result{qw(pid pending_stdin_bytes)} = (
172 _value($object, 'pid'), _value($object, 'pending_stdin_bytes'),
173 );
174 }
175 33 return $result;
176 }
177  
178 25 ▶sub resources ($self) {
Subroutine resources: called CC=1 SCAR=0.0
Pod undocumented
179 25 my $resource = $self->_resources_native;
180 25 $resource->{defer_fd} = $self->_deferred_fd;
181 25 $resource->{pending_deferred} = $self->_deferred_count;
182 25 return $resource;
183 }
184  
185 5 ▶sub why_alive ($self) {
Subroutine why_alive: called CC=2 SCAR=6.9
Pod undocumented
186 my @reason = map {
187 10 my $snapshot = $self->_inspect_object($_, 1);
188 10 $snapshot->{object} = $_;
189 10 $snapshot;
190 5 } @{ $self->_object_snapshot };
191 5 my $resources = $self->resources;
192 push @reason, map {
193 1 +{ type => 'registration', registered => 1, fd => $_ }
194 5 } @{ $resources->{public_registration_fds} };
195 push @reason, {
196 type => 'deferred', pending => $resources->{pending_deferred},
197 5 ▶ } if $resources->{pending_deferred};
Branch: 1 branch
BranchTrueFalseTotal
if $resources->{"pending_deferred"} 1 4 5
198 5 return \@reason;
199 }
200  
201 1 ▶sub pressure ($self) {
Subroutine pressure: called CC=6 SCAR=20.3
Pod undocumented
202 1 my $resource = $self->_resources_native;
203 1 my $stats = $self->stats;
204 1 my $registry_capacity = $resource->{registry_capacity};
205 1 my $timer_capacity = $resource->{timer_heap_capacity};
206 1 my $event_capacity = $resource->{event_capacity};
207 return {
208 registrations => {
209 active => $resource->{registered_fds},
210 capacity => $registry_capacity,
211 utilization => $registry_capacity
212 ? $resource->{registered_fds} / $registry_capacity : 0,
213 },
214 timers => {
215 active => $resource->{active_timers},
216 capacity => $timer_capacity,
217 utilization => $timer_capacity
218 ? $resource->{active_timers} / $timer_capacity : 0,
219 },
220 event_batch => {
221 capacity => $event_capacity,
222 maximum => $stats->{epoll_wait_calls}
223 ? $stats->{epoll_wait_max_batch} : undef,
224 utilization => $stats->{epoll_wait_calls} && $event_capacity
225 1 ▶ ? $stats->{epoll_wait_max_batch} / $event_capacity : undef,
Branch: 4 branches
BranchTrueFalseTotal
$registry_capacity ? : 1 0 1
$timer_capacity ? : 1 0 1
$stats->{'epoll_wait_calls'} ? : 0 1 1
$stats->{'epoll_wait_calls'} && $event_capacity ? : 0 1 1
Condition33%1/3
$stats->{"epoll_wait_calls"} and $event_capacity
!ll&&!rl&&r
100
MC/DC0%0/2
$stats->{"epoll_wait_calls"} and $event_capacity
$stats->{"epoll_wait_calls"} $event_capacity
Truth table33%1/3
A and B
A= $stats->{"epoll_wait_calls"}B= $event_capacity
ABresult
0X0
100
111
226 },
227 };
228 }
229  
230 181 1;
« blib/lib/Linux/Event/Kernel/Inotify.pm ↑ Summary blib/lib/Linux/Event/Kernel/Event.pm »