Java 使用 jmap 查找当前堆大小
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2324552/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Find current heap size with jmap
提问by fmoga
I would like to find out what is the total heap size that is in use at a certain time by a Java process and I have to use jmap.
我想知道 Java 进程在某个时间使用的总堆大小是多少,我必须使用 jmap。
The output of jmap -heap <pid>
gives me something like this:
的输出jmap -heap <pid>
给了我这样的东西:
Attaching to process ID 2899, please wait... Debugger attached successfully. Server compiler detected. JVM version is 14.2-b01 using thread-local object allocation. Parallel GC with 2 thread(s) Heap Configuration: MinHeapFreeRatio = 40 MaxHeapFreeRatio = 70 MaxHeapSize = 1258291200 (1200.0MB) NewSize = 1048576 (1.0MB) MaxNewSize = 4294901760 (4095.9375MB) OldSize = 4194304 (4.0MB) NewRatio = 8 SurvivorRatio = 8 PermSize = 16777216 (16.0MB) MaxPermSize = 67108864 (64.0MB) Heap Usage: PS Young Generation Eden Space: capacity = 119013376 (113.5MB) used = 117277608 (111.84464263916016MB) free = 1735768 (1.6553573608398438MB) 98.54153536489882% used From Space: capacity = 131072 (0.125MB) used = 81920 (0.078125MB) free = 49152 (0.046875MB) 62.5% used To Space: capacity = 131072 (0.125MB) used = 0 (0.0MB) free = 131072 (0.125MB) 0.0% used PS Old Generation capacity = 954466304 (910.25MB) used = 80791792 (77.04905700683594MB) free = 873674512 (833.2009429931641MB) 8.46460390077846% used PS Perm Generation capacity = 57671680 (55.0MB) used = 41699008 (39.76727294921875MB) free = 15972672 (15.23272705078125MB) 72.30413263494319% used
Can I use a formula for these values to find out total memory used?
我可以使用这些值的公式来找出使用的总内存吗?
Other suggestions on how can I find this out on Linux are welcome but jmap is preffered over them.
欢迎其他有关如何在 Linux 上找到此问题的建议,但 jmap 优先于它们。
Thanks
谢谢
回答by skaffman
The entries under Heap Usage:
are listing the various partitioned memory pools in the JVM, along with their max size, used and free space. You could just add up the various used:
values, that should give you a sensible value for the total memory usage, although there may be some JVM overhead that's not accounted for in the listed pools.
下面的条目Heap Usage:
列出了 JVM 中的各种分区内存池,以及它们的最大大小、已用空间和可用空间。您可以将各种used:
值相加,这应该为您提供总内存使用量的合理值,尽管列出的池中可能没有考虑一些 JVM 开销。
回答by eyberg
if you are trying to compare to something like jconsole or jvisualvm with the main window displaying 'total heap usage' I found out that by adding 'used eden space' and 'used ps old generation space' I got the equivalent of what that graph shows in the aforementioned programs -- that's what I tend to go on now
如果您尝试与 jconsole 或 jvisualvm 之类的东西进行比较,并且主窗口显示“总堆使用情况”,我发现通过添加“已使用的伊甸园空间”和“已使用的 ps 旧代空间”,我得到了该图显示的内容在上述程序中——这就是我现在倾向于继续的