Match/Swapped.pm

filter: Statementstmt 90.7% 39 / 43 Branchbran 71.4% 10 / 14 Conditioncond 66.6% 6 / 9 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 5 / 5 Podpod 100% 2 / 2 totaltotal 81.8% 63 / 77 CC 11 SCAR 22.2
CC
11
Cov
83%
match
12.1
BEGIN
1.0
BEGIN
1.0
CRAP 9.2
« Match.pm ↑ Summary Match/Command.pm »
1 package Proc::ProcessTable::Match::Swapped;
2  
3 2 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 =head1 NAME
8  
9 Proc::ProcessTable::Match::Swapped - Check if the process is swapped out.
10  
11 =head1 VERSION
12  
13 Version 0.1.0
14  
15 =cut
16  
17 2 our $VERSION = '0.1.0';
18  
19  
20 =head1 SYNOPSIS
21  
22 use Proc::ProcessTable::Match::Swapped;
23
24 my $checker=Proc::ProcessTable::Match::Swapped->new;
25
26 if ( $checker->match( $proc ) ){
27 print "It matches.\n";
28 }
29  
30 =head1 METHODS
31  
32 =head2 new
33  
34 This intiates the object.
35  
36 my $checker=Proc::ProcessTable::Match::Swapped->new;
37  
38 =cut
39  
40 1 ▶sub new{
Subroutine new: called CC=1 SCAR=0.0
Pod documented
41 1 my $class=$_[0];
42 1 my $self = {
43 };
44 1 bless $self, $class;
45  
46 1 return $self;
47 }
48  
49 =head2 match
50  
51 Checks if a single Proc::ProcessTable::Process object matches.
52  
53 One argument is taken and that is a Proc::ProcessTable::Process object.
54  
55 The returned value is a boolean.
56  
57 if ( $checker->match( $proc ) ){
58 print "The process matches.\n";
59 }
60  
61 =cut
62  
63 4 ▶sub match{
Subroutine match: called CC=11 SCAR=25.0
Pod documented
64 4 my $self=$_[0];
65 4 my $object=$_[1];
66  
67 4 ▶ if ( !defined( $object ) ){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $object) 0 4 4
68 0 return 0;
69 }
70  
71 4 ▶ if ( ref( $object ) ne 'Proc::ProcessTable::Process' ){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $object ne "Proc::ProcessTable::Process") 0 4 4
72 0 return 0;
73 }
74  
75 4 my $proc_state;
76 4 eval{
77 4 $proc_state=$object->state;
78 };
79  
80 # don't bother proceeding, the object won't match ever
81 # as it does not have a state
82 4 ▶ if ( ! defined( $proc_state ) ){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $proc_state) 0 4 4
83 0 return 0;
84 }
85  
86 # will have a 0 rss, but is not swapped
87 # "zombie" is used by the BSDs and "defunct" by Linux
88 4 ▶ if ( $proc_state =~ /^(zombie|defunct)$/ ){
Branch: 1 branch
BranchTrueFalseTotal
if ($proc_state =~ /^(zombie|defunct)$/) 1 3 4
89 1 return 0;
90 }
91  
92 # kernel procs always have a rss of 0, but are not swapped out
93 3 my $proc_uid;
94 3 eval{
95 3 $proc_uid=$object->uid;
96 };
97 3 my $proc_cmndline;
98 3 eval{
99 3 $proc_cmndline=$object->cmndline;
100 };
101 3 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (defined $proc_uid and $proc_uid == 0 and defined $proc_cmndline and $proc_cmndline =~ /^$/) 1 2 3
Condition66%6/9
defined $proc_uid and $proc_uid == 0 and defined $proc_cmndline and $proc_cmndline =~ /^$/
!ll&&!rl&&r
201
defined $proc_uid and $proc_uid == 0 and defined $proc_cmndline
!ll&&!rl&&r
201
defined $proc_uid and $proc_uid == 0
!ll&&!rl&&r
021
MC/DC25%1/4
defined $proc_uid and $proc_uid == 0 and defined $proc_cmndline and $proc_cmndline =~ /^$/
defined $proc_uid $proc_uid == 0 defined $proc_cmndline $proc_cmndline =~ /^$/
Truth table40%2/5
A and B and C and D
A= defined $proc_uidB= $proc_uid == 0C= defined $proc_cmndlineD= $proc_cmndline =~ /^$/
ABCDresult
0XXX0
10XX0
110X0
11100
11111
102 ( defined( $proc_uid ) ) &&
103 ( $proc_uid == 0 ) &&
104 ( defined( $proc_cmndline ) ) &&
105 ( $proc_cmndline =~ /^$/ )
106 ){
107 1 return 0;
108 }
109  
110 2 my $proc_rss;
111 2 eval{
112 2 $proc_rss=$object->rss;
113 };
114  
115 # don't bother proceeding, the object won't match ever
116 # as it does not have a rss
117 2 ▶ if ( ! defined( $proc_rss ) ){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $proc_rss) 0 2 2
118 0 return 0;
119 }
120  
121 # if the rss 0, it is swapped out
122 2 ▶ if ( $proc_rss == 0 ){
Branch: 1 branch
BranchTrueFalseTotal
if ($proc_rss == 0) 1 1 2
123 1 return 1;
124 }
125  
126 1 return 0;
127 }
128  
129 =head1 AUTHOR
130  
131 Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >>
132  
133 =head1 BUGS
134  
135 Please report any bugs or feature requests to C<bug-Proc-ProcessTable-Match at rt.cpan.org>, or through
136 the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Proc-ProcessTable-Match>. I will be notified, and then you'll
137 automatically be notified of progress on your bug as I make changes.
138  
139  
140  
141  
142 =head1 SUPPORT
143  
144 You can find documentation for this module with the perldoc command.
145  
146 perldoc Proc::ProcessTable::Match
147  
148  
149 You can also look for information at:
150  
151 =over 4
152  
153 =item * RT: CPAN's request tracker (report bugs here)
154  
155 L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Proc-ProcessTable-Match>
156  
157 =item * Search CPAN
158  
159 L<https://metacpan.org/release/Proc-ProcessTable-Match>
160  
161 =back
162  
163  
164 =head1 ACKNOWLEDGEMENTS
165  
166  
167 =head1 LICENSE AND COPYRIGHT
168  
169 Copyright 2019 Zane C. Bowers-Hadley.
170  
171 This program is free software; you can redistribute it and/or modify it
172 under the terms of the the Artistic License (2.0). You may obtain a
173 copy of the full license at:
174  
175 L<http://www.perlfoundation.org/artistic_license_2_0>
176  
177 Any use, modification, and distribution of the Standard or Modified
178 Versions is governed by this Artistic License. By using, modifying or
179 distributing the Package, you accept this license. Do not use, modify,
180 or distribute the Package, if you do not accept this license.
181  
182 If your Modified Version has been derived from a Modified Version made
183 by someone other than you, you are nevertheless required to ensure that
184 your Modified Version complies with the requirements of this license.
185  
186 This license does not grant you the right to use any trademark, service
187 mark, tradename, or logo of the Copyright Holder.
188  
189 This license includes the non-exclusive, worldwide, free-of-charge
190 patent license to make, have made, use, offer to sell, sell, import and
191 otherwise transfer the Package with respect to any patent claims
192 licensable by the Copyright Holder that are necessarily infringed by the
193 Package. If you institute patent litigation (including a cross-claim or
194 counterclaim) against any party alleging that the Package constitutes
195 direct or contributory patent infringement, then this Artistic License
196 to you shall terminate on the date that such litigation is filed.
197  
198 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
199 AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
200 THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
201 PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
202 YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
203 CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
204 CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
205 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
206  
207  
208 =cut
209  
210 2 1; # End of Proc::ProcessTable::Match
« Match.pm ↑ Summary Match/Command.pm »