监控 RAM 占用的工具
我编写了一个应用程序,需要与执行相同工作的另一个应用程序进行比较。我的是 OCaml,而另一个是 Java。
我想对程序进行两次运行,并在这些执行期间监视 RAM 使用情况。这两个程序都是内存和CPU密集型的,所以我有足够的数据来比较它们,但我不知道如何比较。
我知道对用不同语言编写的应用程序进行基准测试没有多大意义,但是是否有一种工具可以在一段时间内简单地监视程序的 RAM 使用情况,并可能提供数据集或图表作为结果?
编辑:理想的操作系统是 Mac OS X 或只是 unix
I wrote an application that needs to be compared with another one that does the same job.. mine is in OCaml while other one is in Java.
I would like to make two runs on the programs and monitor the RAM usage during the time elapsed by these executions. Both programs are really memory and cpu intensive so I'll have enough data to compare them but I don't know how.
I know that it is not so much meaningful to benchmark applications written in different languages but is there a tool that simply monitors RAM usage of a program during time maybe providing a data set or a graph as the result?
EDIT: ideal operating system is Mac OS X or just unix
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我使用的解决方案与 ygrek 的类似。
它在实现语言方面是相当通用的,只要你使用的是Unix。
一个小问题是,可用于此目的的命令
top
和ps
在 BSD Unix(Mac OS X 派生自)和 Linux 上的工作方式不同。我猜他的命令行是针对Linux的。对于 Mac OS X,我使用:
对于 Linux:
10 是以秒为单位的采样周期。
如果您想从 OCaml 的 GC 获取信息,可以使用 OCaml 的 GC 模块,但这不能直接与 Java 程序的行为进行比较。
编辑补充:在涉及 GC 的地方,内存开销和 CPU 时间开销之间需要进行权衡。 GC 可以更加努力地使死块更快可用,从而降低内存消耗。如果您发现这使得比较两个程序变得困难,您可以调整 OCaml 的 GC,使其使用与 Java GC 相同的权衡。这记录在 GC 模块中。我希望 Java 也允许调整此设置。
I use a solution comparable to ygrek's.
It is quite universal in terms of the implementation language, as long as you are using Unix.
A small issue is that the commands
top
andps
that can both be used for this purpose are both working differently on BSD Unix (that Mac OS X derives from) and Linux. I guess that his commandline is for Linux.For Mac OS X, I used:
and for Linux:
The 10 is the sampling period in seconds.
If you want to get your information from OCaml's GC, you can use OCaml's GC module, but that is not directly comparable to the behavior of a Java program.
Edited to add: where a GC is involved, there is a trade-off between memory overhead and CPU time overhead. The GC can work harder to make dead blocks available sooner and thus keep memory consumption lower. If you find that this makes it hard to compare your two programs, you can adjust OCaml's GC to make it use the same kind of trade-off as the Java GC. This is documented in the GC module. I expect Java allows this setting to be tuned too.
您可以使用 /usr/bin/jvisualvm 监视 Java 使用情况。
Activity Monitor 程序可以为您提供任何常用 Unix 程序的资源使用情况的粗略估计。
You can monitor Java usage with /usr/bin/jvisualvm
The Activity Monitor program can give you a rough estimate of the resource usage of any usual Unix program.
Valgrind 的 Massif 工具可以对本机代码执行此操作。
Valgrind's Massif tool can do this for native code.