导出jvm的内存快照进行分析

查找对应的进程id(PID)

linux下使用

ps aux|grep java
找出PID后

输出快照

jmap -dump:format=b,file=/usr/local test1.hprof 2778

jmap -dump:format=b,file=/usr/local test1.hprof 2778
Attaching to core 2778 from executable test1.hprof, please wait...
Error attaching to core file: cannot open binary file
sun.jvm.hotspot.debugger.DebuggerException: cannot open binary file
        at sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal.attach0(Native Method)
        at sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal.attach(LinuxDebuggerLocal.java:286)
        at sun.jvm.hotspot.HotSpotAgent.attachDebugger(HotSpotAgent.java:673)
        at sun.jvm.hotspot.HotSpotAgent.setupDebuggerLinux(HotSpotAgent.java:611)
        at sun.jvm.hotspot.HotSpotAgent.setupDebugger(HotSpotAgent.java:337)
        at sun.jvm.hotspot.HotSpotAgent.go(HotSpotAgent.java:304)
        at sun.jvm.hotspot.HotSpotAgent.attach(HotSpotAgent.java:156)
        at sun.jvm.hotspot.tools.Tool.start(Tool.java:191)
        at sun.jvm.hotspot.tools.Tool.execute(Tool.java:118)
        at sun.jvm.hotspot.tools.HeapDumper.main(HeapDumper.java:83)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at sun.tools.jmap.JMap.runTool(JMap.java:201)
        at sun.tools.jmap.JMap.main(JMap.java:130)

找到JDK安装路径
在使用jmap、jstack、jinfo指令时,可能会碰到“Error attaching to core file: Can’t attach to the core file”错误,实际上这个错误很简单,JVM要求你必须使用对应JDK版本jmap、jstack指令来执行。
如果直接使用jmap或者jstack指令,如果要避免这种错误,那么就要到jdk1.8.0_261安装的bin目录下再执行jmap或jinfo指令。
找到jdk路径

/usr/local/jdk1.8.0_261

再次运行

jmap -dump:format=b,file=/usr/local/jdk1.8.0_261/bin/test1.hprof 2778

或者进到JDK/bin下

jmap -dump:format=b,file=head.hprof 2778

无需进到bin下只需要路径正确即可。

jmap -dump:format=b,file=/usr/local/java-project/test11.hprof 22223
查看
jhat -port 9998 jhat -port 9998 /usr/local/jdk1.8.0_261/bin/test1.hprof
 
#浏览器访问
http://localhost:9998
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值