src_bin/ncps

filter: Statementstmt 57.5% 137 / 238 Branchbran 29.1% 39 / 134 Conditioncond 22.6% 19 / 84 MC/DCmcdc 0.0% 0 / 55 Subroutinesub 100% 9 / 9 Podpod n/a totaltotal 39.2% 204 / 520 CC 16 SCAR 26.4
CC
16
Cov
43%
help
20.5
BEGIN
1.0
BEGIN
1.0
CRAP 14.0
« blib/lib/Proc/ProcessTable/ncps.pm ↑ Summary
1 #!perl
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use POSIX ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Proc::ProcessTable;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use Proc::ProcessTable::ncps;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use Proc::ProcessTable::InfoString qw(proc_infostring_describe);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 # figure out what fields this platform supports so switches
12 # that require unsupported fields can be hidden and errored on
13 3 my %have_field;
14 3 foreach my $field ( Proc::ProcessTable->new->fields ) {
15 120 $have_field{$field} = 1;
16 }
17 # rss is still usable if it can be computed from rssize and the page size
18 3 ▶if ( ( !$have_field{rss} )
Branch: 1 branch
BranchTrueFalseTotal
if (not $have_field{"rss"} and $have_field{"rssize"}) 0 3 3
Condition33%1/3
not $have_field{"rss"} and $have_field{"rssize"}
!ll&&!rl&&r
300
MC/DC0%0/2
not $have_field{"rss"} and $have_field{"rssize"}
not $have_field{"rss"} $have_field{"rssize"}
Truth table33%1/3
not(A) and B
A= not $have_field{"rss"}B= $have_field{"rssize"}
ABresult
0X0
100
111
19 && $have_field{rssize} )
20 {
21 0 my $pagesize;
22 0 eval { $pagesize = POSIX::sysconf( POSIX::_SC_PAGESIZE() ); };
23 0 ▶ if ($pagesize) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pagesize) 0 0 0
24 0 $have_field{rss} = 1;
25 }
26 }
27 # pctmem is still usable if it can be computed from rss and physmem
28 3 ▶if ( ( !$have_field{pctmem} )
Branch: 1 branch
BranchTrueFalseTotal
if (not $have_field{"pctmem"} and $have_field{"rss"} and defined "Proc::ProcessTable::ncps"->physmem) 0 3 3
Condition33%2/6
not $have_field{"pctmem"} and $have_field{"rss"} and defined "Proc::ProcessTable::ncps"->physmem
!ll&&!rl&&r
300
not $have_field{"pctmem"} and $have_field{"rss"}
!ll&&!rl&&r
300
MC/DC0%0/3
not $have_field{"pctmem"} and $have_field{"rss"} and defined "Proc::ProcessTable::ncps"->physmem
not $have_field{"pctmem"} $have_field{"rss"} defined "Proc::ProcessTable::ncps"->physmem
Truth table25%1/4
not(A) and B and C
A= not $have_field{"pctmem"}B= $have_field{"rss"}C= defined "Proc::ProcessTable::ncps"->physmem
ABCresult
0XX0
10X0
1100
1111
29 && $have_field{rss}
30 && defined( Proc::ProcessTable::ncps->physmem ) )
31 {
32 0 $have_field{pctmem} = 1;
33 }
34  
35 2 ▶sub version {
Subroutine version: called CC=1 SCAR=0.0
36 2 print "ncps v. " . $Proc::ProcessTable::ncps::VERSION . "\n";
37 }
38  
39 1 ▶sub help {
Subroutine help: called CC=16 SCAR=30.2
40 1 my $help_text = '
41  
42 -c <regex> Search procs using the matching regex.
43 --ci Invert the command search.
44 ';
45  
46 1 ▶ if ( $have_field{cminflt} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($have_field{"cminflt"}) 1 0 1
47 1 $help_text = $help_text . '
48 --cf Show children minor faults.
49 ';
50 }
51  
52 1 ▶ if ( $have_field{cmajflt} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($have_field{"cmajflt"}) 1 0 1
53 1 $help_text = $help_text . '
54 --cF Show children major faults.
55 ';
56 }
57  
58 1 ▶ if ( $have_field{egid} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($have_field{"egid"}) 1 0 1
59 1 $help_text = $help_text . '
60 --eg Search for procs with an EGID set.
61 --egi Invert the EGID set search.
62 ';
63 }
64  
65 1 ▶ if ( $have_field{euid} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($have_field{"euid"}) 1 0 1
66 1 $help_text = $help_text . '
67 --eu Search for procs with an EUID set.
68 --eui Invert the EUID set search.
69 ';
70 }
71  
72 1 ▶ if ( $have_field{minflt} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($have_field{"minflt"}) 1 0 1
73 1 $help_text = $help_text . '
74 -f Show minor faults.
75 ';
76 }
77  
78 1 ▶ if ( $have_field{majflt} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($have_field{"majflt"}) 1 0 1
79 1 $help_text = $help_text . '
80 -F Show major faults.
81 ';
82 }
83  
84 1 ▶ if ( $have_field{jid} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($have_field{"jid"}) 0 1 1
85 0 $help_text = $help_text . '
86 -J Show jail IDs.
87 -j <jids> A comma separated list of JIDs to search for.
88 --ji Invert the JIDs search.
89 ';
90 }
91  
92 1 $help_text = $help_text . '
93 --idle Show the idle kernel process.
94  
95 --kern Searches for kernel processes.
96 --kerni Invert the kernel process search.
97 ';
98  
99 1 ▶ if ( $have_field{pctmem} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($have_field{"pctmem"}) 1 0 1
100 1 $help_text = $help_text . '
101 -m <pctmem> Memory usage percent to search for.
102 --mi Invert the memory usage search.
103 ';
104 }
105  
106 1 ▶ if ( $have_field{numthr} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($have_field{"numthr"}) 0 1 1
107 0 $help_text = $help_text . '
108 -n Show number of threads.
109 ';
110 }
111  
112 1 $help_text = $help_text . '
113 --nc disable color.
114 ';
115  
116 1 ▶ if ( $have_field{pctcpu} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($have_field{"pctcpu"}) 1 0 1
117 1 $help_text = $help_text . '
118 -p <pctcpu> CPU usage percent to search for.
119 --pi Invert the CPU usage search.
120 ';
121 }
122  
123 1 $help_text = $help_text . '
124 --pid <pids> PIDs to search for.
125 --pidi Invert the PID search.
126 ';
127  
128 1 ▶ if ( $have_field{rss} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($have_field{"rss"}) 1 0 1
129 1 $help_text = $help_text . '
130 -r <RSSs> A comma separated list of RSS values to search for.
131 --ri Invert the RSS search.
132 ';
133 }
134  
135 1 $help_text = $help_text . '
136 -s Show swapped out procs.
137 --si Invert the swapped out search.
138  
139 --self Show the ncps process as well.
140  
141 --st <states> A comma separated list of states to search for.
142 --sti Invert the state search.
143  
144 --stats Print some general stats about CPU usage and memory usage.
145 ';
146  
147 1 ▶ if ( $have_field{time} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($have_field{"time"}) 1 0 1
148 1 $help_text = $help_text . '
149 -t <times> A comma separated value of time, in seconds, to search for.
150 --ti Invert the time search.
151 ';
152 }
153  
154 1 ▶ if ( $have_field{ttydev} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($have_field{"ttydev"}) 0 1 1
155 0 $help_text = $help_text . '
156 --tty Show TTYs.
157 ';
158 }
159  
160 1 $help_text = $help_text . '
161 -u <UIDs> A comma separated list of UIDs or usernames.
162 --ui Invert the UID/username search.
163 ';
164  
165 1 ▶ if ( $have_field{size} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($have_field{"size"}) 1 0 1
166 1 $help_text = $help_text . '
167 --vs <VSZs> A comma separated list of VSZs to search for.
168 --vsi Invert the VSZ search.
169 ';
170 }
171  
172 1 ▶ if ( $have_field{wchan} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($have_field{"wchan"}) 1 0 1
173 1 $help_text = $help_text . '
174 -w <wchans> A string search for wait channels.
175 --wi Invert the wait channel search.
176 ';
177 }
178  
179 1 $help_text = $help_text . '
180 -z Show zombie procs.
181  
182  
183 For the various switches above that can take numeric values,
184 the equalities below can be used, by directly prepending them to
185 the number.
186 <
187 <=
188 >
189 >=
190 !
191  
192  
193 The information column is provided by Proc::ProcessTable::InfoString,
194 which describes it for this OS as below.
195  
196 ';
197  
198 # state and flag support varies by OS, so let
199 # Proc::ProcessTable::InfoString describe the ones usable on this one
200 1 $help_text = $help_text . proc_infostring_describe();
201  
202 1 print $help_text;
203 } ## end sub help
204  
205 # defaults
206 3 my $wait_channels_string;
207 3 my $wait_channels_invert = 0;
208 3 my $zombie = 0;
209 3 my $swapped = 0;
210 3 my $no_color = 0;
211 3 my $swapped_invert = 0;
212 3 my $version;
213 my $help;
214 3 my $commands_string;
215 3 my $commands_invert = 0;
216 3 my $pids_string;
217 3 my $pids_invert = 0;
218 3 my $cpu_string;
219 3 my $cpu_invert = 0;
220 3 my $mem_string;
221 3 my $mem_invert = 0;
222 3 my $rss_string;
223 3 my $rss_invert = 0;
224 3 my $time_string;
225 3 my $time_invert = 0;
226 3 my $states_string;
227 3 my $states_invert = 0;
228 3 my $minor_faults = 0;
229 3 my $major_faults = 0;
230 3 my $cminor_faults = 0;
231 3 my $cmajor_faults = 0;
232 3 my $numthr = 0;
233 3 my $tty = 0;
234 3 my $jid = 0;
235 3 my $jids_string;
236 3 my $jids_invert = 0;
237 3 my $uids_string;
238 3 my $uids_invert = 0;
239 3 my $euid = 0;
240 3 my $euid_invert = 0;
241 3 my $egid = 0;
242 3 my $egid_invert = 0;
243 3 my $self_proc = 0;
244 3 my $idle = 0;
245 3 my $stats = 0;
246 3 my $kern = 0;
247 3 my $kern_invert = 0;
248 3 my $vsz_string;
249 3 my $vsz_invert = 0;
250  
251 # get the commandline options
252 3 Getopt::Long::Configure('no_ignore_case');
253 3 Getopt::Long::Configure('bundling');
254 3 my $getopt_success = GetOptions(
255 'w=s' => \$wait_channels_string,
256 'wi' => \$wait_channels_invert,
257 'h' => \$help,
258 'help' => \$help,
259 'v' => \$version,
260 'version' => \$version,
261 'z' => \$zombie,
262 's' => \$swapped,
263 'si' => \$swapped_invert,
264 'c=s' => \$commands_string,
265 'ci' => \$commands_invert,
266 'pid=s' => \$pids_string,
267 'pidi' => \$pids_invert,
268 'p=s' => \$cpu_string,
269 'pi' => \$cpu_invert,
270 'm=s' => \$mem_string,
271 'mi' => \$mem_invert,
272 'r=s' => \$rss_string,
273 'ri' => \$rss_invert,
274 't=s' => \$time_string,
275 'ti' => \$time_invert,
276 'st=s' => \$states_string,
277 'sti' => \$states_invert,
278 'f' => \$minor_faults,
279 'F' => \$major_faults,
280 'cf' => \$cminor_faults,
281 'cF' => \$cmajor_faults,
282 'n' => \$numthr,
283 'tty' => \$tty,
284 'J' => \$jid,
285 'nc' => \$no_color,
286 'j=s' => \$jids_string,
287 'ji' => \$jids_invert,
288 'u=s' => \$uids_string,
289 'ui' => \$uids_invert,
290 'eu' => \$euid,
291 'eui' => \$euid_invert,
292 'eg' => \$egid,
293 'egi' => \$egid_invert,
294 'self' => \$self_proc,
295 'idle' => \$idle,
296 'stats' => \$stats,
297 'kern' => \$kern,
298 'kerni' => \$kern_invert,
299 'vs=s' => \$vsz_string,
300 'vsi' => \$vsz_invert,
301 );
302 3 ▶if ( !$getopt_success ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($getopt_success) 1 2 3
303 1 warn('Failed to parse the command line options');
304 1 exit 255;
305 }
306  
307 # error on any switches requiring fields this platform does not support
308 2 my @unusable_switches;
309 0 ▶if ( $minor_faults && ( !$have_field{minflt} ) ) { push( @unusable_switches, '-f' ); }
Branch: 1 branch
BranchTrueFalseTotal
if ($minor_faults and not $have_field{"minflt"}) 0 2 2
Condition33%1/3
$minor_faults and not $have_field{"minflt"}
!ll&&!rl&&r
200
MC/DC0%0/2
$minor_faults and not $have_field{"minflt"}
$minor_faults not $have_field{"minflt"}
Truth table33%1/3
A and not(B)
A= $minor_faultsB= not $have_field{"minflt"}
ABresult
0X0
100
111
310 0 ▶if ( $major_faults && ( !$have_field{majflt} ) ) { push( @unusable_switches, '-F' ); }
Branch: 1 branch
BranchTrueFalseTotal
if ($major_faults and not $have_field{"majflt"}) 0 2 2
Condition33%1/3
$major_faults and not $have_field{"majflt"}
!ll&&!rl&&r
200
MC/DC0%0/2
$major_faults and not $have_field{"majflt"}
$major_faults not $have_field{"majflt"}
Truth table33%1/3
A and not(B)
A= $major_faultsB= not $have_field{"majflt"}
ABresult
0X0
100
111
311 0 ▶if ( $cminor_faults && ( !$have_field{cminflt} ) ) { push( @unusable_switches, '--cf' ); }
Branch: 1 branch
BranchTrueFalseTotal
if ($cminor_faults and not $have_field{"cminflt"}) 0 2 2
Condition33%1/3
$cminor_faults and not $have_field{"cminflt"}
!ll&&!rl&&r
200
MC/DC0%0/2
$cminor_faults and not $have_field{"cminflt"}
$cminor_faults not $have_field{"cminflt"}
Truth table33%1/3
A and not(B)
A= $cminor_faultsB= not $have_field{"cminflt"}
ABresult
0X0
100
111
312 0 ▶if ( $cmajor_faults && ( !$have_field{cmajflt} ) ) { push( @unusable_switches, '--cF' ); }
Branch: 1 branch
BranchTrueFalseTotal
if ($cmajor_faults and not $have_field{"cmajflt"}) 0 2 2
Condition33%1/3
$cmajor_faults and not $have_field{"cmajflt"}
!ll&&!rl&&r
200
MC/DC0%0/2
$cmajor_faults and not $have_field{"cmajflt"}
$cmajor_faults not $have_field{"cmajflt"}
Truth table33%1/3
A and not(B)
A= $cmajor_faultsB= not $have_field{"cmajflt"}
ABresult
0X0
100
111
313 0 ▶if ( $numthr && ( !$have_field{numthr} ) ) { push( @unusable_switches, '-n' ); }
Branch: 1 branch
BranchTrueFalseTotal
if ($numthr and not $have_field{"numthr"}) 0 2 2
Condition33%1/3
$numthr and not $have_field{"numthr"}
!ll&&!rl&&r
200
MC/DC0%0/2
$numthr and not $have_field{"numthr"}
$numthr not $have_field{"numthr"}
Truth table33%1/3
A and not(B)
A= $numthrB= not $have_field{"numthr"}
ABresult
0X0
100
111
314 0 ▶if ( $tty && ( !$have_field{ttydev} ) ) { push( @unusable_switches, '--tty' ); }
Branch: 1 branch
BranchTrueFalseTotal
if ($tty and not $have_field{"ttydev"}) 0 2 2
Condition33%1/3
$tty and not $have_field{"ttydev"}
!ll&&!rl&&r
200
MC/DC0%0/2
$tty and not $have_field{"ttydev"}
$tty not $have_field{"ttydev"}
Truth table33%1/3
A and not(B)
A= $ttyB= not $have_field{"ttydev"}
ABresult
0X0
100
111
315 0 ▶if ( $jid && ( !$have_field{jid} ) ) { push( @unusable_switches, '-J' ); }
Branch: 1 branch
BranchTrueFalseTotal
if ($jid and not $have_field{"jid"}) 0 2 2
Condition33%1/3
$jid and not $have_field{"jid"}
!ll&&!rl&&r
200
MC/DC0%0/2
$jid and not $have_field{"jid"}
$jid not $have_field{"jid"}
Truth table33%1/3
A and not(B)
A= $jidB= not $have_field{"jid"}
ABresult
0X0
100
111
316 0 ▶if ( defined($jids_string) && ( !$have_field{jid} ) ) { push( @unusable_switches, '-j' ); }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $jids_string and not $have_field{"jid"}) 0 2 2
Condition33%1/3
defined $jids_string and not $have_field{"jid"}
!ll&&!rl&&r
200
MC/DC0%0/2
defined $jids_string and not $have_field{"jid"}
defined $jids_string not $have_field{"jid"}
Truth table33%1/3
A and not(B)
A= defined $jids_stringB= not $have_field{"jid"}
ABresult
0X0
100
111
317 0 ▶if ( defined($mem_string) && ( !$have_field{pctmem} ) ) { push( @unusable_switches, '-m' ); }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $mem_string and not $have_field{"pctmem"}) 0 2 2
Condition33%1/3
defined $mem_string and not $have_field{"pctmem"}
!ll&&!rl&&r
200
MC/DC0%0/2
defined $mem_string and not $have_field{"pctmem"}
defined $mem_string not $have_field{"pctmem"}
Truth table33%1/3
A and not(B)
A= defined $mem_stringB= not $have_field{"pctmem"}
ABresult
0X0
100
111
318 0 ▶if ( defined($cpu_string) && ( !$have_field{pctcpu} ) ) { push( @unusable_switches, '-p' ); }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cpu_string and not $have_field{"pctcpu"}) 0 2 2
Condition33%1/3
defined $cpu_string and not $have_field{"pctcpu"}
!ll&&!rl&&r
200
MC/DC0%0/2
defined $cpu_string and not $have_field{"pctcpu"}
defined $cpu_string not $have_field{"pctcpu"}
Truth table33%1/3
A and not(B)
A= defined $cpu_stringB= not $have_field{"pctcpu"}
ABresult
0X0
100
111
319 0 ▶if ( defined($rss_string) && ( !$have_field{rss} ) ) { push( @unusable_switches, '-r' ); }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rss_string and not $have_field{"rss"}) 0 2 2
Condition33%1/3
defined $rss_string and not $have_field{"rss"}
!ll&&!rl&&r
200
MC/DC0%0/2
defined $rss_string and not $have_field{"rss"}
defined $rss_string not $have_field{"rss"}
Truth table33%1/3
A and not(B)
A= defined $rss_stringB= not $have_field{"rss"}
ABresult
0X0
100
111
320 0 ▶if ( defined($time_string) && ( !$have_field{time} ) ) { push( @unusable_switches, '-t' ); }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $time_string and not $have_field{"time"}) 0 2 2
Condition33%1/3
defined $time_string and not $have_field{"time"}
!ll&&!rl&&r
200
MC/DC0%0/2
defined $time_string and not $have_field{"time"}
defined $time_string not $have_field{"time"}
Truth table33%1/3
A and not(B)
A= defined $time_stringB= not $have_field{"time"}
ABresult
0X0
100
111
321 0 ▶if ( defined($vsz_string) && ( !$have_field{size} ) ) { push( @unusable_switches, '--vs' ); }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $vsz_string and not $have_field{"size"}) 0 2 2
Condition33%1/3
defined $vsz_string and not $have_field{"size"}
!ll&&!rl&&r
200
MC/DC0%0/2
defined $vsz_string and not $have_field{"size"}
defined $vsz_string not $have_field{"size"}
Truth table33%1/3
A and not(B)
A= defined $vsz_stringB= not $have_field{"size"}
ABresult
0X0
100
111
322 0 ▶if ( defined($wait_channels_string) && ( !$have_field{wchan} ) ) { push( @unusable_switches, '-w' ); }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $wait_channels_string and not $have_field{"wchan"}) 0 2 2
Condition33%1/3
defined $wait_channels_string and not $have_field{"wchan"}
!ll&&!rl&&r
200
MC/DC0%0/2
defined $wait_channels_string and not $have_field{"wchan"}
defined $wait_channels_string not $have_field{"wchan"}
Truth table33%1/3
A and not(B)
A= defined $wait_channels_stringB= not $have_field{"wchan"}
ABresult
0X0
100
111
323 0 ▶if ( $euid && ( !$have_field{euid} ) ) { push( @unusable_switches, '--eu' ); }
Branch: 1 branch
BranchTrueFalseTotal
if ($euid and not $have_field{"euid"}) 0 2 2
Condition33%1/3
$euid and not $have_field{"euid"}
!ll&&!rl&&r
200
MC/DC0%0/2
$euid and not $have_field{"euid"}
$euid not $have_field{"euid"}
Truth table33%1/3
A and not(B)
A= $euidB= not $have_field{"euid"}
ABresult
0X0
100
111
324 0 ▶if ( $egid && ( !$have_field{egid} ) ) { push( @unusable_switches, '--eg' ); }
Branch: 1 branch
BranchTrueFalseTotal
if ($egid and not $have_field{"egid"}) 0 2 2
Condition33%1/3
$egid and not $have_field{"egid"}
!ll&&!rl&&r
200
MC/DC0%0/2
$egid and not $have_field{"egid"}
$egid not $have_field{"egid"}
Truth table33%1/3
A and not(B)
A= $egidB= not $have_field{"egid"}
ABresult
0X0
100
111
325  
326 2 ▶if ( defined( $unusable_switches[0] ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $unusable_switches[0]) 0 2 2
327 0 warn( 'The following switches can not be used on this OS as the fields they require are not supported: '
328 . join( ' ', @unusable_switches ) );
329 0 exit 255;
330 }
331  
332 # print the version info if requested
333 2 ▶if ($version) {
Branch: 1 branch
BranchTrueFalseTotal
if ($version) 1 1 2
334 1 &version;
335 1 exit;
336 }
337  
338 1 ▶if ($help) {
Branch: 1 branch
BranchTrueFalseTotal
if ($help) 1 0 1
339 1 &version;
340 1 &help;
341 1 exit;
342 }
343  
344 0 my @filters;
345  
346 #
347 # handles wait channels
348 #
349 0 ▶if ( defined($wait_channels_string) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $wait_channels_string) 0 0 0
350 0 my @wchans = split( /\,/, $wait_channels_string );
351 0 push(
352 @filters,
353 {
354 type => 'WChan',
355 invert => $wait_channels_invert,
356 args => {
357 wchans => \@wchans,
358 },
359 }
360 );
361 } ## end if ( defined($wait_channels_string) )
362  
363 #
364 # handles swappped procs search
365 #
366 0 ▶if ($swapped) {
Branch: 1 branch
BranchTrueFalseTotal
if ($swapped) 0 0 0
367 0 push(
368 @filters,
369 {
370 type => 'Swapped',
371 invert => $swapped_invert,
372 args => {},
373 }
374 );
375 } ## end if ($swapped)
376  
377 #
378 # handles the zombie procs search
379 #
380 0 ▶if ($zombie) {
Branch: 1 branch
BranchTrueFalseTotal
if ($zombie) 0 0 0
381 0 push(
382 @filters,
383 {
384 type => 'State',
385 invert => 0,
386 args => {
387 states => [ 'zombie', 'defunct' ],
388 },
389 }
390 );
391 } ## end if ($zombie)
392  
393 #
394 # handles the commands search
395 #
396 0 ▶if ( defined($commands_string) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $commands_string) 0 0 0
397 0 my @commands = split( /\,/, $commands_string );
398 0 push(
399 @filters,
400 {
401 type => 'Command',
402 invert => $commands_invert,
403 args => {
404 commands => \@commands,
405 },
406 }
407 );
408 } ## end if ( defined($commands_string) )
409  
410 #
411 # handles the PIDs search
412 #
413 0 ▶if ( defined($pids_string) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pids_string) 0 0 0
414 0 my @pids = split( /\,/, $pids_string );
415 0 push(
416 @filters,
417 {
418 type => 'PID',
419 invert => $pids_invert,
420 args => {
421 pids => \@pids,
422 },
423 }
424 );
425 } ## end if ( defined($pids_string) )
426  
427 #
428 # handles the CPU search
429 #
430 0 ▶if ( defined($cpu_string) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cpu_string) 0 0 0
431 0 my @cpus = split( /\,/, $cpu_string );
432 0 push(
433 @filters,
434 {
435 type => 'PctCPU',
436 invert => $cpu_invert,
437 args => {
438 pctcpus => \@cpus,
439 },
440 }
441 );
442 } ## end if ( defined($cpu_string) )
443  
444 #
445 # handles the memory search
446 #
447 0 ▶if ( defined($mem_string) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $mem_string) 0 0 0
448 0 my @mems = split( /\,/, $mem_string );
449 0 push(
450 @filters,
451 {
452 type => 'PctMem',
453 invert => $mem_invert,
454 args => {
455 pctmems => \@mems,
456 },
457 }
458 );
459 } ## end if ( defined($mem_string) )
460  
461 #
462 # handles the RSS search
463 #
464 0 ▶if ( defined($rss_string) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rss_string) 0 0 0
465 0 my @rss = split( /\,/, $rss_string );
466 0 push(
467 @filters,
468 {
469 type => 'RSS',
470 invert => $rss_invert,
471 args => {
472 rss => \@rss,
473 },
474 }
475 );
476 } ## end if ( defined($rss_string) )
477  
478 #
479 # handles the JID search
480 #
481 0 ▶if ( defined($jids_string) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $jids_string) 0 0 0
482 0 my @jids = split( /\,/, $jids_string );
483 0 push(
484 @filters,
485 {
486 type => 'JID',
487 invert => $jids_invert,
488 args => {
489 jids => \@jids,
490 },
491 }
492 );
493 } ## end if ( defined($jids_string) )
494  
495 #
496 # handles the time search
497 #
498 0 ▶if ( defined($time_string) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $time_string) 0 0 0
499 0 my @times = split( /\,/, $time_string );
500 0 push(
501 @filters,
502 {
503 type => 'Time',
504 invert => $time_invert,
505 args => {
506 times => \@times,
507 },
508 }
509 );
510 } ## end if ( defined($time_string) )
511  
512 #
513 # handles the UID/username search
514 #
515 0 ▶if ( defined($uids_string) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $uids_string) 0 0 0
516 0 my @uids = split( /\,/, $uids_string );
517 0 push(
518 @filters,
519 {
520 type => 'UID',
521 invert => $uids_invert,
522 args => {
523 uids => \@uids,
524 },
525 }
526 );
527 } ## end if ( defined($uids_string) )
528  
529 #
530 # handles the virtual size search
531 #
532 0 ▶if ( defined($vsz_string) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $vsz_string) 0 0 0
533 0 my @vszs = split( /\,/, $vsz_string );
534 0 push(
535 @filters,
536 {
537 type => 'Size',
538 invert => $vsz_invert,
539 args => {
540 sizes => \@vszs,
541 },
542 }
543 );
544 } ## end if ( defined($vsz_string) )
545  
546 #
547 # handles the kernel process search
548 #
549 0 ▶if ($kern) {
Branch: 1 branch
BranchTrueFalseTotal
if ($kern) 0 0 0
550 0 push(
551 @filters,
552 {
553 type => 'KernProc',
554 invert => $kern_invert,
555 args => {},
556 }
557 );
558 } ## end if ($kern)
559  
560 #
561 # handles the EUID set search
562 #
563 0 ▶if ($euid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($euid) 0 0 0
564 0 push(
565 @filters,
566 {
567 type => 'EUIDset',
568 invert => $euid_invert,
569 args => {},
570 }
571 );
572 } ## end if ($euid)
573  
574 #
575 # handles the EGID set search
576 #
577 0 ▶if ($egid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($egid) 0 0 0
578 0 push(
579 @filters,
580 {
581 type => 'EGIDset',
582 invert => $egid_invert,
583 args => {},
584 }
585 );
586 } ## end if ($egid)
587  
588 #
589 # handles the states search
590 #
591 0 ▶if ( defined($states_string) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $states_string) 0 0 0
592 0 my @states = split( /\,/, $states_string );
593 0 push(
594 @filters,
595 {
596 type => 'State',
597 invert => $states_invert,
598 args => {
599 states => \@states,
600 },
601 }
602 );
603 } ## end if ( defined($states_string) )
604  
605 # XOR common boolean CLI flags
606 0 ▶if ( defined( $ENV{NCPS_jid} ) && ( $ENV{NCPS_jid} eq '1' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ENV{"NCPS_jid"} and $ENV{"NCPS_jid"} eq 1) 0 0 0
Condition0%0/3
defined $ENV{"NCPS_jid"} and $ENV{"NCPS_jid"} eq 1
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ENV{"NCPS_jid"} and $ENV{"NCPS_jid"} eq 1
defined $ENV{"NCPS_jid"} $ENV{"NCPS_jid"} eq 1
Truth table0%0/3
A and B
A= defined $ENV{"NCPS_jid"}B= $ENV{"NCPS_jid"} eq 1
ABresult
0X0
100
111
607 0 $jid = $jid ^ 1;
608 }
609 0 ▶if ( defined( $ENV{NCPS_numthr} ) && ( $ENV{NCPS_numthr} eq '1' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ENV{"NCPS_numthr"} and $ENV{"NCPS_numthr"} eq 1) 0 0 0
Condition0%0/3
defined $ENV{"NCPS_numthr"} and $ENV{"NCPS_numthr"} eq 1
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ENV{"NCPS_numthr"} and $ENV{"NCPS_numthr"} eq 1
defined $ENV{"NCPS_numthr"} $ENV{"NCPS_numthr"} eq 1
Truth table0%0/3
A and B
A= defined $ENV{"NCPS_numthr"}B= $ENV{"NCPS_numthr"} eq 1
ABresult
0X0
100
111
610 0 $numthr = $numthr ^ 1;
611 }
612 0 ▶if ( defined( $ENV{NCPS_cmajflt} ) && ( $ENV{NCPS_cmajflt} eq '1' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ENV{"NCPS_cmajflt"} and $ENV{"NCPS_cmajflt"} eq 1) 0 0 0
Condition0%0/3
defined $ENV{"NCPS_cmajflt"} and $ENV{"NCPS_cmajflt"} eq 1
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ENV{"NCPS_cmajflt"} and $ENV{"NCPS_cmajflt"} eq 1
defined $ENV{"NCPS_cmajflt"} $ENV{"NCPS_cmajflt"} eq 1
Truth table0%0/3
A and B
A= defined $ENV{"NCPS_cmajflt"}B= $ENV{"NCPS_cmajflt"} eq 1
ABresult
0X0
100
111
613 0 $cmajor_faults = $cmajor_faults ^ 1;
614 }
615 0 ▶if ( defined( $ENV{NCPS_majflt} ) && ( $ENV{NCPS_majflt} eq '1' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ENV{"NCPS_majflt"} and $ENV{"NCPS_majflt"} eq 1) 0 0 0
Condition0%0/3
defined $ENV{"NCPS_majflt"} and $ENV{"NCPS_majflt"} eq 1
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ENV{"NCPS_majflt"} and $ENV{"NCPS_majflt"} eq 1
defined $ENV{"NCPS_majflt"} $ENV{"NCPS_majflt"} eq 1
Truth table0%0/3
A and B
A= defined $ENV{"NCPS_majflt"}B= $ENV{"NCPS_majflt"} eq 1
ABresult
0X0
100
111
616 0 $major_faults = $major_faults ^ 1;
617 }
618 0 ▶if ( defined( $ENV{NCPS_cminflt} ) && ( $ENV{NCPS_cminflt} eq '1' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ENV{"NCPS_cminflt"} and $ENV{"NCPS_cminflt"} eq 1) 0 0 0
Condition0%0/3
defined $ENV{"NCPS_cminflt"} and $ENV{"NCPS_cminflt"} eq 1
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ENV{"NCPS_cminflt"} and $ENV{"NCPS_cminflt"} eq 1
defined $ENV{"NCPS_cminflt"} $ENV{"NCPS_cminflt"} eq 1
Truth table0%0/3
A and B
A= defined $ENV{"NCPS_cminflt"}B= $ENV{"NCPS_cminflt"} eq 1
ABresult
0X0
100
111
619 0 $cminor_faults = $cminor_faults ^ 1;
620 }
621 0 ▶if ( defined( $ENV{NCPS_minflt} ) && ( $ENV{NCPS_minflt} eq '1' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ENV{"NCPS_minflt"} and $ENV{"NCPS_minflt"} eq 1) 0 0 0
Condition0%0/3
defined $ENV{"NCPS_minflt"} and $ENV{"NCPS_minflt"} eq 1
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ENV{"NCPS_minflt"} and $ENV{"NCPS_minflt"} eq 1
defined $ENV{"NCPS_minflt"} $ENV{"NCPS_minflt"} eq 1
Truth table0%0/3
A and B
A= defined $ENV{"NCPS_minflt"}B= $ENV{"NCPS_minflt"} eq 1
ABresult
0X0
100
111
622 0 $minor_faults = $minor_faults ^ 1;
623 }
624 0 ▶if ( defined( $ENV{NCPS_tty} ) && ( $ENV{NCPS_tty} eq '1' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ENV{"NCPS_tty"} and $ENV{"NCPS_tty"} eq 1) 0 0 0
Condition0%0/3
defined $ENV{"NCPS_tty"} and $ENV{"NCPS_tty"} eq 1
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ENV{"NCPS_tty"} and $ENV{"NCPS_tty"} eq 1
defined $ENV{"NCPS_tty"} $ENV{"NCPS_tty"} eq 1
Truth table0%0/3
A and B
A= defined $ENV{"NCPS_tty"}B= $ENV{"NCPS_tty"} eq 1
ABresult
0X0
100
111
625 0 $tty = $tty ^ 1;
626 }
627 0 ▶if ( defined( $ENV{NCPS_self} ) && ( $ENV{NCPS_self} eq '1' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ENV{"NCPS_self"} and $ENV{"NCPS_self"} eq 1) 0 0 0
Condition0%0/3
defined $ENV{"NCPS_self"} and $ENV{"NCPS_self"} eq 1
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ENV{"NCPS_self"} and $ENV{"NCPS_self"} eq 1
defined $ENV{"NCPS_self"} $ENV{"NCPS_self"} eq 1
Truth table0%0/3
A and B
A= defined $ENV{"NCPS_self"}B= $ENV{"NCPS_self"} eq 1
ABresult
0X0
100
111
628 0 $self_proc = $self_proc ^ 1;
629 }
630 0 ▶if ( defined( $ENV{NCPS_idle} ) && ( $ENV{NCPS_idle} eq '1' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ENV{"NCPS_idle"} and $ENV{"NCPS_idle"} eq 1) 0 0 0
Condition0%0/3
defined $ENV{"NCPS_idle"} and $ENV{"NCPS_idle"} eq 1
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ENV{"NCPS_idle"} and $ENV{"NCPS_idle"} eq 1
defined $ENV{"NCPS_idle"} $ENV{"NCPS_idle"} eq 1
Truth table0%0/3
A and B
A= defined $ENV{"NCPS_idle"}B= $ENV{"NCPS_idle"} eq 1
ABresult
0X0
100
111
631 0 $idle = $idle ^ 1;
632 }
633 #if ( defined( $ENV{NCPS_inverted} ) ){
634 # no invert support really yet
635 #}
636  
637 # xor --nc if needed
638 0 ▶if ( defined( $ENV{NO_COLOR} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ENV{"NO_COLOR"}) 0 0 0
639 0 $no_color = $no_color ^ 1;
640 }
641 # disable the color if requested
642 0 ▶if ($no_color) {
Branch: 1 branch
BranchTrueFalseTotal
if ($no_color) 0 0 0
643 0 $ENV{ANSI_COLORS_DISABLED} = 1;
644 }
645  
646 #
647 # handles the self proc flag
648 #
649 0 ▶if ( !$self_proc ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self_proc) 0 0 0
650 0 push(
651 @filters,
652 {
653 type => 'PID',
654 invert => 1,
655 args => {
656 pids => [$$],
657 },
658 }
659 );
660 } ## end if ( !$self_proc )
661  
662 #
663 # handles the idle proc flag
664 #
665 0 ▶if ( !$idle ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($idle) 0 0 0
666 0 push(
667 @filters,
668 {
669 type => 'Idle',
670 invert => 1,
671 args => {},
672 }
673 );
674 } ## end if ( !$idle )
675  
676 0 my $args = {
677 cmajor_faults => $cmajor_faults,
678 cminor_faults => $cminor_faults,
679 major_faults => $major_faults,
680 minor_faults => $minor_faults,
681 numthr => $numthr,
682 tty => $tty,
683 jid => $jid,
684 stats => $stats,
685 match => {
686 checks => \@filters,
687 }
688 };
689  
690 0 my $ncps = Proc::ProcessTable::ncps->new($args);
691 0 print $ncps->run;
692 0 exit 0;
693  
694 =head1 NAME
695  
696 ncps - Searches the process table and displays the results.
697  
698 =head1 SYNOPSIS
699  
700 ncps [B<-c> <regex>] [B<--ci>] [B<--cf>] [B<--cF>] [B<--eg>] [B<--egi>]
701 [B<-f>] [B<-F>] [B<-J>] [B<-j> <JIDs>] [B<--ji>] [B<--idle>] [B<--kern>]
702 [B<--kerni>] [B<-m> <pctmem>] [B<--mi>] [B<-n>] [B<--nc>] [B<-p> <pctcpu>]
703 [B<--pi>] [B<--pid> <PIDs>] [B<--pidi>] [B<-r> <RSS>] [B<--ri>] [B<-s>]
704 [B<--si>] [B<--self>] [B<--st> <states>] [B<--sti>] [B<--stats>]
705 [B<-t> <times>] [B<--ti>] [B<--tty>] [B<-u> <UIDs>] [B<--ui>] [B<--vs> <VSZs>]
706 [B<--vsi>] [B<-w> <WChans>] [B<--wi>] [B<-z>]
707  
708 =head1 DESCRIPTION
709  
710 No flags needed passed to use. By default it will show all processes except
711 for its own and the idle process.
712  
713 The info column is provided by L<Proc::ProcessTable::InfoString>. That
714 POD has the information on what they all mean.
715  
716 State and flag support varies by OS, FreeBSD having the fullest support.
717 The ncps -h output describes the ones usable on the current OS, via
718 L<Proc::ProcessTable::InfoString/proc_infostring_describe>.
719  
720 Switch availability also varies by OS. Switches requiring process table
721 fields the OS does not support are not shown by ncps -h and will error
722 if used.
723  
724 =head1 SWITCHES
725  
726 =head2 -c <regex>
727  
728 Search procs using the matching regex.
729  
730 =head2 --ci
731  
732 Invert the command search.
733  
734 =head2 --cf
735  
736 Show children minor faults.
737  
738 =head2 --cF
739  
740 Show children major faults.
741  
742 =head2 --eg
743  
744 Search for procs with an EGID set.
745  
746 =head2 --egi
747  
748 Invert the EGID set search.
749  
750 =head2 --eu
751  
752 Search for procs with an EUID set.
753  
754 =head2 --eui
755  
756 Invert the EUID set search.
757  
758 =head2 -f
759  
760 Show minor faults.
761  
762 =head2 -F
763  
764 Show major faults.
765  
766 =head2 -J
767  
768 Show jail IDs.
769  
770 =head2 -j <jids>
771  
772 A comma separated list of JIDs to search for.
773  
774 =head2 --ji
775  
776 Invert the JIDs search.
777  
778 =head2 --idle
779  
780 Show the idle kernel process.
781  
782 =head2 --kern
783  
784 Searches for kernel processes.
785  
786 =head2 --kerni
787  
788 Invert the kernel process search.
789  
790 =head2 -m <pctmem>
791  
792 Memory usage percent to search for.
793  
794 =head2 --mi
795  
796 Invert the memory usage search.
797  
798 =head2 -n
799  
800 Show number of threads.
801  
802 =head2 --nc
803  
804 Disable color.
805  
806 =head2 -p <pctcpu>
807  
808 CPU usage percent to search for.
809  
810 =head2 --pi
811  
812 Invert the CPU usage search.
813  
814 =head2 --pid <pids>
815  
816 PIDs to search for.
817  
818 =head2 --pidi
819  
820 Invert the PID search.
821  
822 =head2 -r <RSSs>
823  
824 A comma separated list of RSS values to search for.
825  
826 =head2 --ri
827  
828 Invert the RSS search.
829  
830 =head2 -s
831  
832 Show swapped out procs.
833  
834 =head2 --si
835  
836 Invert the swapped out search.
837  
838 =head2 --self
839  
840 Show the ncps process as well.
841  
842 =head2 --st <states>
843  
844 A comma separated list of states to search for.
845  
846 =head2 --sti
847  
848 Invert the state search.
849  
850 =head2 --stats
851  
852 Print some general stats about CPU usage and memory usage.
853  
854 =head2 -t <times>
855  
856 A comma separated value of time, in seconds, to search for.
857  
858 =head2 --ti
859  
860 Invert the time search.
861  
862 =head2 --tty
863  
864 Show TTYs.
865  
866 =head2 -u <UIDs>
867  
868 A comma separated list of UIDs or usernames.
869  
870 =head2 --ui
871  
872 Invert the UID/username search.
873  
874 =head2 --vs <VSZs>
875  
876 A comma separated list of VSZs to search for.
877  
878 =head2 --vsi
879  
880 Invert the VSZ search.
881  
882 =head2 -w <wchans>
883  
884 A string search for wait channels.
885  
886 =head2 --wi
887  
888 Invert the wait channel search.
889  
890 =head2 -z
891  
892 Show zombie procs.
893  
894 =head1 EQUALITIES
895  
896 For the various switches above that can take numeric values,
897 the equalities below can be used, by directly prepending them to
898 the number.
899  
900 <
901 <=
902 >
903 >=
904 !
905  
906 =head1 ENVIRONMENTAL VARIABLES
907  
908 The environmental variables below may be set to
909 set the default for the flag in question.
910  
911 Unless defined and set to 1, these will
912 default to 0.
913  
914 =head2 NCPS_jid
915  
916 Sets the default for the -J flag.
917  
918 =head2 NCPS_numthr
919  
920 Sets the default for the -n flag.
921  
922 =head2 NCPS_cmajflt
923  
924 Sets the default for the --cF flag.
925  
926 =head2 NCPS_majflt
927  
928 Sets the default for the -F flag.
929  
930 =head2 NCPS_cminflt
931  
932 Sets the default for the --cf flag.
933  
934 =head2 NCPS_minflt
935  
936 Sets the default for the -f flag.
937  
938 =head2 NCPS_tty
939  
940 Sets the default for the --tty flag.
941  
942 =head2 NCPS_self
943  
944 Sets the default for the --self flag.
945  
946 =head2 NCPS_idle
947  
948 Sets the default for the --idle flag.
949  
950 =head2 NO_COLOR
951  
952 Don't colorize the output.
953  
954 =head1 EXAMPLES
955  
956 ncps -J -j 0 --ji
957  
958 Display all processes with a jail ID other than zero.
959  
960 ncps -c firefox --stats
961  
962 Show all firefox processes and the stats for them.
963  
964 ncps -F -f -cF -cf
965  
966 Show all minor/major values for processes.
967  
968 ncps -p '>1'
969  
970 Show all processes using more than 1% of the CPU time.
971  
972 =cut
« blib/lib/Proc/ProcessTable/ncps.pm ↑ Summary