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.
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.
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:
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 Studio Memory Allocation tracker Sunburst View
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:
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. 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 >>