First off, what is a heap dump? A heap dump is essentially a snapshot of an application’s data at a given point in time. It maps a specific process, view, etc. to the memory being used. Sort of like ctl-alt-delete on windows in order to determine what’s using up your app’s memory.
To get a heap dump in Eclipse for an application running on your device:
- Open Eclipse
- Run the target application on the target device by pushing the application to the device over USB (then keep USB connected).
- Select Window->Open Perspective->DDMS
- The target device should be shown on the left side in the devices window.
- The target application should be shown under the device
- Select the target application and then the Dump HPROF file icon(half-full glass with green fluid and red arrow). This will prompt you to save the file; do so.
Convert Android HPROF to readable HPROF
- The previous file cannot yet be read by the Eclipse MAT tool (see below) and so must be converted first.
- On your computer go to C:\…\android-sdks\tools (where … is wherever you installed eclipse) and copy the hprof-conv.exe file
- Navigate to the folder where you saved the heap dump and paste the hprof-conv.exe file (you can probably keep it in its original location and navigate to files, but I’m lazy).
- Open a command prompt and navigate to the folder where your file and the hprof-conv.exe file are located (can do using cd:\folderName).
- Type the following line into the command prompt and hit enter:
hprof-conv dump.hprof converted-dump.hprof
Your newly converted file will be created in the same folder as the original file and will be called converted-dump.hprof.
Opening HPROF in Eclipse after conversion:
- Go to Window->Open Perspective->Other->Memory Analysis
- This may take a while to open
- When it opens, it will show up amoung the coding windows-at least mine did-and so find it using the window icon that looks like a disk structure
- From here, you will be at the home screen of MAT with your app’s dump file. Use any of the following links as reference on how to analyze things:
NOTE: READ THIS…I was trying to open the converted file in Eclipse since I had the MAT plug-in installed and everything went well. But, that was only because I recorded the HPROF before installing the MAT plug-in for Eclipse. After I installed that plug-in, DDMS stopped asking me where to store my file and what to name it. This became very frustrating since I couldn’t get dump files, but I noticed that randomly numbered tabs were showing up in the java perspective and had the MAT disk icons. Well…blam! Those were the dumps and already converted for me. Also, if I hit the phone icon in DDMS it will do a screen capture dump showing me layout views and images on screen! Awesome!!!!