MAT: Getting Setup

Profiling memory usage of an Android application can really help pinpoint performance issues. Your app might be janky or laggy when scrolling, or you may run into the dreaded application OutOfMemoryError. In an effort to tackle these issues I’ve decided to start learning how to correctly profile an Android app and get some meaningful results to hopefully remedy any issues.

Preface

OS: Yosemite 10.10.1

Android Studio: Version 1.2

Device: OnePlus One running Lollipop nightly’s

Installation

You do not need Eclipse to use the MAT tool. Simply download the version suitable for your OS.

Create a heap dump file

Open Android Studio and select the option from the toolbar to open the Android Debug Monitor. The icon is the little green Android guy:

Screen Shot 2015-03-21 at 21.02.53

Next, open your app on your device and use it like a typical user would for a few seconds.

In the Android Debug Monitor, select your device and your application process.

Screen Shot 2015-03-21 at 21.10.00

Click the “Update Heap” button above the process list:

Screen-Shot-2015-03-21-at-21.10.00

Open the “Heap” tab and then hit the “Cause GC” button:

Screen-Shot-2015-03-21-at-21.30.19

Once the GC has occurred (you will see data in the heap tab updated), click the “Dump HPROF file” option. This may take a few seconds so be patient. Save the .hprof file and remember its location.

Screen-Shot-2015-03-21-at-21.34.51

 

Screen-Shot-2015-03-21-at-21.34.00

 

Using the HPROF file

Ok, we’re nearly there. We have HPROF file but before we can use it in MAT, we need to convert it into a compatible format. Luckily, the Android SDK provides a tool called “hprof-conv” in the platform-tools folder. So open up a terminal and type the following command:

If you get a “command not found” error in the terminal, you need to add the Android SDK to your path (details here). Also, remember to change the HPROF file path in the command if you saved the it in a different location.

We’re finally ready to use MAT! Open up MAT and select the option to open a new heap dump. Find your converted HPROF file (“converted.com.test.profiling.hprof”) and open it. You will be given a choice of reports, choose any for now and we’ll look at each option in-depth later.

 

 

 

 

Share This

Leave a Reply