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