java cpu100% 分析过程

分析工具: MAT

一、准备工作

1、修改tomcat/bin 中的文件:

#重启启动,tomcat

启动命令:./startup.sh && tail -f ../logs/catalina.out

启动后, 当内存不足等异常情况, 会先生成文件heapdump.hprof, 后期根据该文件分析程序哪里出现问题。

2、使用MAT 工具分析文件heapdump.hprof

1)从mat 官网下载软件包:MemoryAnalyzer-1.10.0.20200225-linux.gtk.x86_64.zip

2)解压: unzip MemoryAnalyzer-1.10.0.20200225-linux.gtk.x86_64.zip -d  /tmp

解压后的文件:

 [ssss@11111 mat]$ ll
总用量 148
drwxrwxr-x  6 ssss ssss 4096 12月 29 14:30 configuration
-rw-rw-r--  1 sss ssss 16863 2月  25 2020 epl-v10.html
drwxrwxr-x 18 ssss ssss 4096 3月  25 2020 features
-rwxr-xr-x  1 ssss ssss 73064 3月  25 2020 MemoryAnalyzer
-rw-rw-r--  1 ssss ssss 200 12月 29 13:37 MemoryAnalyzer.ini
-rw-rw-r--  1 ssss apps  9013 2月  25 2020 notice.html
drwxrwxr-x  4 ssss ssss 4096 3月  25 2020 p2
-rwxr-xr-x  1 ssss ssss 333 2月  25 2020 ParseHeapDump.sh
drwxrwxr-x  5 ssss ssss 20480 3月  25 2020 plugins
drwxrwxr-x  3 ssss ssss 4096 12月 29 13:38 workspace

调用命令:ParseHeapDump.sh

执行分析命令

执行如下命令会输出泄漏嫌疑对象的分析结果,这个结果是比较全面的。

./ParseHeapDump.sh ../today_heap_dump/jvm.hprof org.eclipse.mat.api:suspects

  • ./ParseHeapDump.sh /path/to/tomcatdump org.eclipse.mat.api:suspects org.eclipse.mat.api:overview org.eclipse.mat.api:top_components

还支持另外两个分析结果:

  1. org.eclipse.mat.api:overview

  2. org.eclipse.mat.api:top_components

[apps@m1111 mat]$ ./ParseHeapDump.sh /apps/tmp/A20211229-1124heapdump.hprof org.eclipse.mat.api:suspects org.eclipse.mat.api:overview org.eclipse.mat.api:top_components

分析后生成文件:

主要是这几个文件:

A20211229-1124heapdump_Leak_Suspects.zip 

A20211229-1124heapdump_System_Overview.zip

A20211229-1124heapdump_Top_Components.zip

unzip 解压这几个文件:

解压到指定目录:

例如:[test@m11154 matfile20220310]$ unzip 20220309heapdump_Leak_Suspects.zip -d /data/test/app/tomcat/webapps/matfile20220310/file0

解压后访问:127.0.0.1:8080/matfile20220310/file0/index.html (根据自己tomcat的ip地址和端口)

-rw-rw-r-- 1 dq dq  83242 12月 29 14:49 A20211229-1124heapdump_Leak_Suspects.zip
-rw-rw-r-- 1 dq dq  65077 12月 29 14:49 A20211229-1124heapdump_System_Overview.zip
-rw-rw-r-- 1 dq dq 229727 12月 29 14:50 A20211229-1124heapdump_Top_Components.zip
drwxrwxr-x 5 dq dq   4096 12月 29 15:01 suspects  #自己新建的目录 放heapdump_Leak_Suspects.zip文件


drwxrwxr-x 5 dq dq   4096 12月 29 15:08 systemOverview #自己新建的目录,放heapdump_System_Overview.zip的解压文件
drwxrwxr-x 5 dq dq   4096 12月 29 15:09 topComponents #自己新建的目录,放heapdump_Top_Components.zip的解压文件。

# tomcat 对应的路径:

tomcat/webapps/matfile2/suspects

浏览器访问:http://localhost:8080/matfile2/suspects/index.html

可以看到结果页面:

点击:The stacktrace of this Thread is available. See stacktrace.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值