简体   繁体   中英

Find current heap size with jmap

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.

The output of jmap -heap <pid> gives me something like this:

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.

Thanks

如果你试图比较像jconsole或jvisualvm这样的东西,主窗口显示'总堆使用',我发现通过添加'使用过的eden空间'和'使用ps老一代空间',我得到了相当于图表显示的内容在前面提到的程序中 - 这就是我现在所倾向的

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM