How do I analyze a .hprof file?
I have a production server running with the following flag: -XX:+HeapDumpOnOutOfMemoryError
Last night it generated a java-38942.hprof file when our server encountered a heap error. It turns out that the developers of the system knew of the flag but no way to get any useful information from it.
If you want a fairly advanced tool to do some serious poking around, look at the Memory Analyzer project at Eclipse, contributed to them by SAP.
Some of what you can do is mind-blowingly good for finding memory leaks etc -- including running a form of limited SQL (OQL) against the in-memory objects, i.e.
SELECT toString(firstName) FROM com.yourcompany.somepackage.User
Read more... Read less...
You can use JHAT, The Java Heap Analysis Tool provided by default with the JDK. It's command line but starts a web server/browser you use to examine the memory. Not the most user friendly, but at least it's already installed most places you'll go. A very useful view is the "heap histogram" link at the very bottom.
jhat -port 7401 -J-Xmx4G dump.hprof
jhat can execute OQL "these days" as well (bottom link "execute OQL")
YourKit Java Profiler seems to handle them too.
If you want to do a custom analysis of your heapdump then there's:
- JVM Heap Dump Analysis library https://github.com/aragozin/jvm-tools/tree/master/hprof-heap
This library is fast but you will need to write your analysis code in Java.
From the docs:
- Does not create any temporary files on disk to process heap dump
- Can work directly GZ compressed heap dumps
- HeapPath notation