简体   繁体   English

如何在Solaris上监视Perl中的内存使用情况?

[英]How can I monitor memory usage in Perl on Solaris?

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. 我想在perl中运行程序时监视内存使用情况,这样如果当前程序使用的内存超过阈值,我应用方法A,否则,应用方法B.

Anyone has any idea? 任何人有任何想法?

I found this script from http://www.perlmonks.org/?node_id=235757 : 我从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. 对于Linux,我能够找到CPAN模块Sys::Statistics::Linux ,它能够读取/proc并获取有关当前进程的数据。 On the off-chance that you're running on Solaris, there's Solaris::Procfs . 如果你在Solaris上运行的可能性很小,那就是Solaris::Procfs I couldn't find anything for Windows. 我找不到任何适合Windows的东西。

Update : Since you are on Solaris, you definitely want Solaris::Procfs . 更新 :由于您使用的 Solaris,因此您肯定需要Solaris::Procfs

Use GTop if you want something slightly more portable. 如果你想要更轻便的东西,请使用GTop The mod_perl manual has usage examples . mod_perl手册有使用示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM