Java jcmd 代替 jmap 导出堆内存快照

JVM jcmd 诊断工具 About 1,007 words

说明

jcmd <pid> GC.heap_dump dump.hprof命令等价于jmap -dump:live,format=b,file=dump.hprof <pid>

jcmd <pid> GC.heap_dump -all dump.hprof命令等价于jmap -dump:format=b,file=dump.hprof <pid>

查看帮助

命令

jcmd 12345 help GC.heap_dump

输出:

12345:
GC.heap_dump
Generate a HPROF format dump of the Java heap.

Impact: High: Depends on Java heap size and content. Request a full GC unless the '-all' option is specified.

Permission: java.lang.management.ManagementPermission(monitor)

Syntax : GC.heap_dump [options] <filename>

Arguments:
        filename :  Name of the dump file (STRING, no default value)

Options: (options must be specified using the <key> or <key>=<value> syntax)
        -all : [optional] Dump all objects, including unreachable objects (BOOLEAN, false)

dump 存活对象

dump存活对象会执行一次Full GC,确保不可达对象全部被回收。当然生成的hprof文件也更小。

jcmd 12345 GC.heap_dump C:\pid-12345.hprof

dump 全部对象

dump所有对象,包括等待垃圾回收的不可达对象。生成的hprof文件也较大。

jcmd 12345 GC.heap_dump -all C:\pid-12345-all.hprof
Views: 3,123 · Posted: 2021-08-11

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh