使用VM命令行查找执行期间最大分配的堆大小?

发布于 2025-01-02 07:03:49 字数 728 浏览 1 评论 0原文

我想知道是否可以使用 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("Current memory usage in kilobytes :"+currentMemory);
}

我想我也可以使用它来获取最大堆大小,但我不确定它是否非常可靠。

我目前使用这些命令行:

-verbose:gc -XX:+PrintGCDetails -XX:+PrintGCApplicationConcurrentTime -XX:+PrintGCApplicationStoppedTime

为了获得有关 gc 活动、年轻代、老一代和永久代的良好信息。但我只能在收集发生时知道当前的总堆空间。

那么有没有办法获取使用其他命令行分配的最大堆空间?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱,才寂寞 2025-01-09 07:03:49

您应该使用 MemoryMXBean,请参阅 javadoc 了解详细信息,因为它解释了如何使用它来获取有关每个 MemoryPool(也称为生成)的信息,并在发生不同事件时获取通知。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文