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

filter: Statementstmt 94.4% 102 / 108 Branchbran 71.8% 69 / 96 Conditioncond 57.8% 11 / 19 MC/DCmcdc 33.3% 4 / 12 Subroutinesub 100% 19 / 19 Podpod 0.0% 0 / 8 totaltotal 78.2% 205 / 262 CC 59 SCAR 23.8
CC
59
Cov
82%
_inspect_object
20.4
_owner_of
18.0
_type_of
10.0
CRAP 10.8
« blib/lib/Linux/Event/Framer/LengthPrefix.pm ↑ Summary blib/lib/Linux/Event/Framer.pm »
1 package Linux::Event::Loop::Introspection;
2 135 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 135 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 135 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 135 ▶use Scalar::Util qw(blessed refaddr);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 135 my @CENSUS_TYPES = qw(stream listener datagram timer signal wakeup process);
8  
9 325 ▶sub _type_of ($object) {
Subroutine _type_of: called CC=10 SCAR=23.0
10 325 ▶ return 'unknown'
Branch: 1 branch
BranchTrueFalseTotal
if $object->isa("Linux::Event::Stream::_Deadline") or $object->isa("Linux::Event::Datagram::_ReadyTimer") 18 307 325
Condition66%2/3
$object->isa("Linux::Event::Stream::_Deadline") or $object->isa("Linux::Event::Datagram::_ReadyTimer")
l!l&&r!l&&!r
018307
MC/DC50%1/2
$object->isa("Linux::Event::Stream::_Deadline") or $object->isa("Linux::Event::Datagram::_ReadyTimer")
$object->isa("Linux::Event::Stream::_Deadline") $object->isa("Linux::Event::Datagram::_ReadyTimer")
Truth table66%2/3
A or B
A= $object->isa("Linux::Event::Stream::_Deadline")B= $object->isa("Linux::Event::Datagram::_ReadyTimer")
ABresult
1X1
011
000
11 if $object->isa('Linux::Event::Stream::_Deadline')
12 || $object->isa('Linux::Event::Datagram::_ReadyTimer');
13 307 ▶ return 'stream' if $object->isa('Linux::Event::Stream');
Branch: 1 branch
BranchTrueFalseTotal
if $object->isa("Linux::Event::Stream") 38 269 307
14 269 ▶ return 'listener' if $object->isa('Linux::Event::Listener');
Branch: 1 branch
BranchTrueFalseTotal
if $object->isa("Linux::Event::Listener") 38 231 269
15 231 ▶ return 'datagram' if $object->isa('Linux::Event::Datagram');
Branch: 1 branch
BranchTrueFalseTotal
if $object->isa("Linux::Event::Datagram") 38 193 231
16 193 ▶ return 'timer' if $object->isa('Linux::Event::Timer');
Branch: 1 branch
BranchTrueFalseTotal
if $object->isa("Linux::Event::Timer") 65 128 193
17 128 ▶ return 'signal' if $object->isa('Linux::Event::Signal');
Branch: 1 branch
BranchTrueFalseTotal
if $object->isa("Linux::Event::Signal") 38 90 128
18 90 ▶ return 'wakeup' if $object->isa('Linux::Event::Wakeup');
Branch: 1 branch
BranchTrueFalseTotal
if $object->isa("Linux::Event::Wakeup") 36 54 90
19 54 ▶ return 'process' if $object->isa('Linux::Event::Process');
Branch: 1 branch
BranchTrueFalseTotal
if $object->isa("Linux::Event::Process") 38 16 54
20 16 return 'unknown';
21 }
22  
23 140 ▶sub _is_current ($self, $object) {
Subroutine _is_current: called CC=7 SCAR=20.8
24 140 ▶ 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 140 140
Condition33%1/3
not builtin::blessed($object) or _type_of($object) eq "unknown"
l!l&&r!l&&!r
00140
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
25 140 my $loop = eval { $object->loop };
26 140 ▶ return 0 if !$loop || refaddr($loop) != refaddr($self);
Branch: 1 branch
BranchTrueFalseTotal
if not $loop or builtin::refaddr($loop) != builtin::refaddr($self) 5 135 140
Condition100%3/3
not $loop or builtin::refaddr($loop) != builtin::refaddr($self)
l!l&&r!l&&!r
32135
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
27 return 0 if $object->can('is_terminal')
28 135 ▶ && eval { $object->is_terminal };
Branch: 1 branch
BranchTrueFalseTotal
if $object->can("is_terminal") and eval { do { $object->is_terminal } } 0 135 135
Condition33%1/3
$object->can("is_terminal") and eval { do { $object->is_terminal } }
!ll&&!rl&&r
01350
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
29 135 return 1;
30 }
31  
32 28 ▶sub _object_snapshot ($self) {
Subroutine _object_snapshot: called CC=8 SCAR=20.9
33 28 my @candidate = @{ $self->_object_candidates_native };
34 28 ▶ push @candidate, @{ Linux::Event::Signal->_objects_for_loop($self) }
Branch: 1 branch
BranchTrueFalseTotal
if "Linux::Event::Signal"->can("_objects_for_loop") 18 10 28
35 if Linux::Event::Signal->can('_objects_for_loop');
36 28 ▶ push @candidate, @{ Linux::Event::Wakeup->_objects_for_loop($self) }
Branch: 1 branch
BranchTrueFalseTotal
if "Linux::Event::Wakeup"->can("_objects_for_loop") 18 10 28
37 if Linux::Event::Wakeup->can('_objects_for_loop');
38 28 ▶ push @candidate, @{ Linux::Event::_Resolver->_objects_for_loop($self) }
Branch: 1 branch
BranchTrueFalseTotal
if "Linux::Event::_Resolver"->can("_objects_for_loop") 28 0 28
39 if Linux::Event::_Resolver->can('_objects_for_loop');
40  
41 28 my %seen;
42 my @result;
43 28 for my $candidate (@candidate) {
44 138 ▶ my $object = _owner_of($candidate) // next;
Condition100%2/2
_owner_of($candidate) // (next)
l!l
12018
MC/DC100%1/1
_owner_of($candidate) // (next)
_owner_of($candidate)
Truth table100%2/2
A
A= _owner_of($candidate)
Aresult
11
00
45 120 ▶ next if $seen{ refaddr($object) }++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen{builtin::refaddr($object)}++ 0 120 120
46 120 ▶ next if !$self->_is_current($object);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_current($object) 0 120 120
47 120 push @result, $object;
48 }
49 28 return \@result;
50 }
51  
52 6 ▶sub count ($self) { scalar @{ $self->_object_snapshot } }
Subroutine count: called CC=1 SCAR=0.0
Pod undocumented
53  
54 20 ▶sub has ($self, $object) {
Subroutine has: called CC=3 SCAR=11.0
Pod undocumented
55 20 ▶ return 0 if !blessed($object);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($object) 0 20 20
56 20 ▶ return 0 if !$self->_is_current($object);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_current($object) 5 15 20
57 15 my $id = refaddr($object);
58 15 return !!grep { refaddr($_) == $id } @{ $self->_object_snapshot };
59 }
60  
61 2 ▶sub objects ($self) { [ @{ $self->_object_snapshot } ] }
Subroutine objects: called CC=1 SCAR=0.0
Pod undocumented
62  
63 2 ▶sub census ($self) {
Subroutine census: called CC=2 SCAR=6.9
Pod undocumented
64 2 my %count = map { $_ => 0 } @CENSUS_TYPES;
65 2 $count{ _type_of($_) }++ for @{ $self->_object_snapshot };
66 2 return \%count;
67 }
68  
69 111 ▶sub _value ($object, $method) {
Subroutine _value: called CC=2 SCAR=7.1
70 111 ▶ return undef if !$object->can($method);
Branch: 1 branch
BranchTrueFalseTotal
unless $object->can($method) 0 111 111
71 111 return eval { $object->$method() };
72 }
73  
74 154 ▶sub _owner_of ($candidate) {
Subroutine _owner_of: called CC=9 SCAR=28.9
75 154 ▶ return undef if !ref($candidate);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $candidate 0 154 154
76 154 ▶ if (blessed($candidate)) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($candidate)) 154 0 154
77 154 ▶ return $candidate if _type_of($candidate) ne 'unknown';
Branch: 1 branch
BranchTrueFalseTotal
if _type_of($candidate) ne "unknown" 120 34 154
78 34 ▶ return _owner_of(eval { $candidate->stream })
Branch: 1 branch
BranchTrueFalseTotal
if $candidate->isa("Linux::Event::Stream::XSState") 16 18 34
79 if $candidate->isa('Linux::Event::Stream::XSState');
80 0 ▶ return _owner_of(eval { $candidate->_introspection_owner })
Branch: 1 branch
BranchTrueFalseTotal
if $candidate->can("_introspection_owner") 0 18 18
81 if $candidate->can('_introspection_owner');
82 18 return undef;
83 }
84 0 ▶ if (ref($candidate) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $candidate eq "HASH") 0 0 0
85 0 for my $key (qw(stream recipient owner object request)) {
86 0 my $owner = _owner_of($candidate->{$key});
87 0 ▶ return $owner if $owner;
Branch: 1 branch
BranchTrueFalseTotal
if $owner 0 0 0
88 }
89 }
90 0 return undef;
91 }
92  
93 9 ▶sub _fd ($object) {
Subroutine _fd: called CC=3 SCAR=11.1
94 9 ▶ return _value($object, 'fd') if $object->can('fd');
Branch: 1 branch
BranchTrueFalseTotal
if $object->can("fd") 6 3 9
95 3 my $fh = _value($object, 'fh');
96 3 ▶ return defined($fh) ? fileno($fh) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $fh ? : 3 0 3
97 }
98  
99 15 ▶sub inspect ($self, $object) {
Subroutine inspect: called CC=1 SCAR=0.0
Pod undocumented
100 15 return $self->_inspect_object($object, $self->has($object));
101 }
102  
103 23 ▶sub _inspect_object ($self, $object, $registered) {
Subroutine _inspect_object: called CC=18 SCAR=30.2
104 23 ▶ my $type = blessed($object) ? _type_of($object) : 'unknown';
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($object) ? : 23 0 23
105 23 ▶ my $result = {
Branch: 1 branch
BranchTrueFalseTotal
$registered ? : 21 2 23
Condition50%1/2
builtin::blessed($object) || undef
l!l
230
MC/DC0%0/1
builtin::blessed($object) || undef
builtin::blessed($object)
Truth table50%1/2
A
A= builtin::blessed($object)
Aresult
11
00
106 type => $type,
107 class => blessed($object) || undef,
108 registered => $registered ? 1 : 0,
109 };
110 23 ▶ return $result if !$registered;
Branch: 1 branch
BranchTrueFalseTotal
unless $registered 2 21 23
111  
112 21 $result->{state} = _value($object, 'state');
113 21 ▶ if ($type eq 'stream') {
Branch: 6 branches
BranchTrueFalseTotal
if ($type eq 'stream') { } 3 18 21
elsif ($type eq 'listener') { } 3 15 18
elsif ($type eq 'datagram') { } 3 12 15
elsif ($type eq 'timer') { } 4 8 12
elsif ($type eq 'signal') { } 3 5 8
elsif ($type eq 'process') { } 3 2 5
114 3 ▶ @$result{qw(fd local peer transport pending_bytes read_paused
Branch: 4 branches
BranchTrueFalseTotal
_value($object, 'is_read_paused') ? : 0 3 3
_value($object, 'is_read_eof') ? : 0 3 3
_value($object, 'is_write_ended') ? : 0 3 3
_value($object, 'is_write_blocked') ? : 0 3 3
115 read_eof write_ended write_blocked)} = (
116 _fd($object), _value($object, 'local'),
117 _value($object, 'peer'), _value($object, 'transport_name'),
118 _value($object, 'pending_bytes'),
119 _value($object, 'is_read_paused') ? 1 : 0,
120 _value($object, 'is_read_eof') ? 1 : 0,
121 _value($object, 'is_write_ended') ? 1 : 0,
122 _value($object, 'is_write_blocked') ? 1 : 0,
123 );
124 }
125 elsif ($type eq 'listener') {
126 3 ▶ @$result{qw(fd host port path family paused accepted)} = (
Branch: 1 branch
BranchTrueFalseTotal
_value($object, 'is_paused') ? : 0 3 3
127 _fd($object), _value($object, 'host'), _value($object, 'port'),
128 _value($object, 'path'), _value($object, 'family'),
129 _value($object, 'is_paused') ? 1 : 0,
130 _value($object, 'accepted'),
131 );
132 }
133 elsif ($type eq 'datagram') {
134 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
135 read_paused)} = (
136 _fd($object), _value($object, 'local'),
137 _value($object, 'peer'),
138 _value($object, 'is_connected') ? 1 : 0,
139 _value($object, 'pending_bytes'),
140 _value($object, 'pending_datagrams'),
141 _value($object, 'is_read_paused') ? 1 : 0,
142 );
143 }
144 elsif ($type eq 'timer') {
145 4 @$result{qw(deadline interval expirations)} = (
146 _value($object, 'deadline'), _value($object, 'interval'),
147 _value($object, 'expirations'),
148 );
149 }
150 elsif ($type eq 'signal') {
151 3 $result->{signals} = _value($object, 'signals');
152 }
153 elsif ($type eq 'process') {
154 3 @$result{qw(pid pending_stdin_bytes)} = (
155 _value($object, 'pid'), _value($object, 'pending_stdin_bytes'),
156 );
157 }
158 21 return $result;
159 }
160  
161 2 ▶sub resources ($self) { $self->_resources_native }
Subroutine resources: called CC=1 SCAR=0.0
Pod undocumented
162  
163 3 ▶sub why_alive ($self) {
Subroutine why_alive: called CC=1 SCAR=0.0
Pod undocumented
164 my @reason = map {
165 8 my $snapshot = $self->_inspect_object($_, 1);
166 8 $snapshot->{object} = $_;
167 8 $snapshot;
168 3 } @{ $self->_object_snapshot };
169 3 my $resources = $self->_resources_native;
170 push @reason, map {
171 1 +{ type => 'registration', registered => 1, fd => $_ }
172 3 } @{ $resources->{public_registration_fds} };
173 3 return \@reason;
174 }
175  
176 1 ▶sub pressure ($self) {
Subroutine pressure: called CC=6 SCAR=20.3
Pod undocumented
177 1 my $resource = $self->_resources_native;
178 1 my $stats = $self->stats;
179 1 my $registry_capacity = $resource->{registry_capacity};
180 1 my $timer_capacity = $resource->{timer_heap_capacity};
181 1 my $event_capacity = $resource->{event_capacity};
182 return {
183 registrations => {
184 active => $resource->{registered_fds},
185 capacity => $registry_capacity,
186 utilization => $registry_capacity
187 ? $resource->{registered_fds} / $registry_capacity : 0,
188 },
189 timers => {
190 active => $resource->{active_timers},
191 capacity => $timer_capacity,
192 utilization => $timer_capacity
193 ? $resource->{active_timers} / $timer_capacity : 0,
194 },
195 event_batch => {
196 capacity => $event_capacity,
197 maximum => $stats->{epoll_wait_calls}
198 ? $stats->{epoll_wait_max_batch} : undef,
199 utilization => $stats->{epoll_wait_calls} && $event_capacity
200 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
201 },
202 };
203 }
204  
205 135 1;
« blib/lib/Linux/Event/Framer/LengthPrefix.pm ↑ Summary blib/lib/Linux/Event/Framer.pm »