我的 Perl 程序 Stas
我需要你的帮助来实现一些东西来监视 Perl 程序执行期间或结束时的 CPU/MEM 使用情况。
想象一下,一个程序每 N 分钟运行一次,由另一个 Perl 程序启动,后者的执行时间可能从几秒到 1 分钟不等。如何获取执行该程序所产生的 CPU/MEM 使用情况。
一些要求是:
- 监控应尽可能少地干扰 尽可能地执行 程序。
- 监控应至少使用 系统资源
- 尽可能独立于操作系统。应该 在 Linux、Win32、HP-UX、Solaris、 AIX。好的,但让我们首先关注 Linux。
我考虑过一些方法:
- 实现我自己的 Devel::MyProfiler 并使用 -d 运行程序 “选项”。 (例如:$ perl -dMyProfiler program.pl)
- 实现一个获取统计信息的包装器 每 N 秒从 /proc/pid 或“$ ps aux",并获取平均统计数据 在程序结束时
- 执行一个并行程序 每 N 秒生成一次“$ ps aux”
- 使用进程跟踪工具
- ! ???
任何提示都会有帮助!
注意:这个问题也发布在 http://perlmonks.com/?node_id= 909934
Tks,
古尔登
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:
- Implement my own Devel::MyProfiler
and run the program with -d
"option". (ex: $ perl -dMyProfiler
program.pl) - 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 - Implement a parallel program that
makes a "$ ps aux" every N seconds - Using a process trace tool!!
- ???
Any tip will be helpfull!!!
Note: this question was also posted in http://perlmonks.com/?node_id=909934
Tks,
gulden
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
分析器或跟踪工具可能是解决此问题的错误方法,因为它会对您正在运行的程序产生性能(和内存使用)影响。可能不是你想要的。
大多数 UNIX-y 操作系统支持像
getrusage()
这样的系统调用,它可以让您获取当前进程或子进程的资源利用率统计信息。Unix::Getrusage
中有一个 Perl 接口;或者,大多数 UNIX 系统都有一个time
实用程序和/或内置 shell 来收集子进程的统计信息。Windows 对我来说是一个黑匣子,所以我不确定它是否有任何等效的东西。
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 inUnix::Getrusage
; alternatively, most UNIX systems have atime
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.
如果您确实想要分析,请查看
http://open.blogs.nytimes .com/2008/03/05/the-new-york-times-perl-profiler
开销是合理的。内存映射非常有帮助。
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.