File Coverage

blib/lib/Proc/ProcessTable/ncps.pm
Criterion Covered Total %
statement 29 362 8.0
branch 0 124 0.0
condition 0 21 0.0
subroutine 10 16 62.5
pod 6 6 100.0
total 45 529 8.5


line stmt bran cond sub pod time code
1             package Proc::ProcessTable::ncps;
2              
3 1     1   101132 use 5.006;
  1         4  
4 1     1   6 use strict;
  1         2  
  1         21  
5 1     1   4 use warnings;
  1         2  
  1         24  
6 1     1   494 use Proc::ProcessTable::Match;
  1         946  
  1         31  
7 1     1   471 use Proc::ProcessTable;
  1         6459  
  1         62  
8 1     1   1692 use Text::ANSITable;
  1         89191  
  1         43  
9 1     1   986 use Term::ANSIColor;
  1         8709  
  1         87  
10 1     1   500 use Statistics::Basic qw(:all);
  1         9279  
  1         5  
11 1     1   20206 use List::Util qw( min max sum );
  1         3  
  1         93  
12 1     1   533 use Proc::ProcessTable::InfoString;
  1         938  
  1         3573  
13              
14             =head1 NAME
15              
16             Proc::ProcessTable::ncps - New Colorized(optional) PS, a enhanced version of PS with advanced searching capabilities
17              
18             =head1 VERSION
19              
20             Version 0.1.1
21              
22             =cut
23              
24             our $VERSION = '0.1.1';
25              
26              
27             =head1 SYNOPSIS
28              
29             use Proc::ProcessTable::ncps;
30            
31             my $args={
32             cmajor_faults=>0,
33             cminor_faults=>0,
34             major_faults=>1,
35             minor_faults=>0,
36             numthr=>0,
37             tty=>0,
38             jid=>0,
39             stats=>1,
40             match=>{
41             checks=>\@filters,
42             }
43             };
44            
45             my $ncps = Proc::ProcessTable::ncps->new( \%args );
46            
47             print $ncps->run
48              
49             The info column is provided by L<Proc::ProcessTable::InfoString>. That
50             POD has the information on what they all mean.
51              
52             =head1 METHODS
53              
54             =head2 new
55              
56             This initiates the object.
57              
58             =head3 args hash ref
59              
60             =head4 match
61              
62             This is a hash to pash to L<Proc::ProcessTable::Match>. If not specified,
63             this it will not be used all processes will be displayed.
64              
65             =head4 cmajor_faults
66              
67             Boolean for if the children major faults column should be shown.
68              
69             Default: 0
70              
71             =head4 cminor_faults
72              
73             Boolean for if the children minor faults column should be shown.
74              
75             Default: 0
76              
77             =head4 major_faults
78              
79             Boolean for if the major faults column should be shown.
80              
81             Default: 0
82              
83             =head4 minor_faults
84              
85             Boolean for if the minor faults column should be shown.
86              
87             Default: 0
88              
89             =head4 jid
90              
91             Boolean for if the JIDs column should be shown.
92              
93             Default: 0
94              
95             =head4 stats
96              
97             Boolean for if stats for PctCPU, PctMem, VSZ, RSS
98             and time should be shown at the end.
99              
100             Default: 0
101              
102             =head4 tty
103              
104             Boolean for if the TTY column should be shown.
105              
106             Default: 0
107              
108             =cut
109              
110             sub new {
111 0     0 1   my %args;
112 0 0         if (defined($_[1])) {
113 0           %args= %{$_[1]};
  0            
114             }
115              
116              
117 0           my $self = {
118             invert=>0,
119             match=>undef,
120             minor_faults=>0,
121             major_faults=>0,
122             cminor_faults=>0,
123             cmajor_faults=>0,
124             colors=>[
125             'BRIGHT_YELLOW',
126             'BRIGHT_CYAN',
127             'BRIGHT_MAGENTA',
128             'BRIGHT_BLUE'
129             ],
130             timeColors=>[
131             'GREEN',
132             'BRIGHT_GREEN',
133             'RED',
134             'BRIGHT_RED'
135             ],
136             vszColors=>[
137             'GREEN',
138             'YELLOW',
139             'RED',
140             'BRIGHT_BLUE'
141             ],
142             rssColors=>[
143             'BRIGHT_GREEN',
144             'BRIGHT_YELLOW',
145             'BRIGHT_RED',
146             'BRIGHT_BLUE'
147             ],
148             processColor=>'BRIGHT_RED',
149             nextColor=>0,
150             stats=>0,
151             jid=>0,
152             tty=>0,
153             numthr=>0,
154             };
155 0           bless $self;
156              
157 0 0 0       if (
      0        
158             defined( $args{match} ) &&
159             defined( $args{match}{checks} ) &&
160             defined( $args{match}{checks}[0] )
161             ){
162 0           $self->{match}=Proc::ProcessTable::Match->new( $args{match} );
163             }
164              
165 0           my @bool_feed=(
166             'major_faults', 'minor_faults', 'cmajor_faults',
167             'cminor_faults', 'numthr', 'tty', 'jid', 'stats'
168             );
169              
170 0           foreach my $feed ( @bool_feed ){
171 0           $self->{$feed}=$args{$feed};
172             }
173              
174 0           return $self;
175             }
176              
177             =head2 run
178              
179             This runs it.
180              
181             The return value is a string.
182              
183             print $ncps->run
184              
185             =cut
186              
187             sub run{
188 0     0 1   my $self=$_[0];
189              
190 0           my $ppt = Proc::ProcessTable->new( 'cache_ttys' => 1 );
191 0           my $pt = $ppt->table;
192              
193 0           my $procs;
194 0 0         if ( defined( $self->{match} ) ){
195 0           $procs=[];
196 0           foreach my $proc ( @{ $pt } ){
  0            
197 0           eval{
198 0 0         if ( $self->{match}->match( $proc ) ){
199 0           push( @{ $procs }, $proc );
  0            
200             }
201             };
202             }
203             }else{
204 0           $procs=$pt;
205             }
206              
207             # figures out if this systems reports nice or not
208 0           my $have_nice=0;
209 0 0 0       if (
210             defined( $procs->[0] ) &&
211             defined($procs->[0]->{nice} )
212             ){
213 0           $have_nice=1;
214             }
215              
216             # figures out if this systems reports priority or not
217 0           my $have_pri=0;
218 0 0 0       if (
219             defined( $procs->[0] ) &&
220             defined($procs->[0]->{priority} )
221             ){
222 0           $have_pri=1;
223             }
224              
225 0           my $physmem;
226 0 0         if ( $^O =~ /bsd/ ){
227 0           $physmem=`/sbin/sysctl -a hw.physmem`;
228 0           chomp( $physmem );
229 0           $physmem=~s/^.*\: //;
230             }
231              
232 0           my $tb = Text::ANSITable->new;
233 0           $tb->border_style('ASCII::None');
234             # this seems to be a bit broken currently
235             #$tb->color_theme();
236              
237             #
238             # assemble the headers
239             #
240 0           my @headers;
241 0           my $header_int=0;
242 0           my $padding=0;
243 0           push( @headers, 'User' );
244 0           $tb->set_column_style($header_int, pad => 0); $header_int++;
  0            
245 0           push( @headers, 'PID' );
246 0           $tb->set_column_style($header_int, pad => 1); $header_int++;
  0            
247 0           push( @headers, 'CPU' );
248 0           $tb->set_column_style($header_int, pad => 0); $header_int++;
  0            
249 0           push( @headers, 'MEM' );
250 0           $tb->set_column_style($header_int, pad => 1); $header_int++;
  0            
251 0           push( @headers, 'VSZ' );
252 0           $tb->set_column_style($header_int, pad => 0); $header_int++;
  0            
253 0           push( @headers, 'RSS' );
254 0           $tb->set_column_style($header_int, pad => 1); $header_int++;
  0            
255 0           push( @headers, 'Info' );
256             # add nice if needed
257 0 0         if ( $have_nice ){
258 0           push( @headers, 'Nic' );
259 0 0         if (( $header_int % 2 ) != 0){ $padding=1; }else{ $padding=0; }
  0            
  0            
260 0           $tb->set_column_style($header_int, pad => $padding ); $header_int++;
  0            
261             }
262             # add priority if needed
263 0 0         if ( $have_pri ){
264 0           push( @headers, 'Pri' );
265 0 0         if (( $header_int % 2 ) != 0){ $padding=1; }else{ $padding=0; }
  0            
  0            
266 0           $tb->set_column_style($header_int, pad => $padding ); $header_int++;
  0            
267             }
268             # add major faults if needed
269 0 0         if ( $self->{major_faults} ){
270 0           push( @headers, 'MajF' );
271 0 0         if (( $header_int % 2 ) != 0){ $padding=1; }else{ $padding=0; }
  0            
  0            
272 0           $tb->set_column_style($header_int, pad => $padding ); $header_int++;
  0            
273             }
274             # add minor faults if needed
275 0 0         if ( $self->{minor_faults} ){
276 0           push( @headers, 'minF' );
277 0 0         if (( $header_int % 2 ) != 0){ $padding=1; }else{ $padding=0; }
  0            
  0            
278 0           $tb->set_column_style($header_int, pad => $padding ); $header_int++;
  0            
279             }
280             # add children major faults if needed
281 0 0         if ( $self->{cmajor_faults} ){
282 0           push( @headers, 'cMajF' );
283 0 0         if (( $header_int % 2 ) != 0){ $padding=1; }else{ $padding=0; }
  0            
  0            
284 0           $tb->set_column_style($header_int, pad => $padding ); $header_int++;
  0            
285             }
286             # add children minor faults if needed
287 0 0         if ( $self->{cminor_faults} ){
288 0           push( @headers, 'cminF' );
289 0 0         if (( $header_int % 2 ) != 0){ $padding=1; }else{ $padding=0; }
  0            
  0            
290 0           $tb->set_column_style($header_int, pad => $padding ); $header_int++;
  0            
291             }
292             # add children minor faults if needed
293 0 0         if ( $self->{numthr} ){
294 0           push( @headers, 'Thr' );
295 0 0         if (( $header_int % 2 ) != 0){ $padding=1; }else{ $padding=0; }
  0            
  0            
296 0           $tb->set_column_style($header_int, pad => $padding ); $header_int++;
  0            
297             }
298             # add children minor faults if needed
299 0 0         if ( $self->{tty} ){
300 0           push( @headers, 'TTY' );
301 0 0         if (( $header_int % 2 ) != 0){ $padding=1; }else{ $padding=0; }
  0            
  0            
302 0           $tb->set_column_style($header_int, pad => $padding ); $header_int++;
  0            
303             }
304             # add jail ID if needed
305 0 0         if ( $self->{jid} ){
306 0           push( @headers, 'JID' );
307 0 0         if (( $header_int % 2 ) != 0){ $padding=1; }else{ $padding=0; }
  0            
  0            
308 0           $tb->set_column_style($header_int, pad => $padding ); $header_int++;
  0            
309             }
310 0 0         if (( $header_int % 2 ) != 0){ $padding=1; }else{ $padding=0; }
  0            
  0            
311 0           $tb->set_column_style($header_int, pad => $padding ); $header_int++;
  0            
312 0           push( @headers, 'Start' );
313 0 0         if (( $header_int % 2 ) != 0){ $padding=1; }else{ $padding=0; }
  0            
  0            
314 0           $tb->set_column_style($header_int, pad => $padding ); $header_int++;
  0            
315 0           push( @headers, 'Time' );
316 0 0         if (( $header_int % 2 ) != 0){ $padding=1; }else{ $padding=0; }
  0            
  0            
317 0           $tb->set_column_style($header_int, pad => $padding ); $header_int++;
  0            
318 0           push( @headers, 'Command' );
319 0 0         if (( $header_int % 2 ) != 0){ $padding=1; }else{ $padding=0; }
  0            
  0            
320 0           $tb->set_column_style($header_int, pad => $padding, formats=>[[wrap => {ansi=>1, mb=>1}]]);
321              
322 0           $tb->columns( \@headers );
323              
324 0           my @stats_rss;
325             my @stats_vsz;
326 0           my @stats_time;
327 0           my @stats_pctcpu;
328 0           my @stats_pctmem;
329              
330 0           my @td;
331 0           foreach my $proc ( @{ $procs } ) {
  0            
332 0           my @new_line;
333              
334             #
335             # handle username column
336             #
337 0           my $user=getpwuid($proc->{uid});
338 0 0         if ( ! defined( $user ) ) {
339 0           $user=$proc->{uid};
340             }
341 0           $user=color($self->nextColor).$user.color('reset');
342 0           push( @new_line, $user );
343              
344             #
345             # handles the PID
346             #
347 0           push( @new_line, color($self->nextColor).$proc->{pid}.color('reset') );
348              
349             #
350             # handles the %CPU
351             #
352 0           push( @new_line, color($self->nextColor).$proc->{pctcpu}.color('reset') );
353 0 0         if ( $self->{stats} ){ push( @stats_pctcpu, $proc->{pctcpu} ); }
  0            
354              
355             #
356             # handles the %MEM
357             #
358 0 0         if ( $^O =~ /bsd/ ) {
359 0           my $mem=(($proc->{rssize} * 1024 * 4 ) / $physmem) * 100;
360 0           push( @new_line, color($self->nextColor).sprintf('%.2f', $mem).color('reset') );
361 0 0         if ( $self->{stats} ){ push( @stats_pctmem, $mem ); }
  0            
362             } else {
363 0           push( @new_line, color($self->nextColor).sprintf('%.2f', $proc->{pctmem}).color('reset') );
364 0 0         if ( $self->{stats} ){ push( @stats_pctmem, $proc->{pctmem} ); }
  0            
365             }
366              
367             #
368             # handles VSZ
369             #
370 0           push( @new_line, $self->memString( $proc->{size}, 'vsz') );
371 0 0         if ( $self->{stats} ){ push( @stats_vsz, $proc->{size} ); }
  0            
372              
373             #
374             # handles the rss
375             #
376 0           push( @new_line, $self->memString( $proc->{rss}, 'rss') );
377 0 0         if ( $self->{stats} ){ push( @stats_rss, $proc->{rss} ); }
  0            
378              
379             #
380             # handles the info
381             #
382 0           my $is = Proc::ProcessTable::InfoString->new({
383             flags_color=>$self->nextColor,
384             wchan_color=>$self->nextColor,
385             });
386 0           push( @new_line, $is->info( $proc ) );
387              
388             #
389             # handle the nice column
390             #
391 0 0         if ( $have_nice ) {
392 0           push( @new_line, color($self->nextColor).$proc->{nice}.color('reset') );
393             }
394              
395             #
396             # handle the priority column
397             #
398 0 0         if ( $have_pri ) {
399 0           push( @new_line, color($self->nextColor).$proc->{priority}.color('reset') );
400             }
401              
402             #
403             # major faults
404             #
405 0 0         if ( $self->{major_faults} ) {
406 0           push( @new_line, color($self->nextColor).$proc->{majflt}.color('reset') );
407             }
408              
409             #
410             # major faults
411             #
412 0 0         if ( $self->{minor_faults} ) {
413 0           push( @new_line, color($self->nextColor).$proc->{minflt}.color('reset') );
414             }
415              
416             #
417             # children major faults
418             #
419 0 0         if ( $self->{cmajor_faults} ) {
420 0           push( @new_line, color($self->nextColor).$proc->{cmajflt}.color('reset') );
421             }
422              
423             #
424             # children major faults
425             #
426 0 0         if ( $self->{cminor_faults} ) {
427 0           push( @new_line, color($self->nextColor).$proc->{cminflt}.color('reset') );
428             }
429              
430             #
431             # number of threads
432             #
433 0 0         if ( $self->{numthr} ) {
434 0           push( @new_line, color($self->nextColor).$proc->{numthr}.color('reset') );
435             }
436              
437             #
438             # number of threads
439             #
440 0 0         if ( $self->{tty} ) {
441 0           push( @new_line, color($self->nextColor).$proc->{ttydev}.color('reset') );
442             }
443              
444             #
445             # jail ID
446             #
447 0 0         if ( $self->{jid} ) {
448 0           push( @new_line, color($self->nextColor).$proc->{jid}.color('reset') );
449             }
450              
451             #
452             # handles the start column
453             #
454 0           push( @new_line, color($self->nextColor).$self->startString( $proc->{start} ).color('reset') );
455              
456             #
457             # handles the time column
458             #
459 0           push( @new_line, $self->timeString( $proc->{time} ) );
460 0 0         if ( $self->{stats} ){ push( @stats_time, $proc->{time} ); }
  0            
461              
462             #
463             # handle the command
464             #
465 0           my $command=color($self->{processColor});
466 0 0         if ( $proc->{cmndline} =~ /^$/ ) {
467 0           $command=$command.'['.$proc->{fname}.']';
468             } else {
469 0           $command=$command.$proc->{cmndline};
470             }
471 0           push( @new_line, $command.color('reset') );
472              
473 0           push( @td, \@new_line );
474 0           $self->{nextColor}=0;
475             }
476              
477 0           $tb->add_rows( \@td );
478              
479 0           my $stats='';
480 0 0         if ( $self->{stats} ){
481 0           my $stb = Text::ANSITable->new;
482 0           $stb->border_style('Default::none_ascii');
483 0           $stb->color_theme('Default::no_color');
484              
485             #
486             # assemble the headers
487             #
488 0           my @stats_headers;
489 0           push( @stats_headers, ' ' );
490 0           $stb->set_column_style($header_int, pad => 0);
491 0           push( @stats_headers, 'Min' );
492 0           $stb->set_column_style($header_int, pad => 1);
493 0           push( @stats_headers, 'Avg' );
494 0           $stb->set_column_style($header_int, pad => 0);
495 0           push( @stats_headers, 'Med' );
496 0           $stb->set_column_style($header_int, pad => 1);
497 0           push( @stats_headers, 'Max' );
498 0           $stb->set_column_style($header_int, pad => 0);
499 0           push( @stats_headers, 'StdDev' );
500 0           $stb->set_column_style($header_int, pad => 1);
501 0           push( @stats_headers, 'Sum' );
502 0           $stb->set_column_style($header_int, pad => 0);
503              
504 0           $stb->columns( \@stats_headers );
505              
506 0           my @std;
507              
508 0           my $stats_avg=avg(@stats_pctcpu);
509 0           $stats_avg=~s/\,//g;
510 0           my $stats_median=median(@stats_pctcpu);
511 0           $stats_median=~s/\,//g;
512 0           my $stats_stddev=stddev(@stats_pctcpu);
513 0           $stats_stddev=~s/\,//g;
514 0           push( @std, [
515             'CPU%',
516             sprintf('%.2f', min( @stats_pctcpu )),
517             $stats_avg,
518             $stats_median,
519             sprintf('%.2f', max( @stats_pctcpu )),
520             $stats_stddev,
521             sprintf('%.2f', sum( @stats_pctcpu )),
522             ]);
523              
524 0           $stats_avg=avg(@stats_pctmem);
525 0           $stats_avg=~s/\,//g;
526 0           $stats_median=median(@stats_pctmem);
527 0           $stats_median=~s/\,//g;
528 0           $stats_stddev=stddev(@stats_pctmem);
529 0           $stats_stddev=~s/\,//g;
530 0           push( @std, [
531             'Mem%',
532             sprintf('%.2f', min( @stats_pctmem )),
533             $stats_avg,
534             $stats_median,
535             sprintf('%.2f', max( @stats_pctmem )),
536             $stats_stddev,
537             sprintf('%.2f', sum( @stats_pctmem )),
538             ]);
539              
540 0           $stats_avg=avg(@stats_vsz);
541 0           $stats_avg=~s/\,//g;
542 0           $stats_median=median(@stats_vsz);
543 0           $stats_median=~s/\,//g;
544 0           $stats_stddev=stddev(@stats_vsz);
545 0           $stats_stddev=~s/\,//g;
546 0           push( @std, [
547             'VSZ',
548             $self->memString( min( @stats_vsz), 'vsz'),
549             $self->memString( $stats_avg, 'vsz'),
550             $self->memString( $stats_median, 'vsz'),
551             $self->memString( max( @stats_vsz ), 'vsz'),
552             $self->memString( $stats_stddev, 'vsz'),
553             $self->memString( sum( @stats_vsz), 'vsz'),
554             ]);
555              
556 0           $stats_avg=avg(@stats_rss);
557 0           $stats_avg=~s/\,//g;
558 0           $stats_median=median(@stats_rss);
559 0           $stats_median=~s/\,//g;
560 0           $stats_stddev=stddev(@stats_rss);
561 0           $stats_stddev=~s/\,//g;
562 0           push( @std, [
563             'RSS',
564             $self->memString( min( @stats_rss ), 'rss'),
565             $self->memString( $stats_avg, 'rss'),
566             $self->memString( $stats_median, 'rss'),
567             $self->memString( max( @stats_rss ), 'rss'),
568             $self->memString( $stats_stddev, 'rss'),
569             $self->memString( sum( @stats_rss ), 'rss'),
570             ]);
571              
572 0           $stats_avg=avg(@stats_time);
573 0           $stats_avg=~s/\,//g;
574 0           $stats_median=median(@stats_time);
575 0           $stats_median=~s/\,//g;
576 0           $stats_stddev=stddev(@stats_time);
577 0           $stats_stddev=~s/\,//g;
578 0           push( @std, [
579             'Time',
580             $self->timeString( min( @stats_time ) ),
581             $self->timeString( $stats_avg ),
582             $self->timeString( $stats_median ),
583             $self->timeString( max( @stats_time ) ),,
584             $self->timeString( $stats_stddev ),
585             $self->timeString( sum( @stats_time ) ),
586             ]);
587              
588 0           $stb->add_rows( \@std );
589              
590 0           $stats="\n".$stb->draw;
591             }
592              
593 0           return $tb->draw.$stats;
594             }
595              
596             =head2 startString
597              
598             Generates a short time string based on the supplied unix time.
599              
600             =cut
601              
602             sub startString{
603 0     0 1   my $self=$_[0];
604 0           my $startTime=$_[1];
605              
606 0           my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($startTime);
607 0           my ($csec,$cmin,$chour,$cmday,$cmon,$cyear,$cwday,$cyday,$cisdst) = localtime(time);
608              
609             #add the required stuff to make this sane
610 0           $year += 1900;
611 0           $cyear += 1900;
612 0           $mon += 1;
613 0           $cmon += 1;
614              
615             #find the most common one and return it
616 0 0         if ( $year ne $cyear ){
617 0           return $year.sprintf('%02d', $mon).sprintf('%02d', $mday).'-'.sprintf('%02d', $hour).':'.sprintf('%02d', $min);
618             }
619 0 0         if ( $mon ne $cmon ){
620 0           return sprintf('%02d', $mon).sprintf('%02d', $mday).'-'.sprintf('%02d', $hour).':'.sprintf('%02d', $min);
621             }
622 0 0         if ( $mday ne $cmday ){
623 0           return sprintf('%02d', $mday).'-'.sprintf('%02d', $hour).':'.sprintf('%02d', $min);
624             }
625              
626             #just return this for anything less
627 0           return sprintf('%02d', $hour).':'.sprintf('%02d', $min);
628             }
629              
630             =head2 timeString
631              
632             Turns the raw run string into something usable.
633              
634             =cut
635              
636             sub timeString{
637 0     0 1   my $self=$_[0];
638 0           my $time=$_[1];
639              
640 0 0         if ( $^O =~ /^linux$/ ){
641 0           $time=$time/1000000;
642             }
643              
644 0           my $hours=0;
645 0 0         if ( $time >= 3600 ){
646 0           $hours = $time / 3600;
647             }
648 0           my $loSeconds = $time % 3600;
649 0           my $minutes=0;
650 0 0         if ( $time >= 60 ){
651 0           $minutes = $loSeconds / 60;
652             }
653 0           my $seconds = $loSeconds % 60;
654              
655             #nicely format it
656 0           $hours=~s/\..*//;
657 0           $minutes=~s/\..*//;
658 0           $seconds=sprintf('%.f',$seconds);
659              
660             #this will be returned
661 0           my $toReturn='';
662              
663             #process the hours bit
664 0 0         if ( $hours == 0 ){
    0          
665             #don't do anything if time is 0
666             }elsif(
667             $hours >= 10
668             ){
669 0           $toReturn=color($self->{timeColors}->[3]).$hours.':';
670             }else{
671 0           $toReturn=color($self->{timeColors}->[2]).$hours.':';
672             }
673              
674             #process the minutes bit
675 0 0 0       if (
676             ( $hours > 0 ) ||
677             ( $minutes > 0 )
678             ){
679 0           $toReturn=$toReturn.color( $self->{timeColors}->[1] ). $minutes.':';
680             }
681              
682 0           $toReturn=$toReturn.color( $self->{timeColors}->[0] ).$seconds.color('reset');
683              
684 0           return $toReturn;
685             }
686              
687             =head2 memString
688              
689             Turns the raw run string into something usable.
690              
691             =cut
692              
693             sub memString{
694 0     0 1   my $self=$_[0];
695 0           my $mem=$_[1];
696 0           my $type=$_[2];
697              
698 0           my $toReturn='';
699              
700 0 0 0       if ( $mem < '10000' ){
    0 0        
    0          
    0          
701 0           $toReturn=color( $self->{$type.'Colors'}[0] ).$mem;
702             }elsif(
703             ( $mem >= '10000' ) &&
704             ( $mem < '1000000' )
705             ){
706 0           $mem=$mem/1000;
707              
708             $toReturn=color( $self->{$type.'Colors'}[0] ).$mem.
709 0           color( $self->{$type.'Colors'}[3] ).'k';
710             }elsif(
711             ( $mem >= '1000000' ) &&
712             ( $mem < '1000000000' )
713             ){
714 0           $mem=($mem/1000)/1000;
715 0           $mem=sprintf('%.3f', $mem);
716 0           my @mem_split=split(/\./, $mem);
717              
718             $toReturn=color( $self->{$type.'Colors'}[1] ).$mem_split[0].'.'.color( $self->{$type.'Colors'}[0] ).$mem_split[1].
719 0           color( $self->{$type.'Colors'}[3] ).'M';
720             }elsif( $mem >= '1000000000' ){
721 0           $mem=(($mem/1000)/1000)/1000;
722 0           $mem=sprintf('%.3f', $mem);
723 0           my @mem_split=split(/\./, $mem);
724              
725             $toReturn=color( $self->{$type.'Colors'}[2] ).$mem_split[0].'.'.color( $self->{$type.'Colors'}[1] ).$mem_split[1].
726 0           color( $self->{$type.'Colors'}[3] ).'G';
727             }
728              
729 0           return $toReturn.color('reset');
730             }
731              
732              
733             =head2 nextColor
734              
735             Returns the next color.
736              
737             =cut
738              
739             sub nextColor{
740 0     0 1   my $self=$_[0];
741              
742 0           my $color;
743              
744 0 0         if ( defined( $self->{colors}[ $self->{nextColor} ] ) ) {
745 0           $color=$self->{colors}[ $self->{nextColor} ];
746 0           $self->{nextColor}++;
747             } else {
748 0           $self->{nextColor}=0;
749 0           $color=$self->{colors}[ $self->{nextColor} ];
750 0           $self->{nextColor}++;
751             }
752              
753 0           return $color;
754             }
755              
756              
757             =head1 AUTHOR
758              
759             Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >>
760              
761             =head1 BUGS
762              
763             Please report any bugs or feature requests to C<bug-proc-processtable-ncps at rt.cpan.org>, or through
764             the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Proc-ProcessTable-ncps>. I will be notified, and then you'll
765             automatically be notified of progress on your bug as I make changes.
766              
767              
768              
769              
770             =head1 SUPPORT
771              
772             You can find documentation for this module with the perldoc command.
773              
774             perldoc Proc::ProcessTable::ncps
775              
776              
777             You can also look for information at:
778              
779             =over 4
780              
781             =item * RT: CPAN's request tracker (report bugs here)
782              
783             L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Proc-ProcessTable-ncps>
784              
785             =item * AnnoCPAN: Annotated CPAN documentation
786              
787             L<http://annocpan.org/dist/Proc-ProcessTable-ncps>
788              
789             =item * CPAN Ratings
790              
791             L<https://cpanratings.perl.org/d/Proc-ProcessTable-ncps>
792              
793             =item * Search CPAN
794              
795             L<https://metacpan.org/release/Proc-ProcessTable-ncps>
796              
797             =item * Repository
798              
799             L<https://github.com/VVelox/Proc-ProcessTable-ncps>
800              
801             =back
802              
803              
804             =head1 ACKNOWLEDGEMENTS
805              
806              
807             =head1 LICENSE AND COPYRIGHT
808              
809             This software is Copyright (c) 2019 by Zane C. Bowers-Hadley.
810              
811             This is free software, licensed under:
812              
813             The Artistic License 2.0 (GPL Compatible)
814              
815              
816             =cut
817              
818             1; # End of Proc::ProcessTable::ncps