自动MAT-从命令行分析Java堆转储

A while ago, I had to analyse a large java heap dump, generated by one of our servers after a memory leak. This was hard.
I usually use Eclipse M一种T for the job, but this time, it was so large the tool could not parse the heap dump in an acceptable time, and required more and more memory.

最终,我在云中使用了具有GUI的强大机器并使其正常工作,但体验却很糟糕。 我必须为此使用GUI,因为那时我所知道的所有工具都需要GUI才能运行。

我并不是每天都在云中运行带有GUI的服务器,而是花了一些时间来配置服务器,启动服务器,连接远程桌面等。

我认为必须有一个更好的选择。 因此,我环顾四周,发现可以让Eclipse MAT从命令行解析堆转储!

您可以使用Linux安装的Eclipse MAT随附的脚本。 该脚本将计算索引以供日后在MAT中使用,并且还可以生成一些不错的HTML报告,这些报告通常足以理解问题。 索引文件将帮助Eclipse MAT在几秒钟内(而不是很长时间)打开。

这比我的经验要好得多,我可以在终端上的远程服务器上运行脚本,该脚本很容易设置,通常我有几个服务器可以为我做一些工作。

我已经尝试了脚本,并且效果很好。 但是,它仅随linux安装一起提供。 如果我想在Mac或Windows上运行该怎么办? 另外,Eclipse MAT要求安装Java。

So, I decided to wrap it in a docker container, and that is how Auto-MAT got created.
Now every time I need to analyse a heap dump I could just run something like:

docker run -it --mount src = $(pwd),target = / data,type = bind docker.bintray.io/jfrog/auto-mat heap1.hprof 11g可疑,概述

这将解析堆转储,创建索引并生成漂亮的2个HTML报告。 嫌疑犯和概述。

运行此命令后,通常足以打开HTML报表以了解问题。 但是,如果您需要更深入地了解内存,则可以使用MAT打开堆转储,并且由于索引已经存在,因此Eclipse MAT将很快打开。

自动MAT-从命令行分析Java堆转储
自动MAT-从命令行分析Java堆转储

Well, that was great, but if I needed a strong machine to run Auto-MAT, I would still have to find a machine, upload the heap dump, install docker if it is not installed, and then download everything back or store it somewhere.

因此,我决定围绕它构建自动化。 首先,我要求我的同事建立一个Jenkins作业,该作业将从生产服务器中获取堆转储,并将其上载到Artifactory。

后来我建立了第二个Jenkins作业,该作业将从Artifactory下载堆转储并在其上运行Auto-MAT。 Auto-MAT运行的工件将被上传回工件。

第二个Jenkins作业可以由第一个作业触发,也可以在有人将堆转储上传到Artifactory之后手动触发。

这样,组织中的任何人都可以单击按钮来分析堆转储。

If you are planning to work with heap dumps in automation, I recommend to compress them, I use pigz which is a faster version of gzip. I used Artifactory to store the files for my automation, you can use anything else, but if you are using Artifactory check out jfrog-cli, and especially the parallel download and upload features.

一种uto-MAT is open source and you can visit the github page for more: https://github.com/jfrog/auto-mat

from: https://dev.to//jfrog/auto-mat-analyse-java-heap-dumps-from-commandline-10hg