add memory percent search
git-svn-id: svn://127.0.0.1/Perl/Proc-ProcessTable-Colorizer/trunk@969 0c1c3402-1be1-de11-8092-0022686faf23
This commit is contained in:
parent
c1c6c5d9f0
commit
6c0cf95eeb
|
@ -38,6 +38,7 @@ sub main::HELP_MESSAGE {
|
|||
"-u <users> A string search for users.\n".
|
||||
"-t <time search> A numeric search for CPU time".
|
||||
"-c <pctcpu search> A numeric search for CPU usage percent\n".
|
||||
"-m <pctmem search> A numeric search for memory usage percent\n".
|
||||
"-w <wait channels> A string search for wait channels.\n".
|
||||
"\n".
|
||||
"\n".
|
||||
|
@ -61,7 +62,7 @@ sub main::VERSION_MESSAGE {
|
|||
|
||||
#gets the options
|
||||
my %opts=();
|
||||
getopts('p:u:zw:st:c:', \%opts);
|
||||
getopts('p:u:zw:st:c:m:', \%opts);
|
||||
|
||||
|
||||
use Proc::ProcessTable::Colorizer;
|
||||
|
@ -87,5 +88,12 @@ if ( defined( $opts{c} ) ){
|
|||
exit $cps->error;
|
||||
}
|
||||
}
|
||||
if ( defined( $opts{m} ) ){
|
||||
$cps->pctcpuSearchSetString( $opts{m} );
|
||||
if ($cps->error){
|
||||
exit $cps->error;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
print $cps->colorize;
|
||||
|
|
|
@ -92,7 +92,7 @@ sub new {
|
|||
zombie_search=>0,
|
||||
swapped_out_search=>0,
|
||||
time_search=>[],
|
||||
pctcpu=>[],
|
||||
pctcpu_search=>[],
|
||||
};
|
||||
bless $self;
|
||||
return $self;
|
||||
|
@ -553,6 +553,76 @@ sub colorize{
|
|||
$pctcpu_search_int++;
|
||||
}
|
||||
}
|
||||
|
||||
#check to see if it needs to search for memory percent
|
||||
my $pctmem_search_array=$self->pctmemSearchGet;
|
||||
if ( defined( $pctmem_search_array->[0] ) ){
|
||||
$required_hits++;
|
||||
my $pctmem_search_int=0;
|
||||
my $matched=0;
|
||||
#search while we have a memory usage defined and it has not already been matched
|
||||
while(
|
||||
defined( $pctmem_search_array->[ $pctmem_search_int ] ) &&
|
||||
( $matched == 0 )
|
||||
){
|
||||
my $checked=0;
|
||||
my $to_match=$pctmem_search_array->[ $pctmem_search_int ];
|
||||
my $pctmem=$proc->{pctmem};
|
||||
#checks for less than or equal
|
||||
if (
|
||||
( $to_match =~ /^\<\=/ ) &&
|
||||
( $checked == 0 )
|
||||
){
|
||||
$checked++;
|
||||
$to_match =~ s/^\<\=//;
|
||||
if ( $pctmem <= $to_match ){
|
||||
$hits++;
|
||||
$matched++;
|
||||
}
|
||||
}
|
||||
|
||||
#checks for less than
|
||||
if (
|
||||
( $to_match =~ /^\</ ) &&
|
||||
( $checked == 0 )
|
||||
){
|
||||
$checked++;
|
||||
$to_match =~ s/^\<//;
|
||||
if ( $pctmem < $to_match ){
|
||||
$hits++;
|
||||
$matched++;
|
||||
}
|
||||
}
|
||||
|
||||
#checks for greater than or equal
|
||||
if (
|
||||
( $to_match =~ /^\>=/ ) &&
|
||||
( $checked == 0 )
|
||||
){
|
||||
$checked++;
|
||||
$to_match =~ s/^\>\=//;
|
||||
if ( $pctmem >= $to_match ){
|
||||
$hits++;
|
||||
$matched++;
|
||||
}
|
||||
}
|
||||
|
||||
#checks for greater than
|
||||
if (
|
||||
( $to_match =~ /^\>/ ) &&
|
||||
( $checked == 0 )
|
||||
){
|
||||
$checked++;
|
||||
$to_match =~ s/^\>//;
|
||||
if ( $pctmem > $to_match ){
|
||||
$hits++;
|
||||
$matched++;
|
||||
}
|
||||
}
|
||||
|
||||
$pctmem_search_int++;
|
||||
}
|
||||
}
|
||||
|
||||
#show zombie procs
|
||||
if ( $self->{zombie_search} ){
|
||||
|
@ -832,7 +902,7 @@ sub fieldsSet{
|
|||
|
||||
}
|
||||
|
||||
=head2 timeSearchGet
|
||||
=head2 pctcpuSearchGet
|
||||
|
||||
Returns the current value for the PCT CPU search.
|
||||
|
||||
|
@ -867,7 +937,7 @@ If the string is undef, all procs will be shown.
|
|||
#search for procs with less than 60% of CPU usage
|
||||
$cps->pctcpuSearchSetString('<60');
|
||||
#shows procs with greater than 60% of CPU usage
|
||||
$cps->waitSearchSetString('>60');
|
||||
$cps->pctcpuSearchSetString('>60');
|
||||
|
||||
=cut
|
||||
|
||||
|
@ -903,6 +973,77 @@ sub pctcpuSearchSetString{
|
|||
return 1;
|
||||
}
|
||||
|
||||
=head2 pctmemSearchGet
|
||||
|
||||
Returns the current value for the PCT MEM search.
|
||||
|
||||
The return is a array ref.
|
||||
|
||||
my $pctmem_search=$cps->pctmemSearchGet;
|
||||
|
||||
=cut
|
||||
|
||||
sub pctmemSearchGet{
|
||||
my $self=$_[0];
|
||||
$self->errorblank;
|
||||
|
||||
return $self->{pctmem_search};
|
||||
}
|
||||
|
||||
=head2 pctmemSearchSetString
|
||||
|
||||
Search for procs based on the memory usage.
|
||||
|
||||
The following equalities are understood.
|
||||
|
||||
<=
|
||||
<
|
||||
>
|
||||
>=
|
||||
|
||||
The string may contain multiple values seperated by a comma. Checking will stop after the first hit.
|
||||
|
||||
If the string is undef, all procs will be shown.
|
||||
|
||||
#search for procs with less than 60% of the memory
|
||||
$cps->pctmemSearchSetString('<60');
|
||||
#shows procs with greater than 60% of the memory
|
||||
$cps->pctmemSearchSetString('>60');
|
||||
|
||||
=cut
|
||||
|
||||
sub pctmemSearchSetString{
|
||||
my $self=$_[0];
|
||||
my $pctmem_search_string=$_[1];
|
||||
$self->errorblank;
|
||||
|
||||
my @pctmem_search_array;
|
||||
if ( ! defined( $pctmem_search_string ) ){
|
||||
$self->{pctmem_search}=\@pctmem_search_array;
|
||||
}else{
|
||||
@pctmem_search_array=split(/\,/, $pctmem_search_string);
|
||||
|
||||
foreach my $item ( @pctmem_search_array ){
|
||||
if (
|
||||
( $item !~ /^\>[0123456789]*$/ ) &&
|
||||
( $item !~ /^\>=[0123456789]*$/ ) &&
|
||||
( $item !~ /^\<[0123456789]*$/ ) &&
|
||||
( $item !~ /^\<=[0123456789]*$/ )
|
||||
){
|
||||
$self->{error}=3;
|
||||
$self->{errorString}='"'.$item.'"" is not a valid value for use in a PCT MEM search';
|
||||
$self->warn;
|
||||
return undef;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$self->{pctmem_search}=\@pctmem_search_array;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
=head2 processColorGet
|
||||
|
||||
my $timeColors=$cps->processColorGet;
|
||||
|
@ -1412,6 +1553,14 @@ The default is as below.
|
|||
|
||||
The time search string contains errors.
|
||||
|
||||
=head2 2 / badPctcpuString
|
||||
|
||||
The PCT CPU search string contains errors.
|
||||
|
||||
=head2 3 / badPctmemString
|
||||
|
||||
The PCT MEM search string contains errors.
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >>
|
||||
|
|
Loading…
Reference in New Issue