Where is the heap dump file created by jcmd?
Asked Answered
C

3

9

I have tried to take a heap dump using jcmd (from a git bash console window):

$ /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?

Cornwall answered 23/10, 2019 at 9:27 Comment(3)
maybe you should specify a path for your find command before -name argumentTrifurcate
find . -iname '*livetest-grindtohalt.hprof*' doesn't find it either. I am assuming it is under the current directory, because that is the repository root in which both the jcmd command was run and process 25156 is running.Cornwall
i understand and it's interesting. I'd give find / ... a try if it doesn't exhaust your machine's resources.Trifurcate
O
13

The answer by Douglas Kretzmann sets you on the correct path to practical jcmd use. To answer the question from the original post, relative paths are resolved against the current working directory of the specified java process. So after

jcmd 6232 GC.heap_dump heap.hprof

you will be able to find heap.hprof in the directory output by

lsof -p 6232 | grep cwd
Obsession answered 30/10, 2020 at 0:53 Comment(0)
O
21

I had the same problem in windows.

jcmd 6232 GC.heap_dump filename=IShp1.hprof

it ran, said file created, but a search of c drive couldn't find it. 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.

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

jcmd 6232 GC.heap_dump /opt/temp/myHd.hprof 
Orchidectomy answered 11/12, 2019 at 21:27 Comment(3)
This answer is pure gold. Indeed, the "filename=" is a documentation error. When you specify that, jcmd creates the dump file named "filename", which is why subsequent invocations produce the "file exists" error (because the equal sign and all that follows are ignored). The correct invocation is giving the desired target path/name directly, without the filename= part.Kolodgie
Is it possible to output this to an stdout? So we can stream it with scp. The thing is, sometimes in real life scenarios, the disk space is too low on servers, and storing it on vm is not an optionForetopgallant
Adding the filename=abc.hprof creates a file with the name "filename" in the current working directory of the Java process.Blindage
O
13

The answer by Douglas Kretzmann sets you on the correct path to practical jcmd use. To answer the question from the original post, relative paths are resolved against the current working directory of the specified java process. So after

jcmd 6232 GC.heap_dump heap.hprof

you will be able to find heap.hprof in the directory output by

lsof -p 6232 | grep cwd
Obsession answered 30/10, 2020 at 0:53 Comment(0)
A
6

Literally upstream refuses to "fix" diagnostic for 4 years:

https://bugs.openjdk.java.net/browse/JDK-8177763 - Getting an hprof dump via jcmd could benefit from stronger option checking.

And official docs: https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/memleaks004.html presents incorrect examples, like:

Example 3-2 Create a Heap Dump using jcmd

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

Just strip 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:

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
Anticlimax answered 21/12, 2020 at 22:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.