in reply to Re: capture cpu and memory usage of JVM using Perl
in thread capture cpu and memory usage of JVM using Perl
With regard to the question at hand, the following code incorporating Proc::ProcessTable may be of use:
use strict; print join("\n", &usage("jvm")), "\n"; # this subroutine takes only one parameter, the process name # to return memory usage information on # # Returns array of two values, raw process memory size and # percentage memory utilisation, in this order. Returns # undefined if these values cannot be determined. sub usage { use Proc::ProcessTable; my @usage; my $proc = Proc::ProcessTable->new; my %fields = map { $_ => 1 } $proc->fields; return undef unless exists $fields{'cmnd'}; foreach (@{$proc->table}) { if ($_->cmnd =~ /$_[0]/) { my @proc; push (@proc, $_->size) if exists $fields{'size'}; push (@proc, $_->pctmem) if exists $fields{'pctmem'}; push @usage, \@proc; } } return @usage; }
perl -e 's&&rob@cowsnet.com.au&&&split/[@.]/&&s&.com.&_&&&print'
|
|---|