There are two key programs that I (and most developers) use to profile my Android apps - DDMS (Dalvik Debug Monitor Server) and Android Studio. Plus, you can do some profiling purely on your device. In this blog I will go over each tool briefly and then I will dive deeper into method profiling and memory tracking in the next two blogs.

What is profiling? Why do we need to profile?

You (as a rockstar developer) can utilize profiling to quickly identify performance / memory bottlenecks in your code. By using profiling you can measure method execution time, monitor the full heap space, and track memory allocations in real time. All developers (Web, mobile, desktop, backend...) should perform profiling to ensure their end users have a great experience. Profiling is especially important on mobile apps because of the tight resource constraints. The end user could have a lower end device with less RAM, could be running multiple apps, or just switching between apps like a madman. You can avoid the Android OS from crashing your app by making sure it is as optimized as possible.

Android Profiling Tools

Dalvik Debug Monitor Server (DDMS)

The Android SDK ships with the Dalvik Debug Monitor Server (DDMS). DDMS is a java app that is independent of the IDE you're using and can be launched directly from the command line. Here is a feature list of DDMS:

  • Heap View
  • Memory allocation tracker
  • Method profiling
  • Logcat
  • File explorer
  • Thread examination
  • Network traffic
  • View hierarchy
  • Emulate phone calls
  • General System info
    • CPU
    • GPU
    • FPS

Android Studio

Additionally if you’re an Android Studio IDE user there are even more tools available. Android Studio comes with real time monitoring for memory, GPU, CPU, and network with no overhead. Specifically for memory monitoring it comes with some excellent data visualization tools to really help you dig deep and quickly identify problems. With the release of Android Studio 1.3 came the Allocation Tracker that has an awesome Sunburst view: Android_Profiling_Sunburst1 Android Studio Memory Allocation tracker Sunburst View

Profiling Purely on Your Device

Away from your development machine but still want to profile your app? After enabling Developer Options on your device you can find the Profile GPU Rendering option in Developer Options. How to enable developer options & select profile GPU rendering on your device:

  1. Open device settings
  2. Open "About device"
  3. Click on "Build number" 7 times, you should see a toast indicating "You are now a developer"
  4. Now in device settings you should see the option "Developer options" near the bottom
  5. Open "Developer options"
  6. Find the section titled "Monitoring" you'll find "Profile GPU rendering" under this section
  7. Click "Profile GPU rendering", once dialog appears select "On screen as bars"

This gives you the option to show onscreen bars that each represent one frame of rendering. The taller the bar the longer it took to render. This tool is highly useful to determine if your app is achieving at least 60 frames per second (important for scrolling, animations and game loops). There will be a green horizontal bar that represents the 16 millisecond mark, you want all of your vertical bars to render under this bar (1000ms / 60 = 16ms per frame) to achieve 60 FPS. Android_Profiling_GPU_rendering The official Android SDK docs go into great detail explaining this tool. Excited yet? In the next 2 parts of this blog series I will go in detail on how to utilize method profiling using DDMS, investigate the heap using DDMS Heap View, and show how to track memory allocations using both DDMS and Android Studio. Continue reading Android Method Profiling with DDMS >> Continue reading Tracking Memory Allocation with DDM and Android Studio >>

Try ComponentOne's Xamarin controls

Download the latest version of ComponentOne Studio Enterprise

Download Now!