使用VM命令行查找执行期间最大分配的堆大小? [英] Find the max allocated heap size during the execution using VM command line?
问题描述
我想知道是否可以使用VM命令行获得分配的堆
的最大大小。
从现在我可以使用 Netbeans Profiler
获得它,但我更喜欢在没有必要启动额外应用程序的情况下获得结果。
我也使用这种方法:
public void printMemUsage(){
double currentMemory =((double )((double)(Runtime.getRuntime()。totalMemory()/ 1024.0))) - ((double)((double)(Runtime.getRuntime()。freeMemory()/ 1024.0)));
System.out.println(当前内存使用量(以千字节为单位:+ currentMemory);
}
我想我可以使用它来获得最大的堆大小,我不知道它是否非常可靠。
我目前使用这些命令行:
-verbose:gc -XX:+ PrintGCDetails -XX:+ PrintGCApplicationConcurrentTime -XX:+ PrintGCApplicationStoppedTime
为了获得良好的信息关于gc活动,年轻一代,老的和永久的。但是我可以在集合发生时告诉当前总堆空间。
那么有没有办法获得使用其他命令行分配的最大堆空间? / p>
您应该使用 MemoryMXBean
,参见 javadoc 的详细信息,因为它解释了如何使用它来获取信息在每个 MemoryPool
(又名一代)上获取通知,并在发生不同事件时收到通知。
I wonder if I can obtain the maximum size of the allocated heap
using VM command line.
From now I'm able to get it using Netbeans Profiler
but I prefer getting result without have to launch an extra application.
I'm also using this method :
public void printMemUsage(){
double currentMemory = ( (double)((double)(Runtime.getRuntime().totalMemory()/1024.0)))- ((double)((double)(Runtime.getRuntime().freeMemory()/1024.0)));
System.out.println("Current memory usage in kilobytes :"+currentMemory);
}
I think I can use this to get the maximum heap size too but I'm not sure if it's very reliable.
I currently use those command lines :
-verbose:gc -XX:+PrintGCDetails -XX:+PrintGCApplicationConcurrentTime -XX:+PrintGCApplicationStoppedTime
In order to get good information about gc activity, young generation, old and permanent. But I just can tell the current total heap space when collections occurs.
So is there a way to get the max heap space that have been alocated using other command lines?
You should use MemoryMXBean
, see the javadoc for details as it explains how to use it to get information on each MemoryPool
(aka generation) and to get notifications when different events happen.
这篇关于使用VM命令行查找执行期间最大分配的堆大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!