开发者

My Perl program Stas

开发者 https://www.devze.com 2023-03-13 21:27 出处:网络
I need your help to implement something to monitor CPU/MEM usage during or at the end of the execution of a perl program.

I need your help to implement something to monitor CPU/MEM usage during or at the end of the execution of a perl program.

Imagine that a program that runs every N minutes which is launched by another Perl program, the execution of the latter can vary 开发者_运维百科from a few seconds to 1 minute. How can I get CPU/MEM usage that result from executing this program.

some of the requirements are:

  • monitoring should interfere as little as possible with the execution of the program.
  • monitoring should use a minimum of system resources
  • OS independent as possible. should run in Linux, Win32, HP-UX, Solaris, AIX. Ok but lets focus first in Linux.

I've thought in some approaches:

  1. Implement my own Devel::MyProfiler and run the program with -d "option". (ex: $ perl -dMyProfiler program.pl)
  2. Implement a wrapper that get stats every N seconds from /proc/pid or "$ ps aux", and gets the average stats at the end of the program
  3. Implement a parallel program that makes a "$ ps aux" every N seconds
  4. Using a process trace tool!!
  5. ???

Any tip will be helpfull!!!

Note: this question was also posted in http://perlmonks.com/?node_id=909934

Tks,

gulden


A profiler or trace tool is probably the wrong approach to this problem, as it'll have a performance (and memory usage) impact on the program you're running. Probably not what you want.

Most UNIX-y operating systems support system calls like getrusage(), which will let you get resource utilization stats for the current process or for child processes. There's a Perl interface for that in Unix::Getrusage; alternatively, most UNIX systems have a time utility and/or shell builtin that'll gather statistics on a child process.

Windows is a black box to me, so I'm not sure if it has any equivalent.


If you do want profiling look at http://open.blogs.nytimes.com/2008/03/05/the-new-york-times-perl-profiler

The overhead is reasonable. The memory map is very helpful.

0

精彩评论

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

关注公众号