File Coverage

blib/lib/Proc/ProcessTable/ncps.pm
Criterion Covered Total %
statement 29 363 7.9
branch 0 124 0.0
condition 0 21 0.0
subroutine 10 16 62.5
pod 6 6 100.0
total 45 530 8.4


line stmt bran cond sub pod time code
1             package Proc::ProcessTable::ncps;
2              
3 1     1   102819 use 5.006;
  1         5  
4 1     1   6 use strict;
  1         2  
  1         21  
5 1     1   5 use warnings;
  1         2  
  1         24  
6 1     1   595 use Proc::ProcessTable::Match;
  1         842  
  1         31  
7 1     1   515 use Proc::ProcessTable;
  1         6762  
  1         67  
8 1     1   1552 use Text::ANSITable;
  1         91788  
  1         39  
9 1     1   740 use Term::ANSIColor;
  1         8641  
  1         87  
10 1     1   507 use Statistics::Basic qw(:all);
  1         10286  
  1         6  
11 1     1   20848 use List::Util qw( min max sum );
  1         3  
  1         94  
12 1     1   607 use Proc::ProcessTable::InfoString;
  1         958  
  1         3532  
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.2
21              
22             =cut
23              
24             our $VERSION = '0.1.2';
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 0           $tb->color_theme('NoColor');
235              
236             #
237             # assemble the headers
238             #
239 0           my @headers;
240 0           my $header_int=0;
241 0           my $padding=0;
242 0           push( @headers, 'User' );
243 0           $tb->set_column_style($header_int, pad => 0); $header_int++;
  0            
244 0           push( @headers, 'PID' );
245 0           $tb->set_column_style($header_int, pad => 1); $header_int++;
  0            
246 0           push( @headers, 'CPU' );
247 0           $tb->set_column_style($header_int, pad => 0); $header_int++;
  0            
248 0           push( @headers, 'MEM' );
249 0           $tb->set_column_style($header_int, pad => 1); $header_int++;
  0            
250 0           push( @headers, 'VSZ' );
251 0           $tb->set_column_style($header_int, pad => 0); $header_int++;
  0            
252 0           push( @headers, 'RSS' );
253 0           $tb->set_column_style($header_int, pad => 1); $header_int++;
  0            
254 0           push( @headers, 'Info' );
255             # add nice if needed
256 0 0         if ( $have_nice ){
257 0           push( @headers, 'Nic' );
258 0 0         if (( $header_int % 2 ) != 0){ $padding=1; }else{ $padding=0; }
  0            
  0            
259 0           $tb->set_column_style($header_int, pad => $padding ); $header_int++;
  0            
260             }
261             # add priority if needed
262 0 0         if ( $have_pri ){
263 0           push( @headers, 'Pri' );
264 0 0         if (( $header_int % 2 ) != 0){ $padding=1; }else{ $padding=0; }
  0            
  0            
265 0           $tb->set_column_style($header_int, pad => $padding ); $header_int++;
  0            
266             }
267             # add major faults if needed
268 0 0         if ( $self->{major_faults} ){
269 0           push( @headers, 'MajF' );
270 0 0         if (( $header_int % 2 ) != 0){ $padding=1; }else{ $padding=0; }
  0            
  0            
271 0           $tb->set_column_style($header_int, pad => $padding ); $header_int++;
  0            
272             }
273             # add minor faults if needed
274 0 0         if ( $self->{minor_faults} ){
275 0           push( @headers, 'minF' );
276 0 0         if (( $header_int % 2 ) != 0){ $padding=1; }else{ $padding=0; }
  0            
  0            
277 0           $tb->set_column_style($header_int, pad => $padding ); $header_int++;
  0            
278             }
279             # add children major faults if needed
280 0 0         if ( $self->{cmajor_faults} ){
281 0           push( @headers, 'cMajF' );
282 0 0         if (( $header_int % 2 ) != 0){ $padding=1; }else{ $padding=0; }
  0            
  0            
283 0           $tb->set_column_style($header_int, pad => $padding ); $header_int++;
  0            
284             }
285             # add children minor faults if needed
286 0 0         if ( $self->{cminor_faults} ){
287 0           push( @headers, 'cminF' );
288 0 0         if (( $header_int % 2 ) != 0){ $padding=1; }else{ $padding=0; }
  0            
  0            
289 0           $tb->set_column_style($header_int, pad => $padding ); $header_int++;
  0            
290             }
291             # add children minor faults if needed
292 0 0         if ( $self->{numthr} ){
293 0           push( @headers, 'Thr' );
294 0 0         if (( $header_int % 2 ) != 0){ $padding=1; }else{ $padding=0; }
  0            
  0            
295 0           $tb->set_column_style($header_int, pad => $padding ); $header_int++;
  0            
296             }
297             # add children minor faults if needed
298 0 0         if ( $self->{tty} ){
299 0           push( @headers, 'TTY' );
300 0 0         if (( $header_int % 2 ) != 0){ $padding=1; }else{ $padding=0; }
  0            
  0            
301 0           $tb->set_column_style($header_int, pad => $padding ); $header_int++;
  0            
302             }
303             # add jail ID if needed
304 0 0         if ( $self->{jid} ){
305 0           push( @headers, 'JID' );
306 0 0         if (( $header_int % 2 ) != 0){ $padding=1; }else{ $padding=0; }
  0            
  0            
307 0           $tb->set_column_style($header_int, pad => $padding ); $header_int++;
  0            
308             }
309 0 0         if (( $header_int % 2 ) != 0){ $padding=1; }else{ $padding=0; }
  0            
  0            
310 0           $tb->set_column_style($header_int, pad => $padding ); $header_int++;
  0            
311 0           push( @headers, 'Start' );
312 0 0         if (( $header_int % 2 ) != 0){ $padding=1; }else{ $padding=0; }
  0            
  0            
313 0           $tb->set_column_style($header_int, pad => $padding ); $header_int++;
  0            
314 0           push( @headers, 'Time' );
315 0 0         if (( $header_int % 2 ) != 0){ $padding=1; }else{ $padding=0; }
  0            
  0            
316 0           $tb->set_column_style($header_int, pad => $padding ); $header_int++;
  0            
317 0           push( @headers, 'Command' );
318 0 0         if (( $header_int % 2 ) != 0){ $padding=1; }else{ $padding=0; }
  0            
  0            
319 0           $tb->set_column_style($header_int, pad => $padding, formats=>[[wrap => {ansi=>1, mb=>1}]]);
320              
321 0           $tb->columns( \@headers );
322              
323 0           my @stats_rss;
324             my @stats_vsz;
325 0           my @stats_time;
326 0           my @stats_pctcpu;
327 0           my @stats_pctmem;
328              
329 0           my @td;
330 0           foreach my $proc ( @{ $procs } ) {
  0            
331 0           my @new_line;
332              
333             #
334             # handle username column
335             #
336 0           my $user=getpwuid($proc->{uid});
337 0 0         if ( ! defined( $user ) ) {
338 0           $user=$proc->{uid};
339             }
340 0           $user=color($self->nextColor).$user.color('reset');
341 0           push( @new_line, $user );
342              
343             #
344             # handles the PID
345             #
346 0           push( @new_line, color($self->nextColor).$proc->{pid}.color('reset') );
347              
348             #
349             # handles the %CPU
350             #
351 0           push( @new_line, color($self->nextColor).$proc->{pctcpu}.color('reset') );
352 0 0         if ( $self->{stats} ){ push( @stats_pctcpu, $proc->{pctcpu} ); }
  0            
353              
354             #
355             # handles the %MEM
356             #
357 0 0         if ( $^O =~ /bsd/ ) {
358 0           my $mem=(($proc->{rssize} * 1024 * 4 ) / $physmem) * 100;
359 0           push( @new_line, color($self->nextColor).sprintf('%.2f', $mem).color('reset') );
360 0 0         if ( $self->{stats} ){ push( @stats_pctmem, $mem ); }
  0            
361             } else {
362 0           push( @new_line, color($self->nextColor).sprintf('%.2f', $proc->{pctmem}).color('reset') );
363 0 0         if ( $self->{stats} ){ push( @stats_pctmem, $proc->{pctmem} ); }
  0            
364             }
365              
366             #
367             # handles VSZ
368             #
369 0           push( @new_line, $self->memString( $proc->{size}, 'vsz') );
370 0 0         if ( $self->{stats} ){ push( @stats_vsz, $proc->{size} ); }
  0            
371              
372             #
373             # handles the rss
374             #
375 0           push( @new_line, $self->memString( $proc->{rss}, 'rss') );
376 0 0         if ( $self->{stats} ){ push( @stats_rss, $proc->{rss} ); }
  0            
377              
378             #
379             # handles the info
380             #
381 0           my $is = Proc::ProcessTable::InfoString->new({
382             flags_color=>$self->nextColor,
383             wchan_color=>$self->nextColor,
384             });
385 0           push( @new_line, $is->info( $proc ) );
386              
387             #
388             # handle the nice column
389             #
390 0 0         if ( $have_nice ) {
391 0           push( @new_line, color($self->nextColor).$proc->{nice}.color('reset') );
392             }
393              
394             #
395             # handle the priority column
396             #
397 0 0         if ( $have_pri ) {
398 0           push( @new_line, color($self->nextColor).$proc->{priority}.color('reset') );
399             }
400              
401             #
402             # major faults
403             #
404 0 0         if ( $self->{major_faults} ) {
405 0           push( @new_line, color($self->nextColor).$proc->{majflt}.color('reset') );
406             }
407              
408             #
409             # major faults
410             #
411 0 0         if ( $self->{minor_faults} ) {
412 0           push( @new_line, color($self->nextColor).$proc->{minflt}.color('reset') );
413             }
414              
415             #
416             # children major faults
417             #
418 0 0         if ( $self->{cmajor_faults} ) {
419 0           push( @new_line, color($self->nextColor).$proc->{cmajflt}.color('reset') );
420             }
421              
422             #
423             # children major faults
424             #
425 0 0         if ( $self->{cminor_faults} ) {
426 0           push( @new_line, color($self->nextColor).$proc->{cminflt}.color('reset') );
427             }
428              
429             #
430             # number of threads
431             #
432 0 0         if ( $self->{numthr} ) {
433 0           push( @new_line, color($self->nextColor).$proc->{numthr}.color('reset') );
434             }
435              
436             #
437             # number of threads
438             #
439 0 0         if ( $self->{tty} ) {
440 0           push( @new_line, color($self->nextColor).$proc->{ttydev}.color('reset') );
441             }
442              
443             #
444             # jail ID
445             #
446 0 0         if ( $self->{jid} ) {
447 0           push( @new_line, color($self->nextColor).$proc->{jid}.color('reset') );
448             }
449              
450             #
451             # handles the start column
452             #
453 0           push( @new_line, color($self->nextColor).$self->startString( $proc->{start} ).color('reset') );
454              
455             #
456             # handles the time column
457             #
458 0           push( @new_line, $self->timeString( $proc->{time} ) );
459 0 0         if ( $self->{stats} ){ push( @stats_time, $proc->{time} ); }
  0            
460              
461             #
462             # handle the command
463             #
464 0           my $command=color($self->{processColor});
465 0 0         if ( $proc->{cmndline} =~ /^$/ ) {
466 0           $command=$command.'['.$proc->{fname}.']';
467             } else {
468 0           $command=$command.$proc->{cmndline};
469             }
470 0           push( @new_line, $command.color('reset') );
471              
472 0           push( @td, \@new_line );
473 0           $self->{nextColor}=0;
474             }
475              
476 0           $tb->add_rows( \@td );
477              
478 0           my $stats='';
479 0 0         if ( $self->{stats} ){
480 0           my $stb = Text::ANSITable->new;
481             #$stb->border_style('Default::none_ascii');
482 0           $stb->border_style('ASCII::None');
483 0           $stb->color_theme('NoColor');
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