ProcessTable/Role/Table/OS/freebsd.pm untested

filter: Statementstmt 0.0% 0 / 49 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 72 CC 4 SCAR 19.7
CC
4
Cov
0%
_process_hash
20.0
list
2.0
fields
2.0
CRAP 7.1
1 package P9Y::ProcessTable::Role::Table::OS::freebsd;
2  
3 our $AUTHORITY = 'cpan:BBYRD'; # AUTHORITY
4 our $VERSION = '1.06_01'; # VERSION
5  
6 #############################################################################
7 # Modules
8  
9 # use sanity;
10 use strict qw(subs vars);
11 no strict 'refs';
12 use warnings FATAL => 'all';
13 no warnings qw(uninitialized);
14  
15 use Moo::Role;
16  
17 requires 'table';
18 requires 'process';
19  
20 use BSD::Process;
21  
22 use namespace::clean;
23 no warnings 'uninitialized';
24  
25 #############################################################################
26 # Methods
27  
28 sub list {
29 my $self = shift;
30 return sort { $a <=> $b } (BSD::Process::list);
31 }
32  
33 sub fields {
34 return ( qw/
35 pid uid gid euid suid sgid ppid pgrp sess
36 exe
37 minflt cminflt majflt cmajflt ttlflt cttlflt utime stime cutime cstime start time ctime
38 priority fname state flags size rss wchan cpuid pctcpu
39 / );
40 }
41  
42 sub _process_hash {
43 my ($self, $pid) = @_;
44 my $info = BSD::Process::info($pid);
45 return unless $info;
46  
47 my $hash = {};
48  
49 # (only has the ones that are different)
50 my $stat_loc = { qw/
51 uid ruid
52 gid rgid
53 euid uid
54 suid svuid
55 sgid svgid
56 pgrp pgid
57 sess sid
58 cpuid oncpu
59 priority nice
60 flags flag
61 cminflt minflt_ch
62 cmajflt majflt_ch
63 cutime utime_ch
64 cstime stime_ch
65 ctime time_ch
66 rss rssize
67 wchan wmesg
68 fname comm
69 exe comm
70 / };
71  
72 foreach my $key ( $self->fields ) {
73 my $item = $info->{ $stat_loc->{$key} || $key };
74 $hash->{$key} = $item if defined $item;
75 }
76  
77 $hash->{ ttlflt} = $hash->{ minflt} + $hash->{ majflt};
78 $hash->{cttlflt} = $hash->{cminflt} + $hash->{cmajflt};
79  
80 my $states = {
81 stat_1 => 'forking',
82 stat_2 => 'run',
83 stat_3 => 'sleep',
84 stat_4 => 'stop',
85 stat_5 => 'defunct',
86 stat_6 => 'wait',
87 stat_7 => 'disk sleep',
88 };
89  
90 my @state;
91 foreach my $key (keys %$states) {
92 push @state, $states->{$key} if $info->{$key};
93 }
94 $hash->{state} = join ' ', @state;
95  
96 return $hash;
97 }
98  
99 42;