Monitor/Backends/cgroups.pm

filter: Statementstmt 50.4% 232 / 460 Branchbran 42.1% 97 / 230 Conditioncond 16.9% 35 / 207 MC/DCmcdc 11.0% 11 / 100 Subroutinesub 100% 16 / 16 Podpod 37.5% 3 / 8 totaltotal 38.5% 394 / 1021 CC 204 SCAR 89.2
CC
204
Cov
41%
run
11990.6
route_get_if
23.2
cgroup_mapping
23.1
CRAP 7452.2
↑ Summary Monitor/Backends/FreeBSD.pm »
1 package OSLV::Monitor::Backends::cgroups;
2  
3 8 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 8 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 8 ▶use Clone 'clone';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 8 ▶use File::Slurp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 8 ▶use Scalar::Util qw(looks_like_number);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 8 ▶use Time::HiRes qw(time);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 =head1 NAME
13  
14 OSLV::Monitor::Backends::cgroups - Backend for Linux cgroups.
15  
16 =head1 VERSION
17  
18 Version 1.0.6
19  
20 =cut
21  
22 8 our $VERSION = '1.0.6';
23  
24 =head1 SYNOPSIS
25  
26 use OSLV::Monitor::Backends::cgroups;
27  
28 my $backend = OSLV::Monitor::Backends::cgroups->new;
29  
30 my $usable=$backend->usable;
31 if ( $usable ){
32 $return_hash_ref=$backend->run;
33 }
34  
35 The cgroup to name mapping is done like below.
36  
37 systemd -> s_$name
38 user -> u_$name
39 docker -> d_$name
40 podman -> p_$name
41 machine.slice, non-podman -> m_$type_$name
42 type is qemu, lxc, or nspawn, omitted if unknown
43 anything else -> $name
44  
45 Anything else is formed like below.
46  
47 $cgroup =~ s/^0\:\:\///;
48 $cgroup =~ s/\/.*//;
49  
50 The following ps to stats mapping are as below.
51  
52 %cpu -> percent-cpu
53 %mem -> percent-memory
54 rss -> rss
55 vsize -> virtual-size
56 trs -> text-size
57 drs -> data-size
58 size -> size
59  
60 "procs" is a total number of procs in that cgroup.
61  
62 The rest of the values are pulled from the following files with
63 the names kept as is.
64  
65 cpu.stat
66 io.stat
67 memory.stat
68  
69 The following mappings are done though.
70  
71 pgfault -> minor-faults
72 pgmajfault -> major-faults
73 usage_usec -> cpu-time
74 system_usec -> system-time
75 user_usec -> user-time
76 throttled_usec -> throttled-time
77 burst_usec -> burst-time
78  
79 =head1 METHODS
80  
81 =head2 new
82  
83 Initiates the backend object.
84  
85 my $backend=OSLV::MOnitor::Backend::cgroups->new(obj=>$obj)
86  
87 - base_dir :: Path to use for the base dir, where the proc/cgroup
88 cache, linux_cache.json, is is created.
89 Default :: /var/cache/oslv_monitor
90  
91 - obj :: The OSLVM::Monitor object.
92  
93 - time_divider :: What to use for "usec" to sec conversion. While normally
94 the usec counters are microseconds, sometimes the value is in
95 nanoseconds, despit the name.
96 Default :: 1000000
97  
98 =cut
99  
100 28 ▶sub new {
Subroutine new: called CC=6 SCAR=17.9
Pod documented
101 28 my ( $blank, %opts ) = @_;
102  
103 28 ▶ if ( !defined( $opts{base_dir} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $opts{"base_dir"}) 1 27 28
104 1 $opts{base_dir} = '/var/cache/oslv_monitor';
105 }
106  
107 28 ▶ if ( !defined( $opts{time_divider} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $opts{'time_divider'}) { } 25 3 28
108 25 $opts{time_divider} = 1000000;
109 } else {
110 3 ▶ if ( !looks_like_number( $opts{time_divider} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&looks_like_number($opts{"time_divider"})) 1 2 3
111 1 die('time_divider is not a number');
112 }
113 }
114  
115 27 ▶ if ( !defined( $opts{obj} ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $opts{'obj'}) { } 1 26 27
elsif (ref $opts{'obj'} ne 'OSLV::Monitor') { } 1 25 26
116 1 die('$opts{obj} is undef');
117 } elsif ( ref( $opts{obj} ) ne 'OSLV::Monitor' ) {
118 1 die('ref $opts{obj} is not OSLV::Monitor');
119 }
120  
121 my $self = {
122 time_divider => $opts{time_divider},
123 version => 1,
124 cgroupns_usable => 1,
125 mappings => {},
126 podman_mapping => {},
127 podman_info => {},
128 docker_mapping => {},
129 docker_info => {},
130 uid_mapping => {},
131 obj => $opts{obj},
132 25 cache_file => $opts{base_dir} . '/linux_cache.json',
133 counters => {
134 'cpu-time' => 1,
135 'system-time' => 1,
136 'user-time' => 1,
137 'throttled-time' => 1,
138 'burst-time' => 1,
139 'core_sched.force_idle-time' => 1,
140 'read-blocks' => 1,
141 'major-faults' => 1,
142 'involuntary-context-switches' => 1,
143 'minor-faults' => 1,
144 'nr_bursts' => 1,
145 'nr_periods' => 1,
146 'nr_throttled' => 1,
147 'received-messages' => 1,
148 'sent-messages' => 1,
149 'swaps' => 1,
150 'voluntary-context-switches' => 1,
151 'written-blocks' => 1,
152 'copy-on-write-faults' => 1,
153 'signals-taken' => 1,
154 'rbytes' => 1,
155 'wbytes' => 1,
156 'dbytes' => 1,
157 'rios' => 1,
158 'wios' => 1,
159 'dios' => 1,
160 'pgactivate' => 1,
161 'pgdeactivate' => 1,
162 'pglazyfree' => 1,
163 'pglazyfreed' => 1,
164 'pgrefill' => 1,
165 'pgscan' => 1,
166 'pgscan_direct' => 1,
167 'pgscan_khugepaged' => 1,
168 'pgscan_kswapd' => 1,
169 'pgsteal' => 1,
170 'pgsteal_direct' => 1,
171 'pgsteal_khugepaged' => 1,
172 'pgsteal_kswapd' => 1,
173 'thp_fault_alloc' => 1,
174 'thp_collapse_alloc' => 1,
175 'thp_swpout' => 1,
176 'thp_swpout_fallback' => 1,
177 'zswpin' => 1,
178 'zswpout' => 1,
179 'zswpwb' => 1,
180 },
181 cache => {},
182 new_cache => {},
183 # seconds since the previous run, for turning counter deltas into rates...
184 # set by run from the time saved in the cache, 300 if that is unknown
185 interval => 300,
186 };
187 25 bless $self;
188  
189 25 return $self;
190 } ## end sub new
191  
192 =head2 run
193  
194 $return_hash_ref=$backend->run(obj=>$obj);
195  
196 =cut
197  
198 4 ▶sub run {
Subroutine run: called CC=136 SCAR=93.9
Pod documented
199 4 my $self = $_[0];
200  
201 4 my $data = {
202 errors => [],
203 cache_failure => 0,
204 oslvms => {},
205 has => {
206 'linux_mem_stats' => 1,
207 'rwdops' => 0,
208 'rwdbytes' => 0,
209 'rwdblocks' => 0,
210 'signals-taken' => 0,
211 'recv_sent_msgs' => 0,
212 'cows' => 0,
213 'stack-size' => 0,
214 'swaps' => 0,
215 'sock' => 1,
216 'burst_time' => 0,
217 'throttled_time' => 0,
218 'burst_count' => 0,
219 'throttled_count' => 0,
220 },
221 totals => {
222 procs => 0,
223 'percent-cpu' => 0,
224 'percent-memory' => 0,
225 'system-time' => 0,
226 'cpu-time' => 0,
227 'user-time' => 0,
228 rbytes => 0,
229 wbytes => 0,
230 rios => 0,
231 wios => 0,
232 dbytes => 0,
233 dios => 0,
234 'core_sched.force_idle_usec' => 0,
235 'core_sched.force_idle-time' => 0,
236 nr_periods => 0,
237 nr_throttled => 0,
238 throttled_usec => 0,
239 'throttled-time' => 0,
240 nr_bursts => 0,
241 burst_usec => 0,
242 'burst-time' => 0,
243 anon => 0,
244 file => 0,
245 kernel => 0,
246 kernel_stack => 0,
247 pagetables => 0,
248 sec_pagetables => 0,
249 percpu => 0,
250 sock => 0,
251 vmalloc => 0,
252 shmem => 0,
253 zswap => 0,
254 zswapped => 0,
255 file_mapped => 0,
256 file_dirty => 0,
257 file_writeback => 0,
258 swapcached => 0,
259 anon_thp => 0,
260 file_thp => 0,
261 shmem_thp => 0,
262 inactive_anon => 0,
263 active_anon => 0,
264 inactive_file => 0,
265 active_file => 0,
266 unevictable => 0,
267 slab_reclaimable => 0,
268 slab_unreclaimable => 0,
269 slab => 0,
270 workingset_refault_anon => 0,
271 workingset_refault_file => 0,
272 workingset_activate_anon => 0,
273 workingset_activate_file => 0,
274 workingset_restore_anon => 0,
275 workingset_restore_file => 0,
276 workingset_nodereclaim => 0,
277 pgscan => 0,
278 pgsteal => 0,
279 pgscan_kswapd => 0,
280 pgscan_direct => 0,
281 pgscan_khugepaged => 0,
282 pgsteal_kswapd => 0,
283 pgsteal_direct => 0,
284 pgsteal_khugepaged => 0,
285 'minor-faults' => 0,
286 'major-faults' => 0,
287 pgrefill => 0,
288 pgactivate => 0,
289 pgdeactivate => 0,
290 pglazyfree => 0,
291 pglazyfreed => 0,
292 zswpin => 0,
293 zswpout => 0,
294 zswpwb => 0,
295 thp_fault_alloc => 0,
296 thp_collapse_alloc => 0,
297 thp_swpout => 0,
298 thp_swpout_fallback => 0,
299 rss => 0,
300 'data-size' => 0,
301 'text-size' => 0,
302 'size' => 0,
303 'virtual-size' => 0,
304 'elapsed-times' => 0,
305 'involuntary-context-switches' => 0,
306 'voluntary-context-switches' => 0,
307 },
308 };
309  
310 4 my $cache_is_new = 0;
311 4 ▶ if ( -f $self->{cache_file} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $self->{'cache_file'}) { } 2 2 4
312 2 eval {
313 2 my $raw_cache = read_file( $self->{cache_file} );
314 2 $self->{cache} = decode_json($raw_cache);
315 };
316 2 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 2 2
317 push(
318 0 @{ $data->{errors} },
319 0 'reading proc cache "' . $self->{cache_file} . '" failed... using a empty one...' . $@
320 );
321 0 $data->{cache_failure} = 1;
322 # treat a corrupt/truncated cache as a fresh one so this run
323 # regenerates and overwrites it with valid data instead of getting
324 # permanently stuck on the bad file
325 0 $self->{cache} = {};
326 0 $cache_is_new = 1;
327 }
328 } else {
329 2 $cache_is_new = 1;
330 }
331  
332 # rates are computed over the time since the previous run, as saved in the
333 # cache, instead of assuming it was 300 seconds ago
334 4 my $run_time = time;
335 4 $self->{interval} = $self->{obj}->interval_since( $self->{cache}, $run_time );
336 4 $self->{new_cache}{__oslv_monitor__} = { time => $run_time };
337  
338 4 my $base_stats = {
339 procs => 0,
340 'percent-cpu' => 0,
341 'percent-memory' => 0,
342 'system-time' => 0,
343 'cpu-time' => 0,
344 'user-time' => 0,
345 rbytes => 0,
346 wbytes => 0,
347 rios => 0,
348 wios => 0,
349 dbytes => 0,
350 dios => 0,
351 'core_sched.force_idle_usec' => 0,
352 'core_sched.force_idle-time' => 0,
353 nr_periods => 0,
354 nr_throttled => 0,
355 throttled_usec => 0,
356 'throttled-time' => 0,
357 nr_bursts => 0,
358 burst_usec => 0,
359 'burst-time' => 0,
360 anon => 0,
361 file => 0,
362 kernel => 0,
363 kernel_stack => 0,
364 pagetables => 0,
365 sec_pagetables => 0,
366 percpu => 0,
367 sock => 0,
368 vmalloc => 0,
369 shmem => 0,
370 zswap => 0,
371 zswapped => 0,
372 file_mapped => 0,
373 file_dirty => 0,
374 file_writeback => 0,
375 swapcached => 0,
376 anon_thp => 0,
377 file_thp => 0,
378 shmem_thp => 0,
379 inactive_anon => 0,
380 active_anon => 0,
381 inactive_file => 0,
382 active_file => 0,
383 unevictable => 0,
384 slab_reclaimable => 0,
385 slab_unreclaimable => 0,
386 slab => 0,
387 workingset_refault_anon => 0,
388 workingset_refault_file => 0,
389 workingset_activate_anon => 0,
390 workingset_activate_file => 0,
391 workingset_restore_anon => 0,
392 workingset_restore_file => 0,
393 workingset_nodereclaim => 0,
394 pgscan => 0,
395 pgsteal => 0,
396 pgscan_kswapd => 0,
397 pgscan_direct => 0,
398 pgscan_khugepaged => 0,
399 pgsteal_kswapd => 0,
400 pgsteal_direct => 0,
401 pgsteal_khugepaged => 0,
402 'minor-faults' => 0,
403 'major-faults' => 0,
404 pgrefill => 0,
405 pgactivate => 0,
406 pgdeactivate => 0,
407 pglazyfree => 0,
408 pglazyfreed => 0,
409 zswpin => 0,
410 zswpout => 0,
411 zswpwb => 0,
412 thp_fault_alloc => 0,
413 thp_collapse_alloc => 0,
414 thp_swpout => 0,
415 thp_swpout_fallback => 0,
416 rss => 0,
417 'data-size' => 0,
418 'text-size' => 0,
419 'size' => 0,
420 'virtual-size' => 0,
421 'elapsed-times' => 0,
422 'involuntary-context-switches' => 0,
423 'voluntary-context-switches' => 0,
424 'ip' => [],
425 'path' => [],
426 };
427  
428 4 my $stat_mapping = {
429 'pgmajfault' => 'major-faults',
430 'pgfault' => 'minor-faults',
431 'usage_usec' => 'cpu-time',
432 'user_usec' => 'user-time',
433 'system_usec' => 'system-time',
434 'throttled_usec' => 'throttled-time',
435 'burst_usec' => 'burst-time',
436 'core_sched.force_idle_usec' => 'core_sched.force_idle-time',
437 };
438  
439 #
440 # get podman/docker ID to name mappings
441 #
442 4 my @podman_compatible = ( 'docker', 'podman' );
443 4 foreach my $cgroup_jank_type (@podman_compatible) {
444 8 my $podman_output;
445 8 ▶ if ( $cgroup_jank_type eq 'podman' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($cgroup_jank_type eq 'podman') { } 4 4 8
elsif ($cgroup_jank_type eq 'docker') { } 4 0 4
446 4 $podman_output = `podman ps --format json 2> /dev/null`;
447 } elsif ( $cgroup_jank_type eq 'docker' ) {
448 # --no-trunc is needed as for some unfathonable reason it truncates even when outputting json
449 4 $podman_output = `docker ps --no-trunc --format json 2> /dev/null`;
450 # returns a series of json entries seperated by a newline... the following expects it as
451 # a array like podman outputs
452 4 my @podman_outputA = split( /\n/, $podman_output );
453 # and it is now a array of hashes as expected
454 4 $podman_output = '[' . join( ',', @podman_outputA ) . ']';
455 }
456 8 ▶ if ( $? == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? == 0) 0 8 8
457 0 my $podman_parsed;
458 0 eval { $podman_parsed = decode_json($podman_output); };
459 0 ▶ if ( defined($podman_parsed) && ref($podman_parsed) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $podman_parsed and ref $podman_parsed eq "ARRAY") 0 0 0
Condition0%0/3
defined $podman_parsed and ref $podman_parsed eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $podman_parsed and ref $podman_parsed eq "ARRAY"
defined $podman_parsed ref $podman_parsed eq "ARRAY"
Truth table0%0/3
A and B
A= defined $podman_parsedB= ref $podman_parsed eq "ARRAY"
ABresult
0X0
100
111
460 0 foreach my $pod ( @{$podman_parsed} ) {
461 0 my $pod_id;
462 0 ▶ if ( defined( $pod->{'Id'} ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $pod->{'Id'}) { } 0 0 0
elsif (defined $pod->{'ID'}) { } 0 0 0
463 0 $pod_id = $pod->{'Id'};
464 } elsif ( defined( $pod->{'ID'} ) ) {
465 0 $pod_id = $pod->{'ID'};
466 }
467  
468 0 my $pod_name;
469 0 ▶ if ( defined( $pod->{'PodName'} )
Branch: 3 branches
BranchTrueFalseTotal
if (defined $pod->{'PodName'} and $pod->{'PodName'} ne '') { } 0 0 0
elsif (defined $pod->{'Names'} and ref $pod->{'Names'} eq '') { } 0 0 0
elsif (defined $pod->{'Names'} and ref $pod->{'Names'} eq 'ARRAY' and defined $pod->{'Names'}[0] and ref $pod->{'Names'}[0] eq '') { } 0 0 0
Condition0%0/3
defined $pod->{"PodName"} and $pod->{"PodName"} ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
defined $pod->{"PodName"} and $pod->{"PodName"} ne ""
defined $pod->{"PodName"} $pod->{"PodName"} ne ""
Truth table0%0/3
A and B
A= defined $pod->{"PodName"}B= $pod->{"PodName"} ne ""
ABresult
0X0
100
111
470 && ( $pod->{'PodName'} ne '' ) )
471 {
472 0 $pod_name = $pod->{'PodName'};
473 ▶ } elsif ( defined( $pod->{'Names'} )
Condition0%0/3
defined $pod->{"Names"} and ref $pod->{"Names"} eq ""
!ll&&!rl&&r
000
MC/DC0%0/2
defined $pod->{"Names"} and ref $pod->{"Names"} eq ""
defined $pod->{"Names"} ref $pod->{"Names"} eq ""
Truth table0%0/3
A and B
A= defined $pod->{"Names"}B= ref $pod->{"Names"} eq ""
ABresult
0X0
100
111
474 && ( ref( $pod->{'Names'} ) eq '' ) )
475 {
476 0 $pod_name = $pod->{'Names'};
477 ▶ } elsif ( defined( $pod->{'Names'} )
Condition0%0/9
defined $pod->{"Names"} and ref $pod->{"Names"} eq "ARRAY" and defined $pod->{"Names"}[0] and ref $pod->{"Names"}[0] eq ""
!ll&&!rl&&r
000
defined $pod->{"Names"} and ref $pod->{"Names"} eq "ARRAY" and defined $pod->{"Names"}[0]
!ll&&!rl&&r
000
defined $pod->{"Names"} and ref $pod->{"Names"} eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/4
defined $pod->{"Names"} and ref $pod->{"Names"} eq "ARRAY" and defined $pod->{"Names"}[0] and ref $pod->{"Names"}[0] eq ""
defined $pod->{"Names"} ref $pod->{"Names"} eq "ARRAY" defined $pod->{"Names"}[0] ref $pod->{"Names"}[0] eq ""
Truth table0%0/5
A and B and C and D
A= defined $pod->{"Names"}B= ref $pod->{"Names"} eq "ARRAY"C= defined $pod->{"Names"}[0]D= ref $pod->{"Names"}[0] eq ""
ABCDresult
0XXX0
10XX0
110X0
11100
11111
478 && ( ref( $pod->{'Names'} ) eq 'ARRAY' )
479 && defined( $pod->{'Names'}[0] )
480 && ( ref( $pod->{'Names'}[0] ) eq '' ) )
481 {
482 0 $pod_name = $pod->{'Names'}[0];
483 }
484  
485 0 ▶ if ( defined($pod_id) && defined($pod_name) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pod_id and defined $pod_name) 0 0 0
Condition0%0/3
defined $pod_id and defined $pod_name
!ll&&!rl&&r
000
MC/DC0%0/2
defined $pod_id and defined $pod_name
defined $pod_id defined $pod_name
Truth table0%0/3
A and B
A= defined $pod_idB= defined $pod_name
ABresult
0X0
100
111
486 $self->{ $cgroup_jank_type . '_mapping' }{$pod_id} = {
487 name => $pod_name,
488 Networks => $pod->{Networks},
489 0 };
490 0 my $inspect_output = `$cgroup_jank_type inspect $pod_id 2> /dev/null`;
491 0 my $inspect_parsed;
492 # every container in a podman pod maps to the pod name, so the info is
493 # only created for the first and the rest are merged into it
494 0 ▶ if ( !defined( $self->{ $cgroup_jank_type . '_info' }{$pod_name} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $$self{$cgroup_jank_type . '_info'}{$pod_name}) 0 0 0
495 0 $self->{ $cgroup_jank_type . '_info' }{$pod_name} = { ip => [], path => [] };
496 }
497 0 my $pod_info = $self->{ $cgroup_jank_type . '_info' }{$pod_name};
498 0 eval { $inspect_parsed = decode_json($inspect_output) };
499 # record the container's root filesystem path when available
500 0 ▶ if ( defined($inspect_parsed)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $inspect_parsed and ref $inspect_parsed eq "ARRAY" and defined $inspect_parsed->[0] and ref $inspect_parsed->[0] eq "HASH" and defined $inspect_parsed->[0]{"GraphDriver"} and ref $inspect_parsed->[0]{"GraphDriver"} eq "HASH" and defined $inspect_parsed->[0]{"GraphDriver"}{"Data"} and ref $inspect_parsed->[0]{"GraphDriver"}{"Data"} eq "HASH" and defined $inspect_parsed->[0]{"GraphDriver"}{"Data"}{"MergedDir"} and ref $inspect_parsed->[0]{"GraphDriver"}{"Data"}{"MergedDir"} eq "" and $inspect_parsed->[0]{"GraphDriver"}{"Data"}{"MergedDir"} ne "") 0 0 0
Condition0%0/30
defined $inspect_parsed and ref $inspect_parsed eq "ARRAY" and defined $inspect_parsed->[0] and ref $inspect_parsed->[0] eq "HASH" and defined $inspect_parsed->[0]{"GraphDriver"} and ref $inspect_parsed->[0]{"GraphDriver"} eq "HASH" and defined $inspect_parsed->[0]{"GraphDriver"}{"Data"} and ref $inspect_parsed->[0]{"GraphDriver"}{"Data"} eq "HASH" and defined $inspect_parsed->[0]{"GraphDriver"}{"Data"}{"MergedDir"} and ref $inspect_parsed->[0]{"GraphDriver"}{"Data"}{"MergedDir"} eq "" and $inspect_parsed->[0]{"GraphDriver"}{"Data"}{"MergedDir"} ne ""
!ll&&!rl&&r
000
defined $inspect_parsed and ref $inspect_parsed eq "ARRAY" and defined $inspect_parsed->[0] and ref $inspect_parsed->[0] eq "HASH" and defined $inspect_parsed->[0]{"GraphDriver"} and ref $inspect_parsed->[0]{"GraphDriver"} eq "HASH" and defined $inspect_parsed->[0]{"GraphDriver"}{"Data"} and ref $inspect_parsed->[0]{"GraphDriver"}{"Data"} eq "HASH" and defined $inspect_parsed->[0]{"GraphDriver"}{"Data"}{"MergedDir"} and ref $inspect_parsed->[0]{"GraphDriver"}{"Data"}{"MergedDir"} eq ""
!ll&&!rl&&r
000
defined $inspect_parsed and ref $inspect_parsed eq "ARRAY" and defined $inspect_parsed->[0] and ref $inspect_parsed->[0] eq "HASH" and defined $inspect_parsed->[0]{"GraphDriver"} and ref $inspect_parsed->[0]{"GraphDriver"} eq "HASH" and defined $inspect_parsed->[0]{"GraphDriver"}{"Data"} and ref $inspect_parsed->[0]{"GraphDriver"}{"Data"} eq "HASH" and defined $inspect_parsed->[0]{"GraphDriver"}{"Data"}{"MergedDir"}
!ll&&!rl&&r
000
defined $inspect_parsed and ref $inspect_parsed eq "ARRAY" and defined $inspect_parsed->[0] and ref $inspect_parsed->[0] eq "HASH" and defined $inspect_parsed->[0]{"GraphDriver"} and ref $inspect_parsed->[0]{"GraphDriver"} eq "HASH" and defined $inspect_parsed->[0]{"GraphDriver"}{"Data"} and ref $inspect_parsed->[0]{"GraphDriver"}{"Data"} eq "HASH"
!ll&&!rl&&r
000
defined $inspect_parsed and ref $inspect_parsed eq "ARRAY" and defined $inspect_parsed->[0] and ref $inspect_parsed->[0] eq "HASH" and defined $inspect_parsed->[0]{"GraphDriver"} and ref $inspect_parsed->[0]{"GraphDriver"} eq "HASH" and defined $inspect_parsed->[0]{"GraphDriver"}{"Data"}
!ll&&!rl&&r
000
defined $inspect_parsed and ref $inspect_parsed eq "ARRAY" and defined $inspect_parsed->[0] and ref $inspect_parsed->[0] eq "HASH" and defined $inspect_parsed->[0]{"GraphDriver"} and ref $inspect_parsed->[0]{"GraphDriver"} eq "HASH"
!ll&&!rl&&r
000
defined $inspect_parsed and ref $inspect_parsed eq "ARRAY" and defined $inspect_parsed->[0] and ref $inspect_parsed->[0] eq "HASH" and defined $inspect_parsed->[0]{"GraphDriver"}
!ll&&!rl&&r
000
defined $inspect_parsed and ref $inspect_parsed eq "ARRAY" and defined $inspect_parsed->[0] and ref $inspect_parsed->[0] eq "HASH"
!ll&&!rl&&r
000
defined $inspect_parsed and ref $inspect_parsed eq "ARRAY" and defined $inspect_parsed->[0]
!ll&&!rl&&r
000
defined $inspect_parsed and ref $inspect_parsed eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/11
defined $inspect_parsed and ref $inspect_parsed eq "ARRAY" and defined $inspect_parsed->[0] and ref $inspect_parsed->[0] eq "HASH" and defined $inspect_parsed->[0]{"GraphDriver"} and ref $inspect_parsed->[0]{"GraphDriver"} eq "HASH" and defined $inspect_parsed->[0]{"GraphDriver"}{"Data"} and ref $inspect_parsed->[0]{"GraphDriver"}{"Data"} eq "HASH" and defined $inspect_parsed->[0]{"GraphDriver"}{"Data"}{"MergedDir"} and ref $inspect_parsed->[0]{"GraphDriver"}{"Data"}{"MergedDir"} eq "" and $inspect_parsed->[0]{"GraphDriver"}{"Data"}{"MergedDir"} ne ""
defined $inspect_parsed ref $inspect_parsed eq "ARRAY" defined $inspect_parsed->[0] ref $inspect_parsed->[0] eq "HASH" defined $inspect_parsed->[0]{"GraphDriver"} ref $inspect_parsed->[0]{"GraphDriver"} eq "HASH" defined $inspect_parsed->[0]{"GraphDriver"}{"Data"} ref $inspect_parsed->[0]{"GraphDriver"}{"Data"} eq "HASH" defined $inspect_parsed->[0]{"GraphDriver"}{"Data"}{"MergedDir"} ref $inspect_parsed->[0]{"GraphDriver"}{"Data"}{"MergedDir"} eq "" $inspect_parsed->[0]{"GraphDriver"}{"Data"}{"MergedDir"} ne ""
Truth table0%0/12
A and B and C and D and E and F and G and H and I and J and K
A= defined $inspect_parsedB= ref $inspect_parsed eq "ARRAY"C= defined $inspect_parsed->[0]D= ref $inspect_parsed->[0] eq "HASH"E= defined $inspect_parsed->[0]{"GraphDriver"}F= ref $inspect_parsed->[0]{"GraphDriver"} eq "HASH"G= defined $inspect_parsed->[0]{"GraphDriver"}{"Data"}H= ref $inspect_parsed->[0]{"GraphDriver"}{"Data"} eq "HASH"I= defined $inspect_parsed->[0]{"GraphDriver"}{"Data"}{"MergedDir"}J= ref $inspect_parsed->[0]{"GraphDriver"}{"Data"}{"MergedDir"} eq ""K= $inspect_parsed->[0]{"GraphDriver"}{"Data"}{"MergedDir"} ne ""
ABCDEFGHIJKresult
0XXXXXXXXXX0
10XXXXXXXXX0
110XXXXXXXX0
1110XXXXXXX0
11110XXXXXX0
111110XXXXX0
1111110XXXX0
11111110XXX0
111111110XX0
1111111110X0
111111111100
111111111111
501 && ref($inspect_parsed) eq 'ARRAY'
502 && defined( $inspect_parsed->[0] )
503 && ref( $inspect_parsed->[0] ) eq 'HASH'
504 && defined( $inspect_parsed->[0]{GraphDriver} )
505 && ref( $inspect_parsed->[0]{GraphDriver} ) eq 'HASH'
506 && defined( $inspect_parsed->[0]{GraphDriver}{Data} )
507 && ref( $inspect_parsed->[0]{GraphDriver}{Data} ) eq 'HASH'
508 && defined( $inspect_parsed->[0]{GraphDriver}{Data}{MergedDir} )
509 && ref( $inspect_parsed->[0]{GraphDriver}{Data}{MergedDir} ) eq ''
510 && $inspect_parsed->[0]{GraphDriver}{Data}{MergedDir} ne '' )
511 {
512 0 my $merged_dir = $inspect_parsed->[0]{GraphDriver}{Data}{MergedDir};
513 0 ▶ if ( !grep { $_ eq $merged_dir } @{ $pod_info->{path} } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {$_ eq $merged_dir;} @{$$pod_info{"path"};}) 0 0 0
514 0 push( @{ $pod_info->{path} }, $merged_dir );
515 }
516 }
517 0 ▶ if ( defined($inspect_parsed)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $inspect_parsed and ref $inspect_parsed eq "ARRAY" and defined $inspect_parsed->[0] and ref $inspect_parsed->[0] eq "HASH" and defined $inspect_parsed->[0]{"NetworkSettings"} and ref $inspect_parsed->[0]{"NetworkSettings"} eq "HASH" and defined $inspect_parsed->[0]{"NetworkSettings"}{"Networks"} and ref $inspect_parsed->[0]{"NetworkSettings"}{"Networks"} eq "HASH") 0 0 0
Condition0%0/21
defined $inspect_parsed and ref $inspect_parsed eq "ARRAY" and defined $inspect_parsed->[0] and ref $inspect_parsed->[0] eq "HASH" and defined $inspect_parsed->[0]{"NetworkSettings"} and ref $inspect_parsed->[0]{"NetworkSettings"} eq "HASH" and defined $inspect_parsed->[0]{"NetworkSettings"}{"Networks"} and ref $inspect_parsed->[0]{"NetworkSettings"}{"Networks"} eq "HASH"
!ll&&!rl&&r
000
defined $inspect_parsed and ref $inspect_parsed eq "ARRAY" and defined $inspect_parsed->[0] and ref $inspect_parsed->[0] eq "HASH" and defined $inspect_parsed->[0]{"NetworkSettings"} and ref $inspect_parsed->[0]{"NetworkSettings"} eq "HASH" and defined $inspect_parsed->[0]{"NetworkSettings"}{"Networks"}
!ll&&!rl&&r
000
defined $inspect_parsed and ref $inspect_parsed eq "ARRAY" and defined $inspect_parsed->[0] and ref $inspect_parsed->[0] eq "HASH" and defined $inspect_parsed->[0]{"NetworkSettings"} and ref $inspect_parsed->[0]{"NetworkSettings"} eq "HASH"
!ll&&!rl&&r
000
defined $inspect_parsed and ref $inspect_parsed eq "ARRAY" and defined $inspect_parsed->[0] and ref $inspect_parsed->[0] eq "HASH" and defined $inspect_parsed->[0]{"NetworkSettings"}
!ll&&!rl&&r
000
defined $inspect_parsed and ref $inspect_parsed eq "ARRAY" and defined $inspect_parsed->[0] and ref $inspect_parsed->[0] eq "HASH"
!ll&&!rl&&r
000
defined $inspect_parsed and ref $inspect_parsed eq "ARRAY" and defined $inspect_parsed->[0]
!ll&&!rl&&r
000
defined $inspect_parsed and ref $inspect_parsed eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/8
defined $inspect_parsed and ref $inspect_parsed eq "ARRAY" and defined $inspect_parsed->[0] and ref $inspect_parsed->[0] eq "HASH" and defined $inspect_parsed->[0]{"NetworkSettings"} and ref $inspect_parsed->[0]{"NetworkSettings"} eq "HASH" and defined $inspect_parsed->[0]{"NetworkSettings"}{"Networks"} and ref $inspect_parsed->[0]{"NetworkSettings"}{"Networks"} eq "HASH"
defined $inspect_parsed ref $inspect_parsed eq "ARRAY" defined $inspect_parsed->[0] ref $inspect_parsed->[0] eq "HASH" defined $inspect_parsed->[0]{"NetworkSettings"} ref $inspect_parsed->[0]{"NetworkSettings"} eq "HASH" defined $inspect_parsed->[0]{"NetworkSettings"}{"Networks"} ref $inspect_parsed->[0]{"NetworkSettings"}{"Networks"} eq "HASH"
Truth table0%0/9
A and B and C and D and E and F and G and H
A= defined $inspect_parsedB= ref $inspect_parsed eq "ARRAY"C= defined $inspect_parsed->[0]D= ref $inspect_parsed->[0] eq "HASH"E= defined $inspect_parsed->[0]{"NetworkSettings"}F= ref $inspect_parsed->[0]{"NetworkSettings"} eq "HASH"G= defined $inspect_parsed->[0]{"NetworkSettings"}{"Networks"}H= ref $inspect_parsed->[0]{"NetworkSettings"}{"Networks"} eq "HASH"
ABCDEFGHresult
0XXXXXXX0
10XXXXXX0
110XXXXX0
1110XXXX0
11110XXX0
111110XX0
1111110X0
111111100
111111111
518 && ref($inspect_parsed) eq 'ARRAY'
519 && defined( $inspect_parsed->[0] )
520 && ref( $inspect_parsed->[0] ) eq 'HASH'
521 && defined( $inspect_parsed->[0]{NetworkSettings} )
522 && ref( $inspect_parsed->[0]{NetworkSettings} ) eq 'HASH'
523 && defined( $inspect_parsed->[0]{NetworkSettings}{Networks} )
524 && ref( $inspect_parsed->[0]{NetworkSettings}{Networks} ) eq 'HASH' )
525 {
526 0 my @podman_networks = keys( %{ $inspect_parsed->[0]{NetworkSettings}{Networks} } );
527 0 foreach my $network_to_process (@podman_networks) {
528 my $current_network
529 0 = $inspect_parsed->[0]{NetworkSettings}{Networks}{$network_to_process};
530 0 ▶ if ( ref($current_network) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $current_network eq "HASH") 0 0 0
531 0 my $network_if;
532 my $network_mac;
533 0 ▶ if ( defined( $current_network->{MacAddress} )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $current_network->{"MacAddress"} and ref $current_network->{"MacAddress"} eq "") 0 0 0
Condition0%0/3
defined $current_network->{"MacAddress"} and ref $current_network->{"MacAddress"} eq ""
!ll&&!rl&&r
000
MC/DC0%0/2
defined $current_network->{"MacAddress"} and ref $current_network->{"MacAddress"} eq ""
defined $current_network->{"MacAddress"} ref $current_network->{"MacAddress"} eq ""
Truth table0%0/3
A and B
A= defined $current_network->{"MacAddress"}B= ref $current_network->{"MacAddress"} eq ""
ABresult
0X0
100
111
534 && ref( $current_network->{MacAddress} ) eq '' )
535 {
536 0 $network_mac = $current_network->{MacAddress};
537 }
538 0 ▶ if ( defined( $current_network->{NetworkID} )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $current_network->{"NetworkID"} and ref $current_network->{"NetworkID"} eq "") 0 0 0
Condition0%0/3
defined $current_network->{"NetworkID"} and ref $current_network->{"NetworkID"} eq ""
!ll&&!rl&&r
000
MC/DC0%0/2
defined $current_network->{"NetworkID"} and ref $current_network->{"NetworkID"} eq ""
defined $current_network->{"NetworkID"} ref $current_network->{"NetworkID"} eq ""
Truth table0%0/3
A and B
A= defined $current_network->{"NetworkID"}B= ref $current_network->{"NetworkID"} eq ""
ABresult
0X0
100
111
539 && ref( $current_network->{NetworkID} ) eq '' )
540 {
541 0 my $network_id = $current_network->{NetworkID};
542 0 my $network_inspect_output
543 = `$cgroup_jank_type network inspect $network_id 2> /dev/null`;
544 0 my $network_inspect_parsed;
545 0 eval { $network_inspect_parsed = decode_json($network_inspect_output) };
546 0 ▶ if ( defined($network_inspect_parsed)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $network_inspect_parsed and ref $network_inspect_parsed eq "ARRAY" and defined $network_inspect_parsed->[0] and ref $network_inspect_parsed->[0] eq "HASH") 0 0 0
Condition0%0/9
defined $network_inspect_parsed and ref $network_inspect_parsed eq "ARRAY" and defined $network_inspect_parsed->[0] and ref $network_inspect_parsed->[0] eq "HASH"
!ll&&!rl&&r
000
defined $network_inspect_parsed and ref $network_inspect_parsed eq "ARRAY" and defined $network_inspect_parsed->[0]
!ll&&!rl&&r
000
defined $network_inspect_parsed and ref $network_inspect_parsed eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/4
defined $network_inspect_parsed and ref $network_inspect_parsed eq "ARRAY" and defined $network_inspect_parsed->[0] and ref $network_inspect_parsed->[0] eq "HASH"
defined $network_inspect_parsed ref $network_inspect_parsed eq "ARRAY" defined $network_inspect_parsed->[0] ref $network_inspect_parsed->[0] eq "HASH"
Truth table0%0/5
A and B and C and D
A= defined $network_inspect_parsedB= ref $network_inspect_parsed eq "ARRAY"C= defined $network_inspect_parsed->[0]D= ref $network_inspect_parsed->[0] eq "HASH"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
547 && ref($network_inspect_parsed) eq 'ARRAY'
548 && defined( $network_inspect_parsed->[0] )
549 && ref( $network_inspect_parsed->[0] ) eq 'HASH' )
550 {
551 0 my $network = $network_inspect_parsed->[0];
552 # podman reports the interface directly, while docker has it as a
553 # option for the bridge, and if not set there, it is br- followed
554 # by the first 12 characters of the network ID
555 0 ▶ if ( defined( $network->{network_interface} )
Branch: 3 branches
BranchTrueFalseTotal
if (defined $network->{'network_interface'} and ref $network->{'network_interface'} eq '') { } 0 0 0
elsif (ref $network->{'Options'} eq 'HASH' and defined $network->{'Options'}{'com.docker.network.bridge.name'} and ref $network->{'Options'}{'com.docker.network.bridge.name'} eq '') { } 0 0 0
elsif (defined $network->{'Driver'} and $network->{'Driver'} eq 'bridge' and defined $network->{'Id'} and ref $network->{'Id'} eq '') { } 0 0 0
Condition0%0/3
defined $network->{"network_interface"} and ref $network->{"network_interface"} eq ""
!ll&&!rl&&r
000
MC/DC0%0/2
defined $network->{"network_interface"} and ref $network->{"network_interface"} eq ""
defined $network->{"network_interface"} ref $network->{"network_interface"} eq ""
Truth table0%0/3
A and B
A= defined $network->{"network_interface"}B= ref $network->{"network_interface"} eq ""
ABresult
0X0
100
111
556 && ref( $network->{network_interface} ) eq '' )
557 {
558 0 $network_if = $network->{network_interface};
559 ▶ } elsif ( ref( $network->{Options} ) eq 'HASH'
Condition0%0/6
ref $network->{"Options"} eq "HASH" and defined $network->{"Options"}{"com.docker.network.bridge.name"} and ref $network->{"Options"}{"com.docker.network.bridge.name"} eq ""
!ll&&!rl&&r
000
ref $network->{"Options"} eq "HASH" and defined $network->{"Options"}{"com.docker.network.bridge.name"}
!ll&&!rl&&r
000
MC/DC0%0/3
ref $network->{"Options"} eq "HASH" and defined $network->{"Options"}{"com.docker.network.bridge.name"} and ref $network->{"Options"}{"com.docker.network.bridge.name"} eq ""
ref $network->{"Options"} eq "HASH" defined $network->{"Options"}{"com.docker.network.bridge.name"} ref $network->{"Options"}{"com.docker.network.bridge.name"} eq ""
Truth table0%0/4
A and B and C
A= ref $network->{"Options"} eq "HASH"B= defined $network->{"Options"}{"com.docker.network.bridge.name"}C= ref $network->{"Options"}{"com.docker.network.bridge.name"} eq ""
ABCresult
0XX0
10X0
1100
1111
560 && defined( $network->{Options}{'com.docker.network.bridge.name'} )
561 && ref( $network->{Options}{'com.docker.network.bridge.name'} ) eq '' )
562 {
563 0 $network_if = $network->{Options}{'com.docker.network.bridge.name'};
564 ▶ } elsif ( defined( $network->{Driver} )
Condition0%0/9
defined $network->{"Driver"} and $network->{"Driver"} eq "bridge" and defined $network->{"Id"} and ref $network->{"Id"} eq ""
!ll&&!rl&&r
000
defined $network->{"Driver"} and $network->{"Driver"} eq "bridge" and defined $network->{"Id"}
!ll&&!rl&&r
000
defined $network->{"Driver"} and $network->{"Driver"} eq "bridge"
!ll&&!rl&&r
000
MC/DC0%0/4
defined $network->{"Driver"} and $network->{"Driver"} eq "bridge" and defined $network->{"Id"} and ref $network->{"Id"} eq ""
defined $network->{"Driver"} $network->{"Driver"} eq "bridge" defined $network->{"Id"} ref $network->{"Id"} eq ""
Truth table0%0/5
A and B and C and D
A= defined $network->{"Driver"}B= $network->{"Driver"} eq "bridge"C= defined $network->{"Id"}D= ref $network->{"Id"} eq ""
ABCDresult
0XXX0
10XX0
110X0
11100
11111
565 && $network->{Driver} eq 'bridge'
566 && defined( $network->{Id} )
567 && ref( $network->{Id} ) eq '' )
568 {
569 0 $network_if = 'br-' . substr( $network->{Id}, 0, 12 );
570 }
571 } ## end if ( defined($network_inspect_parsed) && ...)
572 } ## end if ( defined( $current_network->{NetworkID...}))
573  
574 # a network may have a IPv4 address, a IPv6 one, or both, and each
575 # gets its own entry
576 0 foreach my $ip_keys ( [ 'IPAddress', 'Gateway' ], [ 'GlobalIPv6Address', 'IPv6Gateway' ] )
577 {
578 0 my ( $ip_key, $gw_key ) = @{$ip_keys};
579 0 ▶ if ( !defined( $current_network->{$ip_key} )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $current_network->{$ip_key} or ref $current_network->{$ip_key} ne "" or $current_network->{$ip_key} eq "") 0 0 0
Condition0%0/6
not defined $current_network->{$ip_key} or ref $current_network->{$ip_key} ne "" or $current_network->{$ip_key} eq ""
l!l&&r!l&&!r
000
not defined $current_network->{$ip_key} or ref $current_network->{$ip_key} ne ""
l!l&&r!l&&!r
000
MC/DC0%0/3
not defined $current_network->{$ip_key} or ref $current_network->{$ip_key} ne "" or $current_network->{$ip_key} eq ""
not defined $current_network->{$ip_key} ref $current_network->{$ip_key} ne "" $current_network->{$ip_key} eq ""
Truth table0%0/4
not(A) or B or C
A= not defined $current_network->{$ip_key}B= ref $current_network->{$ip_key} ne ""C= $current_network->{$ip_key} eq ""
ABCresult
1XX1
01X1
0011
0000
580 || ref( $current_network->{$ip_key} ) ne ''
581 || $current_network->{$ip_key} eq '' )
582 {
583 0 next;
584 }
585 my $net_work_info = {
586 0 ip => $current_network->{$ip_key},
587 gw => undef,
588 gw_if => undef,
589 mac => $network_mac,
590 if => $network_if,
591 };
592 0 ▶ if ( defined( $current_network->{$gw_key} )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $current_network->{$gw_key} and ref $current_network->{$gw_key} eq "" and $current_network->{$gw_key} ne "") 0 0 0
Condition0%0/6
defined $current_network->{$gw_key} and ref $current_network->{$gw_key} eq "" and $current_network->{$gw_key} ne ""
!ll&&!rl&&r
000
defined $current_network->{$gw_key} and ref $current_network->{$gw_key} eq ""
!ll&&!rl&&r
000
MC/DC0%0/3
defined $current_network->{$gw_key} and ref $current_network->{$gw_key} eq "" and $current_network->{$gw_key} ne ""
defined $current_network->{$gw_key} ref $current_network->{$gw_key} eq "" $current_network->{$gw_key} ne ""
Truth table0%0/4
A and B and C
A= defined $current_network->{$gw_key}B= ref $current_network->{$gw_key} eq ""C= $current_network->{$gw_key} ne ""
ABCresult
0XX0
10X0
1100
1111
593 && ref( $current_network->{$gw_key} ) eq ''
594 && $current_network->{$gw_key} ne '' )
595 {
596 0 $net_work_info->{gw} = $current_network->{$gw_key};
597 }
598 0 ▶ if ( defined($network_if) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $network_if) 0 0 0
599 0 $net_work_info->{gw_if} = $self->route_get_if( $net_work_info->{ip}, $network_if );
600 }
601 # containers in a pod share the network namespace of the pod,
602 # so the same IP turns up for each of them
603 0 ▶ if ( !grep { $_->{ip} eq $net_work_info->{ip} } @{ $pod_info->{ip} } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {$_->{"ip"} eq $net_work_info->{"ip"};} @{$$pod_info{"ip"};}) 0 0 0
604 0 push( @{ $pod_info->{ip} }, $net_work_info );
605 }
606 } ## end foreach my $ip_keys ( [ 'IPAddress', 'Gateway' ...])
607 } ## end if ( ref($current_network) eq 'HASH' )
608 } ## end foreach my $network_to_process (@podman_networks)
609 } ## end if ( defined($inspect_parsed) && ref($inspect_parsed...))
610 } ## end if ( defined($pod_id) && defined($pod_name...))
611 } ## end foreach my $pod ( @{$podman_parsed} )
612 } ## end if ( defined($podman_parsed) && ref($podman_parsed...))
613 } ## end if ( $? == 0 )
614 } ## end foreach my $cgroup_jank_type (@podman_compatible)
615  
616 #
617 # gets of procs for finding a list of containers
618 #
619 # my $ps_output = `ps -haxo pid,uid,gid,cgroupns,%cpu,%mem,rss,vsize,trs,drs,size,cgroup 2> /dev/null`;
620 # if ( $? != 0 ) {
621 # $self->{cgroupns_usable} = 0;
622 4 my $ps_output = `ps -haxo pid,uid,gid,%cpu,%mem,rss,vsize,trs,drs,size,etimes,comm 2> /dev/null`;
623 # }
624 4 my @ps_output_split = split( /\n/, $ps_output );
625 4 my %found_cgroups;
626 my %cgroups_percpu;
627 4 my %cgroups_permem;
628 4 my %cgroups_procs;
629 4 my %cgroups_rss;
630 4 my %cgroups_vsize;
631 4 my %cgroups_trs;
632 4 my %cgroups_drs;
633 4 my %cgroups_size;
634 4 my %cgroups_etimes;
635 4 my %cgroups_invvol_ctxt_switches;
636 4 my %cgroups_vol_ctxt_switches;
637 4 my %cgroups_root_paths;
638  
639 4 foreach my $line (@ps_output_split) {
640 44 $line =~ s/^\s+//;
641 44 my $vol_ctxt_switches = 0;
642 44 my $invol_ctxt_switches = 0;
643 44 my ( $pid, $uid, $gid, $percpu, $permem, $rss, $vsize, $trs, $drs, $size, $etimes, $comm );
644 # comm is captured last, with a split limit, so a command name containing
645 # whitespace does not shift the earlier fields
646 44 ( $pid, $uid, $gid, $percpu, $permem, $rss, $vsize, $trs, $drs, $size, $etimes, $comm )
647 = split( /\s+/, $line, 12 );
648 # skip the idle/swapper task... the Linux equivalent of FreeBSD's
649 # [idle]... the true idle is PID 0 (swapper), which ps normally does
650 # not list, but guard against it defensively so it can never be
651 # counted as CPU usage
652 44 ▶ if ( defined($comm) && ( $comm eq 'swapper' || $comm =~ m{^swapper/} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $comm and $comm eq "swapper" || $comm =~ m[^swapper/]) 0 44 44
Condition33%2/6
defined $comm and $comm eq "swapper" || $comm =~ m[^swapper/]
!ll&&!rl&&r
0440
$comm eq "swapper" or $comm =~ m[^swapper/]
l!l&&r!l&&!r
0044
MC/DC0%0/3
defined $comm and $comm eq "swapper" || $comm =~ m[^swapper/]
defined $comm $comm eq "swapper" $comm =~ m[^swapper/]
Truth table25%1/4
A and B or C
A= defined $commB= $comm eq "swapper"C= $comm =~ m[^swapper/]
ABCresult
0XX0
1000
11X1
1011
653 0 next;
654 }
655  
656 # the cgroup is read from procfs rather than being fetched via ps as ps
657 # hard truncates the cgroup column to 27 characters when it is not the
658 # final column, regardless of -w/--width or COLUMNS... that both mangles
659 # the name, mapping unrelated units to the same one, and leaves the path
660 # under /sys/fs/cgroup non-existent, meaning no stats get read at all
661 44 my $cgroup = $self->proc_cgroup($pid);
662 # undef if the proc exited or is not under the unified hierarchy
663 44 ▶ if ( !defined($cgroup) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $cgroup) 44 0 44
664 44 next;
665 }
666  
667 0 my $cache_name = 'proc-' . $pid . '-' . $uid . '-' . $gid . '-' . $cgroup;
668  
669 0 $found_cgroups{$cgroup} = $cgroup;
670  
671 # save the root fs path as seen by this process, resolving chroots
672 # and the like... for the usual case this is just /
673 0 my $proc_root_path = readlink( '/proc/' . $pid . '/root' );
674 0 ▶ if ( defined($proc_root_path) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $proc_root_path) 0 0 0
675 0 $cgroups_root_paths{$cgroup}{$proc_root_path} = 1;
676 }
677  
678 0 eval {
679 0 ▶ if ( -f '/proc/' . $pid . '/status' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f '/proc/' . $pid . '/status') 0 0 0
680 0 my @switches_find = grep( /voluntary\_ctxt\_switches\:/, read_file( '/proc/' . $pid . '/status' ) );
681 0 foreach my $found_switch (@switches_find) {
682 0 chomp($found_switch);
683 0 my @switch_split = split( /\:[\ \t]+/, $found_switch );
684 0 ▶ if ( defined( $switch_split[0] ) && defined( $switch_split[1] ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $switch_split[0] and defined $switch_split[1]) 0 0 0
Condition0%0/3
defined $switch_split[0] and defined $switch_split[1]
!ll&&!rl&&r
000
MC/DC0%0/2
defined $switch_split[0] and defined $switch_split[1]
defined $switch_split[0] defined $switch_split[1]
Truth table0%0/3
A and B
A= defined $switch_split[0]B= defined $switch_split[1]
ABresult
0X0
100
111
685 0 ▶ if ( $switch_split[0] eq 'voluntary_ctxt_switches' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($switch_split[0] eq 'voluntary_ctxt_switches') { } 0 0 0
elsif ($switch_split[0] eq 'nonvoluntary_ctxt_switches') { } 0 0 0
686 0 $vol_ctxt_switches = $switch_split[1];
687 } elsif ( $switch_split[0] eq 'nonvoluntary_ctxt_switches' ) {
688 # the kernel calls these nonvoluntary and not involuntary
689 0 $invol_ctxt_switches = $switch_split[1];
690 }
691 }
692 } ## end foreach my $found_switch (@switches_find)
693 } ## end if ( -f '/proc/' . $pid . '/status' )
694 };
695 0 $vol_ctxt_switches
696 = $self->cache_process( $cache_name, 'voluntary-context-switches', $vol_ctxt_switches, $etimes );
697 0 $invol_ctxt_switches
698 = $self->cache_process( $cache_name, 'involuntary-context-switches', $invol_ctxt_switches, $etimes );
699  
700 0 ▶ if ( !defined( $cgroups_permem{$cgroup} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $cgroups_permem{$cgroup}) { } 0 0 0
701 0 $cgroups_permem{$cgroup} = $permem;
702 0 $cgroups_percpu{$cgroup} = $percpu;
703 0 $cgroups_procs{$cgroup} = 1;
704 0 $cgroups_rss{$cgroup} = $rss;
705 0 $cgroups_vsize{$cgroup} = $vsize;
706 0 $cgroups_trs{$cgroup} = $trs;
707 0 $cgroups_drs{$cgroup} = $drs;
708 0 $cgroups_size{$cgroup} = $size;
709 0 $cgroups_etimes{$cgroup} = $etimes;
710 0 $cgroups_invvol_ctxt_switches{$cgroup} = $invol_ctxt_switches;
711 0 $cgroups_vol_ctxt_switches{$cgroup} = $vol_ctxt_switches;
712 } else {
713 0 $cgroups_permem{$cgroup} = $cgroups_permem{$cgroup} + $permem;
714 0 $cgroups_percpu{$cgroup} = $cgroups_percpu{$cgroup} + $percpu;
715 0 $cgroups_procs{$cgroup}++;
716 0 $cgroups_rss{$cgroup} = $cgroups_rss{$cgroup} + $rss;
717 0 $cgroups_vsize{$cgroup} = $cgroups_vsize{$cgroup} + $vsize;
718 0 $cgroups_trs{$cgroup} = $cgroups_trs{$cgroup} + $trs;
719 0 $cgroups_drs{$cgroup} = $cgroups_drs{$cgroup} + $drs;
720 0 $cgroups_size{$cgroup} = $cgroups_size{$cgroup} + $size;
721 0 $cgroups_etimes{$cgroup} = $cgroups_etimes{$cgroup} + $etimes;
722 0 $cgroups_invvol_ctxt_switches{$cgroup} = $cgroups_invvol_ctxt_switches{$cgroup} + $invol_ctxt_switches;
723 0 $cgroups_vol_ctxt_switches{$cgroup} = $cgroups_vol_ctxt_switches{$cgroup} + $vol_ctxt_switches;
724 } ## end else [ if ( !defined( $cgroups_permem{$cgroup} ) )]
725 } ## end foreach my $line (@ps_output_split)
726  
727 #
728 # build a list of mappings
729 #
730 # more than one cgroup will commonly map to the same name, such as each
731 # session scope for a user or a service with cgroups nested under it, so the
732 # cgroups are grouped up by the name they map to... each also maps to the dir
733 # under /sys/fs/cgroup to read the stats from, which for the likes of a user is
734 # the slice for that user and not the individual session scopes, given that
735 # with cgroup v2 the stats for a cgroup include those of all its descendants
736 4 my %name_to_cgroups;
737 my %name_to_stat_dirs;
738 4 foreach my $cgroup ( keys(%found_cgroups) ) {
739 #my $cgroupns = $found_cgroups{$cgroup};
740 0 my ( $map_to, $stat_dir ) = $self->cgroup_mapping($cgroup);
741 0 ▶ if ( defined($map_to) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $map_to) 0 0 0
742 0 $self->{mappings}{$cgroup} = $map_to;
743 0 push( @{ $name_to_cgroups{$map_to} }, $cgroup );
744 0 ▶ if ( defined($stat_dir) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $stat_dir) 0 0 0
745 # keyed on the dir so that one shared by several cgroups is only read
746 # once, otherwise the same values would be counted repeatedly
747 0 $name_to_stat_dirs{$map_to}{$stat_dir} = 1;
748 }
749 }
750 } ## end foreach my $cgroup ( keys(%found_cgroups) )
751  
752 #
753 # get the stats
754 #
755 4 foreach my $name ( keys(%name_to_cgroups) ) {
756  
757 # only process this cgroup if the include check returns true, otherwise ignore it
758 0 ▶ if ( $self->{obj}->include($name) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"obj"}->include($name)) 0 0 0
759  
760 0 $data->{oslvms}{$name} = clone($base_stats);
761  
762 # these all come from ps and are per proc, so they are just summed up
763 # across every cgroup mapping to this name... the totals are summed here
764 # as well so they only cover included names, same as the cgroup stats
765 0 my %root_paths_found;
766 0 foreach my $cgroup ( @{ $name_to_cgroups{$name} } ) {
767 my %ps_stats = (
768 'percent-cpu' => $cgroups_percpu{$cgroup},
769 'percent-memory' => $cgroups_permem{$cgroup},
770 procs => $cgroups_procs{$cgroup},
771 rss => $cgroups_rss{$cgroup},
772 'size' => $cgroups_size{$cgroup},
773 'virtual-size' => $cgroups_vsize{$cgroup},
774 'text-size' => $cgroups_trs{$cgroup},
775 'data-size' => $cgroups_drs{$cgroup},
776 'elapsed-times' => $cgroups_etimes{$cgroup},
777 'voluntary-context-switches' => $cgroups_vol_ctxt_switches{$cgroup},
778 0 'involuntary-context-switches' => $cgroups_invvol_ctxt_switches{$cgroup},
779 );
780 0 foreach my $stat ( keys(%ps_stats) ) {
781 0 $data->{oslvms}{$name}{$stat} = $data->{oslvms}{$name}{$stat} + $ps_stats{$stat};
782 0 $data->{totals}{$stat} = $data->{totals}{$stat} + $ps_stats{$stat};
783 }
784  
785 0 ▶ if ( defined( $cgroups_root_paths{$cgroup} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cgroups_root_paths{$cgroup}) 0 0 0
786 0 foreach my $root_path ( keys( %{ $cgroups_root_paths{$cgroup} } ) ) {
787 0 $root_paths_found{$root_path} = 1;
788 }
789 }
790 } ## end foreach my $cgroup ( @{ $name_to_cgroups{$name}...})
791  
792 0 ▶ if ( $name =~ /^p\_/ || $name =~ /^d\_/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /^p\_/ or $name =~ /^d\_/) 0 0 0
Condition0%0/3
$name =~ /^p\_/ or $name =~ /^d\_/
l!l&&r!l&&!r
000
MC/DC0%0/2
$name =~ /^p\_/ or $name =~ /^d\_/
$name =~ /^p\_/ $name =~ /^d\_/
Truth table0%0/3
A or B
A= $name =~ /^p\_/B= $name =~ /^d\_/
ABresult
1X1
011
000
793 0 my $container_name = $name;
794 0 $container_name =~ s/^[pd]\_//;
795 0 ▶ my $info_key = ( $name =~ /^p\_/ ) ? 'podman_info' : 'docker_info';
Branch: 1 branch
BranchTrueFalseTotal
$name =~ /^p\_/ ? : 0 0 0
796 # a container with no ps/inspect info, such as one whose ID could not be
797 # mapped to a name, keeps the empty IP list from the base stats
798 0 ▶ if ( defined( $self->{$info_key}{$container_name} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{$info_key}{$container_name}) 0 0 0
799 0 $data->{oslvms}{$name}{'ip'} = $self->{$info_key}{$container_name}{ip};
800 }
801 }
802  
803 # record the root fs path for this oslvm, akin to the path for a FreeBSD
804 # jail... for containers prefer the rootfs reported by "inspect" as the
805 # procs there are in their own mount namespace and will see it as just /,
806 # otherwise use the roots the procs see, which handles chroots and the like
807 0 my @root_paths;
808 0 ▶ if ( $name =~ /^[pd]\_/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /^[pd]\_/) 0 0 0
809 0 my $container_name = $name;
810 0 $container_name =~ s/^[pd]\_//;
811 0 ▶ my $info_key = ( $name =~ /^p\_/ ) ? 'podman_info' : 'docker_info';
Branch: 1 branch
BranchTrueFalseTotal
$name =~ /^p\_/ ? : 0 0 0
812 0 ▶ if ( defined( $self->{$info_key}{$container_name} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{$info_key}{$container_name}) 0 0 0
813 0 push( @root_paths, @{ $self->{$info_key}{$container_name}{path} } );
814 }
815 }
816 0 ▶ if ( !@root_paths ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@root_paths) 0 0 0
817 0 @root_paths = sort( keys(%root_paths_found) );
818 }
819 0 ▶ if ( !@root_paths ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@root_paths) 0 0 0
820 0 push( @root_paths, '/' );
821 }
822 0 push( @{ $data->{oslvms}{$name}{path} }, @root_paths );
823  
824 0 foreach my $stat_dir ( sort( keys( %{ $name_to_stat_dirs{$name} } ) ) ) {
825 0 my $base_dir = '/sys/fs/cgroup' . $stat_dir;
826  
827 # cached per cgroup dir rather than per name so the deltas stay correct
828 # as the cgroups making up a name come and go
829 0 my $cache_name = 'cgroup-' . $stat_dir;
830  
831 0 my $cpu_stats_raw;
832 0 ▶ if ( -f $base_dir . '/cpu.stat' && -r $base_dir . '/cpu.stat' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $base_dir . '/cpu.stat' and -r $base_dir . '/cpu.stat') 0 0 0
Condition0%0/3
-f $base_dir . '/cpu.stat' and -r $base_dir . '/cpu.stat'
!ll&&!rl&&r
000
MC/DC0%0/2
-f $base_dir . '/cpu.stat' and -r $base_dir . '/cpu.stat'
-f $base_dir . '/cpu.stat' -r $base_dir . '/cpu.stat'
Truth table0%0/3
A and B
A= -f $base_dir . '/cpu.stat'B= -r $base_dir . '/cpu.stat'
ABresult
0X0
100
111
833 0 eval { $cpu_stats_raw = read_file( $base_dir . '/cpu.stat' ); };
834 0 ▶ if ( defined($cpu_stats_raw) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cpu_stats_raw) 0 0 0
835 0 my @cpu_stats_split = split( /\n/, $cpu_stats_raw );
836 0 foreach my $line (@cpu_stats_split) {
837 0 my ( $stat, $value ) = split( /\s+/, $line, 2 );
838 0 ▶ if ( defined( $stat_mapping->{$stat} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $stat_mapping->{$stat}) 0 0 0
839 0 $stat = $stat_mapping->{$stat};
840 }
841 0 ▶ if ( defined( $data->{oslvms}{$name}{$stat} ) && defined($value) && $value =~ /[0-9\.]+/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $data->{"oslvms"}{$name}{$stat} and defined $value and $value =~ /[0-9\.]+/) 0 0 0
Condition0%0/6
defined $data->{"oslvms"}{$name}{$stat} and defined $value and $value =~ /[0-9\.]+/
!ll&&!rl&&r
000
defined $data->{"oslvms"}{$name}{$stat} and defined $value
!ll&&!rl&&r
000
MC/DC0%0/3
defined $data->{"oslvms"}{$name}{$stat} and defined $value and $value =~ /[0-9\.]+/
defined $data->{"oslvms"}{$name}{$stat} defined $value $value =~ /[0-9\.]+/
Truth table0%0/4
A and B and C
A= defined $data->{"oslvms"}{$name}{$stat}B= defined $valueC= $value =~ /[0-9\.]+/
ABCresult
0XX0
10X0
1100
1111
842 0 $value = $self->cache_process( $cache_name, $stat, $value );
843 0 $data->{oslvms}{$name}{$stat} = $data->{oslvms}{$name}{$stat} + $value;
844 0 $data->{totals}{$stat} = $data->{totals}{$stat} + $value;
845 0 ▶ if ( $stat eq 'nr_bursts' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stat eq "nr_bursts") 0 0 0
846 0 $data->{has}{burst_count} = 1;
847 }
848 0 ▶ if ( $stat eq 'burst-time' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stat eq "burst-time") 0 0 0
849 0 $data->{has}{burst_time} = 1;
850 }
851 0 ▶ if ( $stat eq 'throttled-time' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stat eq "throttled-time") 0 0 0
852 0 $data->{has}{throttled_time} = 1;
853 }
854 0 ▶ if ( $stat eq 'nr_throttled' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stat eq "nr_throttled") 0 0 0
855 0 $data->{has}{throttled_count} = 1;
856 }
857 } ## end if ( defined( $data->{oslvms}{$name}{$stat...}))
858 } ## end foreach my $line (@cpu_stats_split)
859 } ## end if ( defined($cpu_stats_raw) )
860 } ## end if ( -f $base_dir . '/cpu.stat' && -r $base_dir...)
861  
862 0 my $memory_stats_raw;
863 0 ▶ if ( -f $base_dir . '/memory.stat' && -r $base_dir . '/memory.stat' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $base_dir . '/memory.stat' and -r $base_dir . '/memory.stat') 0 0 0
Condition0%0/3
-f $base_dir . '/memory.stat' and -r $base_dir . '/memory.stat'
!ll&&!rl&&r
000
MC/DC0%0/2
-f $base_dir . '/memory.stat' and -r $base_dir . '/memory.stat'
-f $base_dir . '/memory.stat' -r $base_dir . '/memory.stat'
Truth table0%0/3
A and B
A= -f $base_dir . '/memory.stat'B= -r $base_dir . '/memory.stat'
ABresult
0X0
100
111
864 0 eval { $memory_stats_raw = read_file( $base_dir . '/memory.stat' ); };
865 0 ▶ if ( defined($memory_stats_raw) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $memory_stats_raw) 0 0 0
866 0 my @memory_stats_split = split( /\n/, $memory_stats_raw );
867 0 foreach my $line (@memory_stats_split) {
868 0 my ( $stat, $value ) = split( /\s+/, $line, 2 );
869 0 ▶ if ( defined( $stat_mapping->{$stat} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $stat_mapping->{$stat}) 0 0 0
870 0 $stat = $stat_mapping->{$stat};
871 }
872 0 ▶ if ( defined( $data->{oslvms}{$name}{$stat} ) && defined($value) && $value =~ /[0-9\.]+/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $data->{"oslvms"}{$name}{$stat} and defined $value and $value =~ /[0-9\.]+/) 0 0 0
Condition0%0/6
defined $data->{"oslvms"}{$name}{$stat} and defined $value and $value =~ /[0-9\.]+/
!ll&&!rl&&r
000
defined $data->{"oslvms"}{$name}{$stat} and defined $value
!ll&&!rl&&r
000
MC/DC0%0/3
defined $data->{"oslvms"}{$name}{$stat} and defined $value and $value =~ /[0-9\.]+/
defined $data->{"oslvms"}{$name}{$stat} defined $value $value =~ /[0-9\.]+/
Truth table0%0/4
A and B and C
A= defined $data->{"oslvms"}{$name}{$stat}B= defined $valueC= $value =~ /[0-9\.]+/
ABCresult
0XX0
10X0
1100
1111
873 0 $value = $self->cache_process( $cache_name, $stat, $value );
874 0 $data->{oslvms}{$name}{$stat} = $data->{oslvms}{$name}{$stat} + $value;
875 0 $data->{totals}{$stat} = $data->{totals}{$stat} + $value;
876 }
877 } ## end foreach my $line (@memory_stats_split)
878 } ## end if ( defined($memory_stats_raw) )
879 } ## end if ( -f $base_dir . '/memory.stat' && -r $base_dir...)
880  
881 0 my $io_stats_raw;
882 0 ▶ if ( -f $base_dir . '/io.stat' && -r $base_dir . '/io.stat' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $base_dir . '/io.stat' and -r $base_dir . '/io.stat') 0 0 0
Condition0%0/3
-f $base_dir . '/io.stat' and -r $base_dir . '/io.stat'
!ll&&!rl&&r
000
MC/DC0%0/2
-f $base_dir . '/io.stat' and -r $base_dir . '/io.stat'
-f $base_dir . '/io.stat' -r $base_dir . '/io.stat'
Truth table0%0/3
A and B
A= -f $base_dir . '/io.stat'B= -r $base_dir . '/io.stat'
ABresult
0X0
100
111
883 0 eval { $io_stats_raw = read_file( $base_dir . '/io.stat' ); };
884 0 ▶ if ( defined($io_stats_raw) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $io_stats_raw) 0 0 0
885 0 $data->{has}{rwdops} = 1;
886 0 $data->{has}{rwdbytes} = 1;
887 0 my @io_stats_split = split( /\n/, $io_stats_raw );
888 0 foreach my $line (@io_stats_split) {
889 0 my @line_split = split( /\s/, $line );
890 0 shift(@line_split);
891 0 foreach my $item (@line_split) {
892 0 my ( $stat, $value ) = split( /\=/, $item, 2 );
893 0 ▶ if ( defined( $stat_mapping->{$stat} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $stat_mapping->{$stat}) 0 0 0
894 0 $stat = $stat_mapping->{$stat};
895 }
896 0 ▶ if ( defined( $data->{oslvms}{$name}{$stat} )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $data->{"oslvms"}{$name}{$stat} and defined $value and $value =~ /[0-9]+/) 0 0 0
Condition0%0/6
defined $data->{"oslvms"}{$name}{$stat} and defined $value and $value =~ /[0-9]+/
!ll&&!rl&&r
000
defined $data->{"oslvms"}{$name}{$stat} and defined $value
!ll&&!rl&&r
000
MC/DC0%0/3
defined $data->{"oslvms"}{$name}{$stat} and defined $value and $value =~ /[0-9]+/
defined $data->{"oslvms"}{$name}{$stat} defined $value $value =~ /[0-9]+/
Truth table0%0/4
A and B and C
A= defined $data->{"oslvms"}{$name}{$stat}B= defined $valueC= $value =~ /[0-9]+/
ABCresult
0XX0
10X0
1100
1111
897 && defined($value)
898 && $value =~ /[0-9]+/ )
899 {
900 0 $value = $self->cache_process( $cache_name, $stat, $value );
901 0 $data->{oslvms}{$name}{$stat} = $data->{oslvms}{$name}{$stat} + $value;
902 0 $data->{totals}{$stat} = $data->{totals}{$stat} + $value;
903 }
904 } ## end foreach my $item (@line_split)
905 } ## end foreach my $line (@io_stats_split)
906 } ## end if ( defined($io_stats_raw) )
907 } ## end if ( -f $base_dir . '/io.stat' && -r $base_dir...)
908 } ## end foreach my $stat_dir ( sort( keys( %{ $name_to_stat_dirs...})))
909 } ## end if ( $self->{obj}->include($name) )
910 } ## end foreach my $name ( keys(%name_to_cgroups) )
911  
912 4 $data->{uid_mapping} = $self->{uid_mapping};
913  
914 # save the proc cache for next run... written atomically so an interrupted
915 # write cannot leave behind a truncated/empty cache file
916 4 eval { write_file( $self->{cache_file}, { atomic => 1 }, encode_json( $self->{new_cache} ) ); };
917 4 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 4 4
918 0 push( @{ $data->{errors} }, 'saving proc cache failed, "' . $self->{cache_file} . '"... ' . $@ );
919 0 $data->{cache_failure} = 1;
920 }
921  
922 4 ▶ if ($cache_is_new) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cache_is_new) 2 2 4
923 2 delete( $data->{oslvms} );
924 2 $data->{oslvms} = {};
925 2 my @total_keys = keys( %{ $data->{totals} } );
926 2 foreach my $total_key (@total_keys) {
927 170 ▶ if ( ref( $data->{totals}{$total_key} ) eq '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $data->{"totals"}{$total_key} eq "") 170 0 170
928 170 $data->{totals}{$total_key} = 0;
929 }
930 }
931 } ## end if ($cache_is_new)
932  
933 4 return $data;
934 } ## end sub run
935  
936 =head2 usable
937  
938 Dies if not usable, meaning not Linux or cgroup v2 is not mounted at
939 /sys/fs/cgroup.
940  
941 eval{ $backend->usable; };
942 if ( $@ ){
943 print 'Not usable because... '.$@."\n";
944 }
945  
946 =cut
947  
948 1 ▶sub usable {
Subroutine usable: called CC=3 SCAR=12.7
Pod documented
949 1 my $self = $_[0];
950  
951 # make sure it is linux
952 1 ▶ if ( $^O !~ 'linux' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($^O =~ /linux/) 0 1 1
953 0 die '$^O is "' . $^O . '" and not "linux"';
954 }
955  
956 # the stats are read from under /sys/fs/cgroup, which on a hybrid or v1 only
957 # setup is not the unified hierarchy
958 1 ▶ if ( !-f '/sys/fs/cgroup/cgroup.controllers' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f "/sys/fs/cgroup/cgroup.controllers") 0 1 1
959 0 die 'cgroup v2 is not mounted at /sys/fs/cgroup';
960 }
961  
962 1 return 1;
963 } ## end sub usable
964  
965 # Finds the cgroup v2 cgroup for a process.
966 #
967 # One arg is taken, the PID to check.
968 #
969 # Returns the unified hierarchy line from /proc/$pid/cgroup, as is, such as
970 # "0::/system.slice/ssh.service". undef is returned if the PID is undef or not
971 # a number, the process exited before it could be read, it is in the root
972 # cgroup, or it is not under the unified hierarchy.
973 #
974 # my $cgroup = $backend->proc_cgroup(1234);
975 # # "0::/user.slice/user-1000.slice/session-5.scope"
976 51 ▶sub proc_cgroup {
Subroutine proc_cgroup: called CC=7 SCAR=19.7
Pod undocumented
977 51 my $self = $_[0];
978 51 my $pid = $_[1];
979  
980 51 ▶ if ( !defined($pid) || !looks_like_number($pid) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $pid and &looks_like_number($pid)) 4 47 51
Condition100%3/3
defined $pid and &looks_like_number($pid)
!ll&&!rl&&r
2247
MC/DC100%2/2
defined $pid and &looks_like_number($pid)
defined $pid &looks_like_number($pid)
Truth table100%3/3
A and B
A= defined $pidB= &looks_like_number($pid)
ABresult
0X0
100
111
981 4 return undef;
982 }
983  
984 47 my $raw;
985 # the proc may exit between being listed by ps and being read here, so a
986 # failure to read it is entirely expected and not worth noting as a error
987 47 eval { $raw = read_file( '/proc/' . $pid . '/cgroup' ); };
988 47 ▶ if ( !defined($raw) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $raw) 9 38 47
989 9 return undef;
990 }
991  
992 # only the unified hierarchy, hierarchy ID 0 with a empty controller list,
993 # is of interest here... on a hybrid setup the v1 lines are also present
994 38 foreach my $line ( split( /\n/, $raw ) ) {
995 38 ▶ if ( $line =~ /^0\:\:\// ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ m[^0\:\:/]) 38 0 38
996 # the root cgroup, where kernel threads and the like live, is not a
997 # container of any sort and has no name to map to, so it is skipped,
998 # matching what ps did previously by printing "-" for those
999 38 ▶ if ( $line eq '0::/' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line eq "0::/") 38 0 38
1000 38 return undef;
1001 }
1002 0 return $line;
1003 }
1004 } ## end foreach my $line ( split( /\n/, $raw ) )
1005  
1006 0 return undef;
1007 } ## end sub proc_cgroup
1008  
1009 # Finds the host interface that traffic from a container IP leaves by, as seen
1010 # by the routing table for a packet arriving from the container's network.
1011 # Nothing is sent... "ip route get" only does a route lookup, using a public
1012 # address, 8.8.8.8 or 2001:4860:4860::8888, as the destination.
1013 #
1014 # Takes the args below.
1015 #
1016 # - ip :: The container IP, IPv4 or IPv6.
1017 #
1018 # - if :: The host interface for the container's network, such as docker0
1019 # or podman0.
1020 #
1021 # Returns the interface name, or undef if either arg is undef or does not look
1022 # like a IP or interface name, or if the lookup fails. The args are checked as
1023 # they are passed to the shell.
1024 #
1025 # my $gw_if = $backend->route_get_if( '172.17.0.2', 'docker0' ); # "eth0"
1026 # $gw_if = $backend->route_get_if( 'fd00::2', 'podman0' ); # "eth0"
1027 6 ▶sub route_get_if {
Subroutine route_get_if: called CC=11 SCAR=31.4
Pod undocumented
1028 6 my $self = $_[0];
1029 6 my $ip = $_[1];
1030 6 my $if = $_[2];
1031  
1032 6 ▶ if ( !defined($ip)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ip and defined $if and $ip =~ /^[0-9a-fA-F\.\:]+$/ and $if =~ /^[A-Za-z0-9\.\_\-\@]+$/) 5 1 6
Condition100%9/9
defined $ip and defined $if and $ip =~ /^[0-9a-fA-F\.\:]+$/ and $if =~ /^[A-Za-z0-9\.\_\-\@]+$/
!ll&&!rl&&r
411
defined $ip and defined $if and $ip =~ /^[0-9a-fA-F\.\:]+$/
!ll&&!rl&&r
222
defined $ip and defined $if
!ll&&!rl&&r
114
MC/DC100%4/4
defined $ip and defined $if and $ip =~ /^[0-9a-fA-F\.\:]+$/ and $if =~ /^[A-Za-z0-9\.\_\-\@]+$/
defined $ip defined $if $ip =~ /^[0-9a-fA-F\.\:]+$/ $if =~ /^[A-Za-z0-9\.\_\-\@]+$/
Truth table100%5/5
A and B and C and D
A= defined $ipB= defined $ifC= $ip =~ /^[0-9a-fA-F\.\:]+$/D= $if =~ /^[A-Za-z0-9\.\_\-\@]+$/
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1033 || !defined($if)
1034 || $ip !~ /^[0-9a-fA-F\.\:]+$/
1035 || $if !~ /^[A-Za-z0-9\.\_\-\@]+$/ )
1036 {
1037 5 return undef;
1038 }
1039  
1040 1 my ( $family, $destination ) = ( '-4', '8.8.8.8' );
1041 1 ▶ if ( $ip =~ /\:/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ip =~ /\:/) 0 1 1
1042 0 ( $family, $destination ) = ( '-6', '2001:4860:4860::8888' );
1043 }
1044  
1045 1 my $output = `ip -j $family route get $destination from $ip iif $if 2> /dev/null`;
1046 1 ▶ if ( $? != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0) 1 0 1
1047 1 return undef;
1048 }
1049  
1050 0 my $parsed;
1051 0 eval { $parsed = decode_json($output); };
1052 0 ▶ if ( ref($parsed) eq 'ARRAY'
Branch: 1 branch
BranchTrueFalseTotal
if (ref $parsed eq "ARRAY" and ref $parsed->[0] eq "HASH" and defined $parsed->[0]{"dev"} and ref $parsed->[0]{"dev"} eq "") 0 0 0
Condition0%0/9
ref $parsed eq "ARRAY" and ref $parsed->[0] eq "HASH" and defined $parsed->[0]{"dev"} and ref $parsed->[0]{"dev"} eq ""
!ll&&!rl&&r
000
ref $parsed eq "ARRAY" and ref $parsed->[0] eq "HASH" and defined $parsed->[0]{"dev"}
!ll&&!rl&&r
000
ref $parsed eq "ARRAY" and ref $parsed->[0] eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/4
ref $parsed eq "ARRAY" and ref $parsed->[0] eq "HASH" and defined $parsed->[0]{"dev"} and ref $parsed->[0]{"dev"} eq ""
ref $parsed eq "ARRAY" ref $parsed->[0] eq "HASH" defined $parsed->[0]{"dev"} ref $parsed->[0]{"dev"} eq ""
Truth table0%0/5
A and B and C and D
A= ref $parsed eq "ARRAY"B= ref $parsed->[0] eq "HASH"C= defined $parsed->[0]{"dev"}D= ref $parsed->[0]{"dev"} eq ""
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1053 && ref( $parsed->[0] ) eq 'HASH'
1054 && defined( $parsed->[0]{dev} )
1055 && ref( $parsed->[0]{dev} ) eq '' )
1056 {
1057 0 return $parsed->[0]{dev};
1058 }
1059  
1060 0 return undef;
1061 } ## end sub route_get_if
1062  
1063 # Maps a cgroup to the name it is reported as and to the dir its stats are read
1064 # from. See the POD SYNOPSIS for the naming. docker_mapping and podman_mapping
1065 # need to be filled in first for containers to be named, else the ID is used.
1066 #
1067 # For a user slice, uid_mapping is also filled in with the passwd info for the
1068 # UID if one exists.
1069 #
1070 # One arg is taken, the cgroup as returned by proc_cgroup.
1071 #
1072 # Returns a list of two items. The first is the name. The second is the dir to
1073 # read stats from, relative to /sys/fs/cgroup. As cgroup v2 stats include
1074 # descendants, this is the unit, slice, or container the name is for and not
1075 # the cgroup itself. Both are undef if there is no name to map to, such as the
1076 # root cgroup.
1077 #
1078 # my ( $name, $stat_dir ) = $backend->cgroup_mapping('0::/system.slice/systemd-udevd.service/udev');
1079 # # ( 's_systemd-udevd', '/system.slice/systemd-udevd.service' )
1080 #
1081 # ( $name, $stat_dir ) = $backend->cgroup_mapping('0::/user.slice/user-1000.slice/session-5.scope');
1082 # # ( 'u_1000', '/user.slice/user-1000.slice' )
1083 36 ▶sub cgroup_mapping {
Subroutine cgroup_mapping: called CC=23 SCAR=31.4
Pod undocumented
1084 36 my $self = $_[0];
1085 36 my $cgroup_name = $_[1];
1086  
1087 36 ▶ if ( !defined($cgroup_name) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $cgroup_name) 1 35 36
1088 1 return undef;
1089 }
1090  
1091 35 ▶ if ( $cgroup_name eq '0::/init.scope' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cgroup_name eq "0::/init.scope") 1 34 35
1092 1 return ( 'init', '/init.scope' );
1093 }
1094  
1095 34 ▶ if ( $cgroup_name =~ /^0\:\:\/system\.slice\/docker\-[a-zA-Z0-9]+\.scope/ ) {
Branch: 6 branches
BranchTrueFalseTotal
if ($cgroup_name =~ m[^0\:\:/system\.slice/docker\-[a-zA-Z0-9]+\.scope]) { } 3 31 34
elsif ($cgroup_name =~ m[^0\:\:/docker/]) { } 3 28 31
elsif ($cgroup_name =~ m[^0\:\:/machine\.slice/libpod\-conmon-]) { } 1 27 28
elsif ($cgroup_name =~ m[^0\:\:/machine\.slice/libpod\-]) { } 3 24 27
elsif ($cgroup_name =~ m[^0\:\:/(system|machine)\.slice/]) { } 15 9 24
elsif ($cgroup_name =~ m[^0\:\:/user\.slice/]) { } 5 4 9
1096 3 my $id = $cgroup_name;
1097 3 $id =~ s/^0\:\:\/system\.slice\/docker\-//;
1098 3 $id =~ s/\.scope.*$//;
1099 # the scope for the container is what the stats are wanted for, not any of
1100 # the cgroups nested under it
1101 3 my $stat_dir = '/system.slice/docker-' . $id . '.scope';
1102 3 ▶ if ( defined( $self->{docker_mapping}{$id} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"docker_mapping"}{$id}) 2 1 3
1103 2 return ( 'd_' . $self->{docker_mapping}{$id}{name}, $stat_dir );
1104 }
1105 1 return ( 'd_' . $id, $stat_dir );
1106 } elsif ( $cgroup_name =~ /^0\:\:\/docker\// ) {
1107 3 my $id = $cgroup_name;
1108 3 $id =~ s/^0\:\:\/docker\///;
1109 3 $id =~ s/\/.*$//;
1110 3 ▶ if ( defined( $self->{docker_mapping}{$id} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"docker_mapping"}{$id}) 2 1 3
1111 2 return ( 'd_' . $self->{docker_mapping}{$id}{name}, '/docker/' . $id );
1112 }
1113 1 return ( 'd_' . $id, '/docker/' . $id );
1114 } elsif ( $cgroup_name =~ /^0\:\:\/machine\.slice\/libpod\-conmon-/ ) {
1115 # every container has its own conmon scope and all of them are lumped in
1116 # under the one name, so the stats are read from each of those scopes
1117 1 my $scope = $cgroup_name;
1118 1 $scope =~ s/^0\:\:\/machine\.slice\///;
1119 1 $scope =~ s/\/.*$//;
1120 1 return ( 'libpod-conmon', '/machine.slice/' . $scope );
1121 } elsif ( $cgroup_name =~ /^0\:\:\/machine\.slice\/libpod\-/ ) {
1122 3 my $id = $cgroup_name;
1123 3 $id =~ s/^0\:\:\/machine\.slice\/libpod\-//;
1124 3 $id =~ s/\.scope.*$//;
1125 3 my $stat_dir = '/machine.slice/libpod-' . $id . '.scope';
1126 3 ▶ if ( defined( $self->{podman_mapping}{$id} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"podman_mapping"}{$id}) 2 1 3
1127 2 return ( 'p_' . $self->{podman_mapping}{$id}{name}, $stat_dir );
1128 }
1129 1 return ( 'libpod', $stat_dir );
1130 } elsif ( $cgroup_name =~ /^0\:\:\/(system|machine)\.slice\// ) {
1131 # machine.slice is handled the same as system.slice once the libpod scopes
1132 # have been dealt with... reading stats from all of machine.slice would also
1133 # count every podman container under it a second time
1134 15 my $slice = $1;
1135 15 ▶ my $prefix = ( $slice eq 'system' ) ? 's_' : 'm_';
Branch: 1 branch
BranchTrueFalseTotal
$slice eq 'system' ? : 9 6 15
1136 15 my $under_slice = $cgroup_name;
1137 15 $under_slice =~ s/^0\:\:\/(system|machine)\.slice\///;
1138 # the first unit in the path is used so that a service with nested
1139 # cgroups, such as systemd-udevd.service/udev, is grouped under the
1140 # service and not under the name of the nested cgroup... nested slices,
1141 # such as system-getty.slice, are skipped over as the unit of interest
1142 # lives under them
1143 15 my @path_split = split( /\//, $under_slice );
1144 15 my @unit_path;
1145 my $unit;
1146 15 foreach my $part (@path_split) {
1147 24 ▶ if ( !defined($unit) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $unit) 16 8 24
1148 16 push( @unit_path, $part );
1149 16 ▶ if ( $part =~ /\.(service|scope)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($part =~ /\.(service|scope)$/) 14 2 16
1150 14 $unit = $part;
1151 }
1152 }
1153 }
1154 15 ▶ if ( !defined($unit) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $unit) 1 14 15
1155 1 $unit = $path_split[-1];
1156 }
1157 15 ▶ if ( !defined($unit) || $unit eq '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $unit or $unit eq "") 0 15 15
Condition33%1/3
not defined $unit or $unit eq ""
l!l&&r!l&&!r
0015
MC/DC0%0/2
not defined $unit or $unit eq ""
not defined $unit $unit eq ""
Truth table33%1/3
not(A) or B
A= not defined $unitB= $unit eq ""
ABresult
1X1
011
000
1158 0 return undef;
1159 }
1160 # stats are read from the unit and not from the cgroups nested under it as
1161 # the name is for the unit as a whole
1162 15 my $stat_dir = '/' . $slice . '.slice/' . join( '/', @unit_path );
1163 15 $unit =~ s/\.(service|scope)$//;
1164 15 ▶ if ( $slice eq 'machine' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($slice eq "machine") 6 9 15
1165 6 $unit = $self->machine_name($unit);
1166 }
1167 15 return ( $prefix . $unit, $stat_dir );
1168 } elsif ( $cgroup_name =~ /^0\:\:\/user\.slice\// ) {
1169 5 my $user = $cgroup_name;
1170 5 $user =~ s/^0\:\:\/user\.slice\///;
1171 5 $user =~ s/\/.*$//;
1172 # the slice for the user is where the stats come from, meaning the session
1173 # scopes and the like nested under it are all accounted for
1174 5 my $stat_dir = '/user.slice/' . $user;
1175 5 $user =~ s/\.slice$//;
1176 5 $user =~ s/^user[\-\_]//;
1177  
1178 5 ▶ if ( $user =~ /^\d+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($user =~ /^\d+$/) 5 0 5
1179 5 my ( $name, $passwd, $uid, $gid, $quota, $comment, $gecos, $dir, $shell, $expire ) = getpwuid($user);
1180 5 ▶ if ( defined($name) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name) 5 0 5
1181 5 $self->{uid_mapping}{$user} = {
1182 name => $name,
1183 gid => $gid,
1184 home => $dir,
1185 gecos => $gecos,
1186 shell => $shell,
1187 };
1188 }
1189 } ## end if ( $user =~ /^\d+$/ )
1190  
1191 5 return ( 'u_' . $user, $stat_dir );
1192 }
1193  
1194 4 $cgroup_name =~ s/^0\:\:\///;
1195 4 $cgroup_name =~ s/\/.*//;
1196 4 ▶ if ( $cgroup_name eq '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cgroup_name eq "") 1 3 4
1197 1 return undef;
1198 }
1199 3 return ( $cgroup_name, '/' . $cgroup_name );
1200 } ## end sub cgroup_mapping
1201  
1202 # Normalizes the name of a unit under machine.slice to the name of the machine,
1203 # so it is readable and stays the same across restarts.
1204 #
1205 # systemd escapes "-" in unit names as \x2d, machined names scopes
1206 # machine-$name, and libvirt adds its type and domain ID, which changes each
1207 # time the VM starts, as $type-$id-$name. nspawn started via machinectl is
1208 # systemd-nspawn@$name instead.
1209 #
1210 # One arg is taken, the unit name with .service or .scope already removed.
1211 #
1212 # Returns the normalized name, prefixed with what it came from, qemu_, lxc_, or
1213 # nspawn_, when that is known. A plain machine-$name scope could be from any
1214 # machined user, such as nspawn run directly, so it gets no type. If normalizing
1215 # leaves no name, the unit name is returned as is.
1216 #
1217 # machine-qemu\x2d1\x2dvm -> qemu_vm
1218 # machine-lxc\x2d12\x2dweb -> lxc_web
1219 # systemd-nspawn@foo -> nspawn_foo
1220 # machine-foo -> foo
1221 # foo\x2dbar -> foo-bar
1222 6 ▶sub machine_name {
Subroutine machine_name: called CC=6 SCAR=18.0
Pod undocumented
1223 6 my $self = $_[0];
1224 6 my $unit = $_[1];
1225  
1226 6 my $name = $unit;
1227 6 my $type;
1228 6 $name =~ s/\\x([0-9a-fA-F]{2})/chr(hex($1))/ge;
1229 6 ▶ if ( $name =~ s/^machine\-// ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($name =~ s/^machine\-//) { } 4 2 6
elsif ($name =~ s/^systemd\-nspawn\@//) { } 2 0 2
1230 4 ▶ if ( $name =~ s/^(qemu|lxc)\-\d+\-// ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ s/^(qemu|lxc)\-\d+\-//) 3 1 4
1231 3 $type = $1;
1232 }
1233 } elsif ( $name =~ s/^systemd\-nspawn\@// ) {
1234 2 $type = 'nspawn';
1235 }
1236  
1237 6 ▶ if ( $name eq '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "") 0 6 6
1238 0 return $unit;
1239 }
1240  
1241 6 ▶ if ( defined($type) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $type) 5 1 6
1242 5 return $type . '_' . $name;
1243 }
1244  
1245 1 return $name;
1246 } ## end sub machine_name
1247  
1248 # Turns a counter into a per second rate using the value cached by the previous
1249 # run. Gauges, anything not in the counters list, are returned as is.
1250 #
1251 # For counters the raw value is saved to new_cache for the next run. The rate
1252 # is the delta divided by the interval since the previous run. *_usec time
1253 # counters are also divided by time_divider, making them seconds per second.
1254 #
1255 # Takes the args below.
1256 #
1257 # - name :: The cache entry, such as "cgroup-/system.slice/ssh.service" or
1258 # "proc-$pid-$uid-$gid-$cgroup".
1259 #
1260 # - var :: The stat name, such as "rbytes" or "cpu-time".
1261 #
1262 # - new_value :: The current raw value.
1263 #
1264 # - age :: Optional age in seconds of what the counter is for. Used when
1265 # nothing is cached, see below.
1266 #
1267 # Returns the rate, or the value for a gauge. 0 is returned if any of the first
1268 # three args are undef, for a rate over 10000000000 as it is garbage, and for a
1269 # counter with nothing cached unless age is set and within the interval, as
1270 # then the total accrued is all from this interval. If the counter went
1271 # backwards it was reset, so the raw value is used as the delta.
1272 #
1273 # # rbytes cached as 100 and a interval of 300
1274 # my $rate = $backend->cache_process( 'cgroup-/foo', 'rbytes', 400 ); # 1
1275 #
1276 # # a gauge
1277 # my $anon = $backend->cache_process( 'cgroup-/foo', 'anon', 12345 ); # 12345
1278 16 ▶sub cache_process {
Subroutine cache_process: called CC=19 SCAR=29.7
Pod undocumented
1279 16 my $self = $_[0];
1280 16 my $name = $_[1];
1281 16 my $var = $_[2];
1282 16 my $new_value = $_[3];
1283 16 my $age = $_[4];
1284  
1285 16 ▶ if ( !defined($name) || !defined($var) || !defined($new_value) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $name and defined $var and defined $new_value) 2 14 16
Condition83%5/6
defined $name and defined $var and defined $new_value
!ll&&!rl&&r
1114
defined $name and defined $var
!ll&&!rl&&r
1015
MC/DC66%2/3
defined $name and defined $var and defined $new_value
defined $name defined $var defined $new_value
Truth table75%3/4
A and B and C
A= defined $nameB= defined $varC= defined $new_value
ABCresult
0XX0
10X0
1100
1111
1286 2 warn('name, var, or new_value is undef');
1287 2 return 0;
1288 }
1289  
1290 # is a gauge and not a counter
1291 14 ▶ if ( !defined( $self->{counters}{$var} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"counters"}{$var}) 1 13 14
1292 1 return $new_value;
1293 }
1294  
1295 # not seen it yet
1296 13 ▶ if ( !defined( $self->{new_cache}{$name} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"new_cache"}{$name}) 13 0 13
1297 13 $self->{new_cache}{$name} = {};
1298 }
1299 13 $self->{new_cache}{$name}{$var} = $new_value;
1300  
1301 # first time seeing this counter, so there is no previous value to compute
1302 # a delta against... if what it is for is older than the polling interval,
1303 # or of unknown age, return 0 to avoid a spike from the accumulated total,
1304 # but for young ones the total accrued is from this interval, so usable...
1305 # either way the raw value saved to new_cache above provides the delta next run
1306 13 ▶ if ( !defined( $self->{cache}{$name}{$var} ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $self->{'cache'}{$name}{$var}) { } 4 9 13
elsif ($new_value >= $self->{'cache'}{$name}{$var}) { } 8 1 9
1307 4 ▶ if ( !defined($age) || !looks_like_number($age) || $age > $self->{interval} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $age && &looks_like_number($age) or $age > $self->{"interval"}) 3 1 4
Condition83%5/6
not defined $age && &looks_like_number($age) or $age > $self->{"interval"}
l!l&&r!l&&!r
121
defined $age && &looks_like_number($age)
!ll&&!rl&&r
103
MC/DC66%2/3
not defined $age && &looks_like_number($age) or $age > $self->{"interval"}
defined $age &looks_like_number($age) $age > $self->{"interval"}
Truth table75%3/4
not(A && B) or C
A= defined $ageB= &looks_like_number($age)C= $age > $self->{"interval"}
ABCresult
0XX1
10X1
1111
1100
1308 3 return 0;
1309 }
1310 } elsif ( $new_value >= $self->{cache}{$name}{$var} ) {
1311 # if the counter instead went backwards it was reset, such as the cgroup
1312 # being recreated, in which case the raw value is what has accrued since then
1313 8 $new_value = $new_value - $self->{cache}{$name}{$var};
1314 }
1315  
1316 10 ▶ if ( $new_value != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_value != 0) 9 1 10
1317 9 ▶ if ( $var eq 'cpu-time'
Branch: 1 branch
BranchTrueFalseTotal
if ($var eq "cpu-time" or $var eq "system-time" or $var eq "user-time" or $var eq "throttled-time" or $var eq "burst-time" or $var eq "core_sched.force_idle-time") 2 7 9
Condition66%10/15
$var eq "cpu-time" or $var eq "system-time" or $var eq "user-time" or $var eq "throttled-time" or $var eq "burst-time" or $var eq "core_sched.force_idle-time"
l!l&&r!l&&!r
207
$var eq "cpu-time" or $var eq "system-time" or $var eq "user-time" or $var eq "throttled-time" or $var eq "burst-time"
l!l&&r!l&&!r
207
$var eq "cpu-time" or $var eq "system-time" or $var eq "user-time" or $var eq "throttled-time"
l!l&&r!l&&!r
207
$var eq "cpu-time" or $var eq "system-time" or $var eq "user-time"
l!l&&r!l&&!r
207
$var eq "cpu-time" or $var eq "system-time"
l!l&&r!l&&!r
207
MC/DC16%1/6
$var eq "cpu-time" or $var eq "system-time" or $var eq "user-time" or $var eq "throttled-time" or $var eq "burst-time" or $var eq "core_sched.force_idle-time"
$var eq "cpu-time" $var eq "system-time" $var eq "user-time" $var eq "throttled-time" $var eq "burst-time" $var eq "core_sched.force_idle-time"
Truth table28%2/7
A or B or C or D or E or F
A= $var eq "cpu-time"B= $var eq "system-time"C= $var eq "user-time"D= $var eq "throttled-time"E= $var eq "burst-time"F= $var eq "core_sched.force_idle-time"
ABCDEFresult
1XXXXX1
01XXXX1
001XXX1
0001XX1
00001X1
0000011
0000000
1318 || $var eq 'system-time'
1319 || $var eq 'user-time'
1320 || $var eq 'throttled-time'
1321 || $var eq 'burst-time'
1322 || $var eq 'core_sched.force_idle-time' )
1323 {
1324 2 $new_value = $new_value / $self->{time_divider};
1325 }
1326 9 $new_value = $new_value / $self->{interval};
1327 } ## end if ( $new_value != 0 )
1328  
1329 # discard garbage values... new_cache keeps the raw value saved above so
1330 # the delta for the next run is still sane
1331 10 ▶ if ( $new_value > 10000000000 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_value > '10000000000') 1 9 10
1332 1 return 0;
1333 }
1334  
1335 9 return $new_value;
1336 } ## end sub cache_process
1337  
1338 =head1 AUTHOR
1339  
1340 Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >>
1341  
1342 =head1 BUGS
1343  
1344 Please report any bugs or feature requests to C<bug-oslv-monitor at rt.cpan.org>, or through
1345 the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=OSLV-Monitor>. I will be notified, and then you'll
1346 automatically be notified of progress on your bug as I make changes.
1347  
1348  
1349  
1350  
1351 =head1 SUPPORT
1352  
1353 You can find documentation for this module with the perldoc command.
1354  
1355 perldoc OSLV::Monitor
1356  
1357  
1358 You can also look for information at:
1359  
1360 =over 4
1361  
1362 =item * RT: CPAN's request tracker (report bugs here)
1363  
1364 L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=OSLV-Monitor>
1365  
1366 =item * CPAN Ratings
1367  
1368 L<https://cpanratings.perl.org/d/OSLV-Monitor>
1369  
1370 =item * Search CPAN
1371  
1372 L<https://metacpan.org/release/OSLV-Monitor>
1373  
1374 =back
1375  
1376  
1377 =head1 ACKNOWLEDGEMENTS
1378  
1379  
1380 =head1 LICENSE AND COPYRIGHT
1381  
1382 This software is Copyright (c) 2024 by Zane C. Bowers-Hadley.
1383  
1384 This is free software, licensed under:
1385  
1386 The Artistic License 2.0 (GPL Compatible)
1387  
1388  
1389 =cut
1390  
1391 8 1; # End of OSLV::Monitor
↑ Summary Monitor/Backends/FreeBSD.pm »