测量 Java 程序内存使用情况的最佳方法? [英] Best way to measure Memory Usage of a Java Program?

查看:55
本文介绍了测量 Java 程序内存使用情况的最佳方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用 VisualVM,但我遇到的问题是我无法保存它生成的图形.我需要报告一些有关其内存使用情况和运行时间的数据,尽管使用 System.nanoTime() 很容易获得运行时间.我也试过 NetBeans 分析器,但这不是我想要的,因为我不是在寻找会减慢它的特定部分或任何东西,所以这会矫枉过正.它最大的问题是它占用了太多的处理时间.也不允许我像 VisualVM 一样轻松捕获/传输数据,至少据我所知.

I'm currently using VisualVM, but the problem I'm having is that I can't save the graphs it generates. I need to report some data about its memory usage and running time, though running time is easy to get with System.nanoTime(). I've also tried the NetBeans profiler but it isn't what I want, since I'm not looking for specific parts that would be slowing it down or anything, so that would be overkill. The biggest problem with it is that it eats up too much processing time. Also doesn't let me capture/transfer the data easily, like VisualVM, at least as far as I can tell.

理想情况下,最好的方法是调用一些方法,因为这样我就可以更轻松地获取信息,但实际上可以让我保存图形的 VisualVM 之类的东西都很好.与 NetBeans 分析器相比,VisualVM 的性能也相当不错,不过我想这是因为我没有使用它的分析器.

Ideally the best way to go about it would be some method call because then I'd be able to get the information a lot more easily, but anything like VisualVM that actually lets me save the graph is fine. Performance with VisualVM is pretty good too, compared to the NetBeans profiler, though I suppose that's because I wasn't using its profiler.

我目前使用的是 Ubuntu,但 Windows 7 很好.不过,我更希望有一个专门从事此工作的程序,因为不这样做的程序获得的信息很可能包括 JVM 和其他最好忽略的信息.

I'm currently using Ubuntu, but Windows 7 is fine. I'd rather have a program that specializes in doing this though, since the information gotten by programs who don't is likely to include the JVM and other things that would be better left out.

嗯,显然,您可以保存当前会话的快照并最大化 VisualVM 中的窗口,这样您就可以使图表更大,拍摄快照并剪切它们......但这有点像黑客.欢迎提出更好的建议.

Well, apparently, you can save snapshots of the current session and maximize the window in VisualVM, so you could make the charts bigger, take a snapshot and cut them... But that's kind of a hack. Better suggestions welcome.

推荐答案

Runtime.getRuntime().freeMemory();

Runtime.getRuntime().totalMemory();

这篇关于测量 Java 程序内存使用情况的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆