jmap 获取内存dump的几种方式
java获取内存dump的几种方式
java获取内存dump的几种方式
获取内存详情:jmap -dump:format=b,file=e.bin pid
这种方式可以用 jvisualvm.exe 进行内存分析,或者采用 Eclipse Memory Analysis Tools (MAT)这个工具
获取内存dump: jmap -histo:live pid
这种方式会先出发fullgc,所有如果不希望触发fullgc 可以使用jmap -histo pid
第三种方式:jdk启动加参数:
-XX:+HeapDumpBeforeFullGC
-XX:HeapDumpPath=/httx/logs/dump
这种方式会产生dump日志,再通过jvisualvm.exe 或者Eclipse Memory Analysis Tools 工具进行分析
jmap
1)查看堆内存信息,包括使用的GC算法、堆配置参数和各代中堆内存使用情况,可以结合jhat使用
2)主要用于分析OOM
用法:
jmap -heap <PID>
jmap -dump:format=b,file=HeapDump <pid> #dump出内存信息,可用内存分析工具分析情况,format=b是通过二进制的意思
例如:
[root@lsy-36-70 ~]# jmap -heap 7574 Attaching to process ID 7574, please wait... Debugger attached successfully. Server compiler detected. JVM version is 25.211-b12 using thread-local object allocation. Parallel GC with 8 thread(s) Heap Configuration: MinHeapFreeRatio = 0 MaxHeapFreeRatio = 100 MaxHeapSize = 3183476736 (3036.0MB) NewSize = 66060288 (63.0MB) MaxNewSize = 1061158912 (1012.0MB) OldSize = 133169152 (127.0MB) NewRatio = 2 SurvivorRatio = 8 MetaspaceSize = 21807104 (20.796875MB) CompressedClassSpaceSize = 1073741824 (1024.0MB) MaxMetaspaceSize = 17592186044415 MB G1HeapRegionSize = 0 (0.0MB) Heap Usage: PS Young Generation Eden Space: capacity = 562561024 (536.5MB) used = 386173616 (368.2838592529297MB) free = 176387408 (168.2161407470703MB) 68.64564012170172% used From Space: capacity = 1048576 (1.0MB) used = 720896 (0.6875MB) free = 327680 (0.3125MB) 68.75% used To Space: capacity = 14155776 (13.5MB) used = 0 (0.0MB) free = 14155776 (13.5MB) 0.0% used PS Old Generation capacity = 108003328 (103.0MB) used = 27321200 (26.055526733398438MB) free = 80682128 (76.94447326660156MB) 25.296627896503338% used 16408 interned Strings occupying 1561208 bytes.
2)dump出堆内存信息到文件
[root@lsy-36-70 ~]# jmap -dump:format=b,file=/tmp/dump01.dat 7574 Dumping heap to /tmp/dump01.dat ... Heap dump file created
或者
[root@lsy-36-70 ~]# jmap -dump:format=b,file=/tmp/dump01.dump 7574
Dumping heap to /tmp/dump01.dump ...
Heap dump file created
3)jhat查看,浏览器输入7000端口访问
[root@lsy-36-70 ~]# jhat -port 7000 /tmp/dump01.dat
或者
[root@lsy-36-70 ~]# jhat -port 7000 /tmp/dump01.dump