Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Analyse Java Application for memory usages using Eclipse Memory Analyzer
# Login to server on which java application is running
# Get Java PID
ps -ef | grep java
# Take Heapdump using commandline tool jmap which ships with jdk
# jmap -dump:format=b,file=<filepath> <pid>
jmap -dump:format=b,file=/opt/22may2017050500-heapdump.bin 1718
# Copy this dumpfile from remote server to local machine , as parsing of large file may slow down the server
# Download Eclipse MAT from http://www.eclipse.org/mat/
# Extract MemoryAnalyzer-1.6.1.20161125-linux.gtk.x86_64.zip
cd mat/
ll
total 180
drwxr-xr-x 6 a a 4096 May 22 19:12 configuration
-rw-r--r-- 1 a a 16863 Nov 23 15:11 epl-v10.html
drwxr-xr-x 18 a a 4096 Dec 5 07:22 features
-rw-rw-r-- 1 a a 17759 May 22 18:14 hs_err_pid14154.log
-rwxr-xr-x 1 a a 79058 Dec 5 07:21 MemoryAnalyzer
-rw-r--r-- 1 a a 191 May 22 18:20 MemoryAnalyzer.ini
-rw-r--r-- 1 a a 193 May 22 17:24 MemoryAnalyzer.ini~
-rw-r--r-- 1 a a 9013 Nov 23 15:11 notice.html
drwxr-xr-x 4 a a 4096 Dec 5 07:22 p2
-rwxr-xr-x 1 a a 333 Nov 23 15:11 ParseHeapDump.sh
drwxr-xr-x 5 a a 20480 Dec 5 07:22 plugins
drwxrwxr-x 3 a a 4096 May 22 18:20 workspace
#Out of Memory Error while Running the Memory Analyzer
# Well, analyzing big heap dumps can also require more heap space. Give it some more memory (possible by running on a 64-bit machine):
MemoryAnalyzer -vmargs -Xmx4g -XX:-UseGCOverheadLimit
# Alternatively, edit the MemoryAnalyzer.ini to contain:
-vmargs
-Xmx4g
-XX:-UseGCOverheadLimit
# Analyse Heap dump using Command line Eclipse MAT Memory Analyser Tool
./ParseHeapDump.sh <heapdumpfilename.bin> org.eclipse.mat.api:suspects
# The output is a small and easy to download jvm_Leak_Suspects.zip. This has HTML files just like the MAT Eclipse UI. It can be easily SCP'ed/emailed around.
# Extract the zip file and open default index.html file to analyze the report
# How to analyse unreachable objects : add -keep_unreachable_objects flag
./ParseHeapDump.sh -keep_unreachable_objects <heapdumpfilename.bin> org.eclipse.mat.api:suspects
# other reports using the same dump
./ParseHeapDump.sh <heapdumpfilename.bin> org.eclipse.mat.api:suspects
./ParseHeapDump.sh <heapdumpfilename.bin> org.eclipse.mat.api:overview
./ParseHeapDump.sh <heapdumpfilename.bin> org.eclipse.mat.api:top_components
More details -
http://wiki.eclipse.org/index.php/MemoryAnalyzer/FAQ
http://javaforu.blogspot.in/2013/11/analyzing-large-java-heap-dumps-when.html
http://eclipsesource.com/blogs/2013/01/21/10-tips-for-using-the-eclipse-memory-analyzer/
http://memoryanalyzer.blogspot.in/2008/05/automated-heap-dump-analysis-finding.html
http://java.jiderhamn.se/2011/12/11/classloader-leaks-i-how-to-find-classloader-leaks-with-eclipse-memory-analyser-mat/
http://docs.oracle.com/javase/8/docs/api/java/lang/Class.html
http://docs.oracle.com/javase/8/docs/api/java/lang/ClassLoader.html
https://tomcat.apache.org/tomcat-8.0-doc/class-loader-howto.html
https://tomcat.apache.org/tomcat-8.0-doc/config/loader.html
https://www.dynatrace.com/resources/ebooks/javabook/class-loader-issues/
https://www.dynatrace.com/technologies/java-monitoring/java-performance/
https://www.dynatrace.com/resources/ebooks/javabook/
http://javaeesupportpatterns.blogspot.in/2014/03/classnotfoundexception-is-it-slowing.html
http://dimovelev.blogspot.in/2015/02/performance-pitfalls-hibernate-criteria.html
http://dimovelev.blogspot.in/2015/02/performance-pitfalls-hibernate-query.html
https://vladmihalcea.com/2016/12/14/the-performance-penalty-of-class-forname-when-parsing-jpql-and-criteria-queries/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment