File Coverage

blib/lib/DBD/Sys/Plugin/Any/Procs.pm
Criterion Covered Total %
statement 13 41 31.7
branch 0 14 0.0
condition n/a
subroutine 5 8 62.5
pod 3 3 100.0
total 21 66 31.8


line stmt bran cond sub pod time code
1             package DBD::Sys::Plugin::Any::Procs;
2              
3 3     3   4141 use strict;
  3         7  
  3         109  
4 3     3   17 use warnings;
  3         6  
  3         102  
5 3     3   17 use vars qw($VERSION @colNames);
  3         6  
  3         169  
6              
7 3     3   14 use base qw(DBD::Sys::Table);
  3         6  
  3         1652  
8              
9             =pod
10              
11             =head1 NAME
12              
13             DBD::Sys::Plugin::Any::Procs - provides a table containing running processes
14              
15             =head1 SYNOPSIS
16              
17             $processes = $dbh->selectall_hashref("select * from procs", "pid");
18              
19             =head1 ISA
20              
21             DBD::Sys::Plugin::Any::Procs
22             ISA DBD::Sys::Table
23              
24             =cut
25              
26             $VERSION = "0.102";
27             @colNames = (
28             qw(uid gid euid egid pid ppid pgrp sess priority ttynum flags),
29             qw(fulltime ctime virtsize rss wchan fname start),
30             qw(pctcpu state pctmem cmndline ttydev)
31             );
32              
33             my $haveProcProcessTable;
34              
35             my %knownCols;
36              
37             =head1 DESCRIPTION
38              
39             This module provides the table C for any operating system (which is
40             supported by Proc::ProcessTable).
41              
42             =head2 COLUMNS
43              
44             =head3 uid
45              
46             UID of process
47              
48             =head3 gid
49              
50             GID of process
51            
52             =head3 euid
53              
54             Effective UID of process
55              
56             =head3 egid
57              
58             Effective GID of process
59              
60             =head3 pid
61              
62             Process ID
63            
64             =head3 ppid
65              
66             Parent process ID
67            
68             =head3 pgrp
69              
70             Process group
71            
72             =head3 sess
73              
74             Session ID
75              
76             =head3 cpuid
77              
78             CPU ID of processor running on # FIX ME!
79            
80             =head3 priority
81              
82             Priority of process
83            
84             =head3 ttynum
85              
86             TTY number of process
87            
88             =head3 flags
89              
90             Flags of process
91            
92             =head3 fulltime
93              
94             User + system time
95            
96             =head3 ctime
97              
98             Child user + system time
99            
100             =head3 timensec
101              
102             User + system nanoseconds part # FIX ME!
103            
104             =head3 ctimensec
105              
106             Child user + system nanoseconds # FIX ME!
107            
108             =head3 qtime
109              
110             Cumulative cpu time # FIX ME!
111            
112             =head3 virtsize
113              
114             Virtual memory size (bytes)
115            
116             =head3 rss
117              
118             Resident set size (bytes)
119            
120             =head3 wchan
121              
122             Address of current system call
123            
124             =head3 fname
125              
126             File name
127            
128             =head3 start
129              
130             Start time (seconds since the epoch)
131            
132             =head3 pctcpu
133              
134             Percent cpu used since process started
135            
136             =head3 state
137              
138             State of process
139            
140             =head3 pctmem
141              
142             Percent memory
143            
144             =head3 cmndline
145              
146             Full command line of process
147            
148             =head3 ttydev
149              
150             Path of process's tty
151            
152             =head3 clname
153              
154             Scheduling class name #FIX ME!
155              
156             =head1 METHODS
157              
158             =head2 get_col_names
159              
160             Returns the column names of the table as named in L
161              
162             =cut
163              
164 2     2 1 21 sub get_col_names() { @colNames }
165              
166             =head2 get_primary_key
167              
168             Returns 'pid' - which is the process identifier.
169              
170             =cut
171              
172 0     0 1   sub get_primary_key() { return 'pid'; }
173              
174             my %colMap = (
175             fulltime => 'time',
176             virtsize => 'size',
177             );
178              
179             sub _init_knownCols
180             {
181 0     0     my $table = $_[0];
182 0 0         unless ( 0 == scalar(@$table) )
183             {
184 0 0         %knownCols = map {
185 0           defined $colMap{$_} or $colMap{$_} = $_;
186 0           my $fn = $colMap{$_};
187 0           $@ = undef;
188 0           eval { $table->[0]->$fn() };
  0            
189 0 0         $_ => ( $@ ? 0 : 1 )
190             } @colNames;
191             }
192             }
193              
194             =head2 collect_data
195              
196             Retrieves the data from L and put it into fetchable rows.
197              
198             =cut
199              
200             sub collect_data()
201             {
202 0     0 1   my @data;
203              
204 0 0         unless ( defined($haveProcProcessTable) )
205             {
206 0           $haveProcProcessTable = 0;
207 0           eval {
208 0           require Proc::ProcessTable;
209 0           $haveProcProcessTable = 1;
210             };
211             }
212              
213 0 0         if ($haveProcProcessTable)
214             {
215 0           my $pt = Proc::ProcessTable->new();
216 0           my $table = $pt->table();
217              
218 0 0         _init_knownCols($table) if ( 0 == scalar( keys %knownCols ) );
219              
220 0           foreach my $proc ( @{$table} )
  0            
221             {
222 0           my @row;
223              
224             #@row = (@$pt{@colNames}); # calls an error, proc::processtable bugged, handle as seen below.
225 0 0         @row = map { my $fn = $colMap{$_}; $knownCols{$_} ? $proc->$fn() : undef } @colNames;
  0            
  0            
226              
227 0           push( @data, \@row );
228             }
229             }
230              
231 0           return \@data;
232             }
233              
234             =head1 PREREQUISITES
235              
236             The module L is required to provide data for the table.
237              
238             =head1 AUTHOR
239              
240             Jens Rehsack Alexander Breibach
241             CPAN ID: REHSACK
242             rehsack@cpan.org alexander.breibach@googlemail.com
243             http://www.rehsack.de/
244              
245             =head1 COPYRIGHT
246              
247             This program is free software; you can redistribute
248             it and/or modify it under the same terms as Perl itself.
249              
250             The full text of the license can be found in the
251             LICENSE file included with this module.
252              
253             =head1 SUPPORT
254              
255             Free support can be requested via regular CPAN bug-tracking system. There is
256             no guaranteed reaction time or solution time, but it's always tried to give
257             accept or reject a reported ticket within a week. It depends on business load.
258             That doesn't mean that ticket via rt aren't handles as soon as possible,
259             that means that soon depends on how much I have to do.
260              
261             Business and commercial support should be acquired from the authors via
262             preferred freelancer agencies.
263              
264             =cut
265              
266             1;