除了jmap之外,还有命令行方法来获取jvm堆转储吗? [英] Is there a command line method to get a jvm heap dump besides jmap?

查看:302
本文介绍了除了jmap之外,还有命令行方法来获取jvm堆转储吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在Linux中使用oracle jvm 1.8 64bit.

We are using oracle jvm 1.8 64bit in linux.

我们知道jmap可以获取jvm堆转储:

We know jmap can get jvm heap dump:

jmap -F -dump:format=b,file=***filepath*** ***pid***

但是它很慢.

我们知道,通过JVisualVM和JConsole,连接到JMX也会获得堆转储,而且速度非常快.但是它们带有GUI.

We know with JVisualVM and JConsole connecting to JMX can also get a heap dump, and it's very quick. But they are with GUI.

但是,在我们的产品环境中,没有GUI.而且任何具有GUI的计算机都无法访问该环境.

However, in our product environment, there is no GUI. And no machine with GUI can access that environment.

所以我们的问题是- JVisualVM和JConsole可以支持命令行进行堆转储吗? 或者 除了jmap之外,还有命令行方法来获取jvm堆转储吗?

So our question is - Can JVisualVM and JConsole support a command line to do heap dump? Or Is there a command line method to get a jvm heap dump besides jmap?

我们今天尝试过-

1,使用jvisualvm(remote jmx),我们可以成功获得堆转储

1, using jvisualvm(remote jmx), we can get heap dump successfully

2,使用不带-F选项的jmap,转储失败:

2, using jmap without -F option, the dump failed:

[root @ panda01〜]#jmap -dump:format = b,file =/tmp/heapdump.31941.hprof 31941

[root@panda01 ~]# jmap -dump:format=b,file=/tmp/heapdump.31941.hprof 31941

31941:无法打开套接字文件:目标进程未响应或未加载HotSpot VM

31941: Unable to open socket file: target process not responding or HotSpot VM not loaded

当目标进程没有响应时,可以使用-F选项

The -F option can be used when the target process is not responding

3,使用带有-F选项的jmap,转储成功,但是速度很慢:

3, using jmap with -F option, the dump successfully, but slow:

[root @ panda01〜]#jmap -F -dump:format = b,file =/tmp/heapdump.31941.hprof 31941

[root@panda01 ~]# jmap -F -dump:format=b,file=/tmp/heapdump.31941.hprof 31941

附加到进程ID 31941,请等待...

Attaching to process ID 31941, please wait...

调试器已成功连接.

检测到服务器编译器.

JVM版本为25.92-b14

JVM version is 25.92-b14

将堆转储到/tmp/heapdump.31941.hprof ...

Dumping heap to /tmp/heapdump.31941.hprof ...

已创建堆转储文件

我们注意到结果(2个.hprof文件).使用jvisualvm的文件转储(称为第一个转储)小于使用jmap -F的文件转储(称为第二个转储). 使用jvisualvm查看时,第一个转储中的实例数和大小比第二个转储中的实例数和大小小得多.

And we notice the result(2 .hprof files). The file dump with jvisualvm(called first dump) is smaller than the file dump with jmap -F(called 2nd dump). View with jvisualvm, the instance count and size in the 1st dump are much less than the ones in the 2nd dump.

推荐答案

在不使用-F选项的情况下使用jmap-这样会更快.

Use jmap without -F option - it will be a way faster.

此答案中描述了差异

请注意,在没有-F的情况下,jmap应该在与目标进程相同的用户/组下运行.

Note that without -F jmap should be run under the same user/group as the target process.

这篇关于除了jmap之外,还有命令行方法来获取jvm堆转储吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆