开发者

How can I monitor memory usage in Perl on Solaris?

开发者 https://www.devze.com 2023-01-11 13:56 出处:网络
I want to monitor memory usage when running a program in perl, so that if the 开发者_开发百科memory used by the current program is more than a threshold, I apply approach A, otherwise, apply approach

I want to monitor memory usage when running a program in perl, so that if the 开发者_开发百科memory used by the current program is more than a threshold, I apply approach A, otherwise, apply approach B.

Anyone has any idea?


I found this script from http://www.perlmonks.org/?node_id=235757:

#!/usr/bin/perl  

use Proc::ProcessTable;  

sub memory_usage {  
  my $t = new Proc::ProcessTable;  
  foreach my $got ( @{$t->table} ) {  
    next if not $got->pid eq $$;  
    return $got->size;  
  }  
}  


print 'memory: '. memory_usage()/1024/1024 ."\n";  


This is going to be highly OS specific. For Linux, I was able to find the CPAN module Sys::Statistics::Linux, which is able to read /proc and get you data about your current process. On the off-chance that you're running on Solaris, there's Solaris::Procfs. I couldn't find anything for Windows.

Update: Since you are on Solaris, you definitely want Solaris::Procfs.


Use GTop if you want something slightly more portable. The mod_perl manual has usage examples.

0

精彩评论

暂无评论...
验证码 换一张
取 消