Sunday, March 31, 2013

How to enable MAT (Eclipse Memory Analyzer) in your Eclipse?

When talk about out of memory crashing issue in my Java app, I really felt helpless in finding the root cause. Even though MAT can be an alternative in helping me getting closer to the issue, but in the end of the day, all still depending on the code review and the best practice during the development.

Below are steps to setup the MAT.

1. To install MAT, open Eclipse, click on Help -> Install New Software ->
2. Enter "Add" button and enter "Name" and "Location" into the dialog box
Name: MAT
Location: http://download.eclipse.org/mat/1.2/update-site/
3. Check the "Memory Analyzer for Eclipse IDE" and "Standalone Memory Analyzer" and click on "Next" button. Follow the step as shown in the wizard, the MAT will be installed into the Eclipse once the Eclipse is restarted.


4. To allow the application to generate hprof file, right click on the project, Run As -> Run Configurations, select "Arguments" tab and enter "-XX:+HeapDumpOnOutOfMemoryError" into "VM arguments" text box.

5. When the Java/Android app crashes, hrof will be generated.

6. Double click on the hprof file, MAT will be launched and select "Leak Suspect Report" option and click on "Finish" button.

7. Leaks Suspect report will be generated.

If you encounter "Parsing heap dump" while opening the hprof file, open the eclipse.ini file which is located at Eclipse home folder. Increase the -Xms and -Xmx size (until the message disappear), refer to the highlighted paragraph as shown below:-


-startup
plugins/org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.200.v20120522-1813
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
1024m
--launcher.defaultAction
openFile
-product
org.eclipse.epp.package.jee.product
--launcher.defaultAction
openFile
--launcher.XXMaxPermSize
1024M
-vmargs
-Dosgi.requiredJavaVersion=1.5
-Dhelp.lucene.tokenizer=standard
-Xms8192m
-Xmx10240m


To produce Android hprof file for MAT analysis, launch the DDMS, select device follow by running application. Click on dump HPROF file, the MAT analyzer will be launched.





No comments: