File Coverage

blib/lib/Siebel/Srvrmgr/OS/Process.pm
Criterion Covered Total %
statement 33 35 94.2
branch 6 8 75.0
condition 2 3 66.6
subroutine 10 10 100.0
pod 3 3 100.0
total 54 59 91.5


line stmt bran cond sub pod time code
1             package Siebel::Srvrmgr::OS::Process;
2              
3 2     2   1550 use Moose;
  2         345748  
  2         16  
4 2     2   15732 use MooseX::FollowPBP;
  2         21232  
  2         9  
5 2     2   17691 use namespace::autoclean;
  2         8534  
  2         18  
6 2     2   868 use Set::Tiny;
  2         1199  
  2         101  
7 2     2   705 use Scalar::Util::Numeric qw(isint);
  2         750  
  2         136  
8 2     2   11 use Carp qw(confess cluck);
  2         3  
  2         979  
9              
10             =pod
11              
12             =head1 NAME
13              
14             Siebel::Srvrmgr::OS::Process - class to represents a operational system process of Siebel
15              
16             =head2 DESCRIPTION
17              
18             This class holds information regarding a operational system process that is (hopefully) related to a running Siebel Server.
19              
20             =head1 ATTRIBUTES
21              
22             Except for the C<comp_alias> attribute, all attributes are read-only and required during object instantiation.
23              
24             =head2 pid
25              
26             A integer representing the process identification.
27              
28             =cut
29              
30             has pid => ( is => 'ro', isa => 'Int', required => 1 );
31              
32             =head2 fname
33              
34             A string of the program filename
35              
36             =cut
37              
38             has fname => ( is => 'ro', isa => 'Str', required => 1 );
39              
40             =head2 pctcpu
41              
42             A float of the percentage of CPU the process was using.
43              
44             =cut
45              
46             has pctcpu => ( is => 'ro', isa => 'Num', required => 1 );
47              
48             =head2 pctmem
49              
50             A float of the percentage of memory the process was using.
51              
52             =cut
53              
54             has pctmem => ( is => 'ro', isa => 'Num', required => 1 );
55              
56             =head2 rss
57              
58             For Unix-like OS only: the RSS of the process.
59              
60             =cut
61              
62             has rss => ( is => 'ro', isa => 'Int', required => 1 );
63              
64             =head2 vsz
65              
66             For Unix-like OS only: the VSZ used by the process.
67              
68             =cut
69              
70             has vsz => ( is => 'ro', isa => 'Int', required => 1 );
71              
72             =head2 comp_alias
73              
74             A string of the component alias associated with the process.
75              
76             When the process is not directly related to Siebel (for example, a web server that servers SWSE), the value will be automatically defined
77             to "/NA".
78              
79             When the PID is not identified in the source (a class that implements L<Siebel::Srvrmgr::Comps_source>), the default value will be "unknown".
80              
81             =cut
82              
83             has comp_alias => ( is => 'rw', isa => 'Str', required => 0 );
84              
85             sub _build_set {
86              
87 3     3   58 return Set::Tiny->new(
88             'siebmtsh', 'siebmtshmw', 'siebproc', 'siebprocmw',
89             'siebsess', 'siebsh', 'siebshmw'
90             );
91              
92             }
93              
94             =head2 tasks_num
95              
96             A integer representing the number of tasks that Siebel Component has executed in determined moment.
97              
98             This is read-write, non-required attribute with the default value of zero. For processes related to Siebel but not related to Siebel
99             Components, this is the expected value too.
100              
101             =cut
102              
103             has tasks_num => (
104             is => 'ro',
105             isa => 'Int',
106             required => 0,
107             default => 0,
108             reader => 'get_tasks_num',
109             writer => '_set_tasks_num'
110             );
111              
112             =head1 METHODS
113              
114             All attributes have their "getter" methods as defined in the Perl Best Practices book.
115              
116             =head2 set_comp_alias
117              
118             Sets the attribute C<comp_alias>. Expects a string passed as parameter.
119              
120             =head2 BUILD
121              
122             This method is invoked automatically when a object is created.
123              
124             It takes care of setting proper initialization of the C<comp_alias> attribute.
125              
126             =cut
127              
128             sub BUILD {
129              
130 2     2 1 6 my $self = shift;
131 2         7 my $set = $self->_build_set();
132              
133 2 50       167 if ( $set->has( $self->get_fname ) ) {
134              
135 2         131 $self->set_comp_alias('unknown');
136              
137             }
138             else {
139              
140 0         0 $self->set_comp_alias('N/A');
141              
142             }
143              
144             }
145              
146             =head2 is_comp
147              
148             Returns true if the process is from a Siebel component, otherwise false.
149              
150             =cut
151              
152             sub is_comp {
153              
154 3     3 1 6 my $self = shift;
155              
156 3         145 my $comp_alias = $self->get_comp_alias();
157              
158 3 100 66     29 if ( ( $comp_alias eq 'unknown' ) or ( $comp_alias eq 'N/A' ) ) {
159              
160 1         5 return 0;
161              
162             }
163             else {
164              
165 2         11 return 1;
166              
167             }
168              
169             }
170              
171             =head2 set_tasks_num
172              
173             Sets the value of C<tasks_num> related to this process.
174              
175             Expects as parameter a positive integer.
176              
177             The method will validate if the process being updated is related to a Siebel Component. If not, a warning will be raised and
178             no update will be made.
179              
180             =cut
181              
182             sub set_tasks_num {
183              
184 2     2 1 38 my ( $self, $value ) = @_;
185              
186 2 100       33 confess "set_tasks_num requires a positive integer as parameter"
187             unless ( isint($value) );
188              
189 1         3 my $set = $self->_build_set();
190              
191 1 50       53 if ( $set->has( $self->get_fname ) ) {
192              
193 1         52 $self->_set_tasks_num($value);
194              
195             }
196             else {
197              
198 0           cluck 'the process '
199             . $self->get_fname()
200             . ' is not a valid Siebel Server process';
201              
202             }
203              
204             }
205              
206             __PACKAGE__->meta->make_immutable;