简体   繁体   English

jcmd创建的堆转储文件在哪里?

[英]Where is the heap dump file created by jcmd?

I have tried to take a heap dump using jcmd (from a git bash console window):我尝试使用 jcmd 进行堆转储(来自 git bash 控制台窗口):

$ /c/Program\ Files/Java/jdk1.8.0_202/bin/jcmd 25156 GC.heap_dump filename=livetest-grindtohalt.hprof
25156:
Heap dump file created

However, the file does not seem to exist:但是,该文件似乎不存在:

$ find -name livetest-grindtohalt.hprof

$

Where can I find it?我在哪里可以找到它?

I had the same problem in windows.我在 windows 中遇到了同样的问题。

jcmd 6232 GC.heap_dump filename=IShp1.hprof

it ran, said file created, but a search of c drive couldn't find it.它运行,表示文件已创建,但搜索 c 驱动器找不到它。 Reran and got 'file exists'.重新运行并得到“文件存在”。

Tried with a path specified in filename, and a different file name,尝试使用文件名中指定的路径和不同的文件名,

jcmd 6232 GC.heap_dump filename=c:\temp\IShp2.hprof

This also got 'file exists'.这也得到了“文件存在”。

I conclude 'filename' is not being honored.我的结论是“文件名”没有得到尊重。 Presumably jcmd is writing some internally-specified unknown file name to some unknown location, when the 'filename' is specified.当指定“文件名”时,大概 jcmd 正在将一些内部指定的未知文件名写入某个未知位置。

Instead反而

jcmd 6232 GC.heap_dump c:\temp\isHpdmp1.hprof

works and writes the file to the specified location.工作并将文件写入指定位置。 So presumably for *nix something like所以大概对于*nix类似

jcmd 6232 GC.heap_dump /opt/temp/myHd.hprof 

The answer by Douglas Kretzmann sets you on the correct path to practical jcmd use. Douglas Kretzmann 的回答让您走上了实际使用 jcmd 的正确道路。 To answer the question from the original post, relative paths are resolved against the current working directory of the specified java process.为了回答原始帖子中的问题,相对路径是针对指定 java 进程的当前工作目录解析的。 So after所以之后

jcmd 6232 GC.heap_dump heap.hprof

you will be able to find heap.hprof in the directory output by您将能够在目录 output 中找到heap.hprof

lsof -p 6232 | grep cwd

Literally upstream refuses to "fix" diagnostic for 4 years:从字面上看,上游拒绝“修复”诊断 4 年:

https://bugs.openjdk.java.net/browse/JDK-8177763 - Getting an hprof dump via jcmd could benefit from stronger option checking. https://bugs.openjdk.java.net/browse/JDK-8177763 - 通过 jcmd 获取 hprof 转储可以受益于更强大的选项检查。

And official docs: https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/memleaks004.html presents incorrect examples, like:并提供官方文档: https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/memleaks004.ZFC35FDC70D5FC69D2569883A82E不正确的例子,例如:C

Example 3-2 Create a Heap Dump using jcmd示例 3-2 使用 jcmd 创建堆转储

jcmd <process id/main class> GC.heap_dump filename=Myheapdump

Just strip filename= .只需剥离filename=

Current working directory for dump is of PID process, not of jcmd : So use full path if you don't want to search for dump )) Full workflow:转储的当前工作目录是PID进程,而不是jcmd :因此,如果您不想搜索转储,请使用完整路径))完整工作流程:

mkdir dest/
chmod a+w dest/

sudo jcmd
1234 my.evil.app

sudo -u myuser -g mygrp jcmd 1234 GC.heap_dump $PWD/dest/myapp.hprof

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM