Monitor/Backends/cgroups.pm

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