I am creating heap dump using below command:
jmap -dump:file=DumpFile.txt <process-id>
I have opened the generated file - DumpFile.txt
but it is not in readable format.
So please let me know how to analyze the data in the generated file.
I am creating heap dump using below command:
jmap -dump:file=DumpFile.txt <process-id>
I have opened the generated file - DumpFile.txt
but it is not in readable format.
So please let me know how to analyze the data in the generated file.
You should use jmap -heap:format=b <process-id>
without any paths. So it creates a *.bin file which you can open with jvisualvm.exe
(same path as jmap). It's a great tool to open such dump files.
File > Load...
the heap dump (it's not a core dump). See: https://mcmap.net/q/282198/-visualvm-not-a-valid-core-dump –
Disepalous You can use jhat
(Java Heap Analysis Tool) to read the generated file:
jhat [ options ] <heap-dump-file>
The jhat command parses a java heap dump file and launches a webserver. jhat enables you to browse heap dumps using your favorite webbrowser.
Note that you should have a hprof
binary format output to be able to parse it with jhat
. You can use format=b
option to generate the dump in this format.
-dump:format=b,file=<filename>
Reading from 447start.out... java.io.IOException: Unrecognized magic number: 1027423549 at com.sun.tools.hat.internal.parser.Reader.readFile(Reader.java:81) at com.sun.tools.hat.Main.main(Main.java:143)
Here 447start.out is the name of the log file. –
Oliguria format=b
option like this: jmap -dump:format=b,file=<filename>
–
Nayarit -XX:+HeapDumpOnOutOfMemoryError
jvm option, and jhat
worked smoothlessly with it. Thanks for th nice hint! –
Devitalize Very late to answer this, but worth to take a quick look at. Just 2 minutes needed to understand in detail.
First create this java program
import java.util.ArrayList;
import java.util.List;
public class GarbageCollectionAnalysisExample{
public static void main(String[] args) {
List<String> l = new ArrayList<String>();
for (int i = 0; i < 100000000; i++) {
l = new ArrayList<String>(); //Memory leak
System.out.println(l);
}
System.out.println("Done");
}
}
Use jps to find the vmid (virtual machine id i.e. JVM id)
Go to CMD and type below commands >
C:\>jps
18588 Jps
17252 GarbageCollectionAnalysisExample
16048
2084 Main
17252 is the vmid which we need.
Now we will learn how to use jmap and jhat
Use jmap - to generate heap dump
From java docs about jmap “jmap prints shared object memory maps or heap memory details of a given process or core file or a remote debug server”
Use following command to generate heap dump >
C:\>jmap -dump:file=E:\heapDump.jmap 17252
Dumping heap to E:\heapDump.jmap ...
Heap dump file created
Where 17252 is the vmid (picked from above).
Heap dump will be generated in E:\heapDump.jmap
Now use Jhat Jhat is used for analyzing the garbage collection dump in java -
C:\>jhat E:\heapDump.jmap
Reading from E:\heapDump.jmap...
Dump file created Mon Nov 07 23:59:19 IST 2016
Snapshot read, resolving...
Resolving 241865 objects...
Chasing references, expect 48 dots................................................
Eliminating duplicate references................................................
Snapshot resolved.
Started HTTP server on port 7000
Server is ready.
By default, it will start http server on port 7000. Then we will go to http://localhost:7000/
Courtesy : JMAP, How to monitor and analyze the garbage collection in 10 ways
If you use Eclipse as your IDE I would recommend the excellent eclipse plugin memory analyzer
Another option is to use JVisualVM, it can read (and create) heap dumps as well, and is shipped with every JDK. You can find it in the bin directory of your JDK.
VisualVm does not come with Apple JDK. You can use VisualVM Mac Application bundle(dmg) as a separate application, to compensate for that.
As mentioned in most answers above you could take a Heap Dump easily with bellow command:
jmap -dump:live,format=b,file=/path/to/mydump.hprof <pid>
<pid> - The Java Process ID
It would be easy to understand what you just got using a graphical heap dump analyzer such as Eclipse MAT
.
You need Eclipse IDE
and Memory Analyzer plugin
to get started.
More details can be found in this article.
MAT, jprofiler,jhat are possible options. since jhat comes with jdk, you can easily launch it to do some basic analysis. check this out
If you just run jmap -histo:live or jmap -histo, it outputs the contents on the console!
© 2022 - 2024 — McMap. All rights reserved.
jmap -heap <process-id> > DumpFile.txt
? – Wellordered