Using the Traceview and dmtracedump platform tools
The Android SDK includes among its various tools two that are specially intended to analyze performance problems and profiles, and potentially determine the target to apply optimizations. Android also offers us the Dalvik Debug Monitor Service (DDMS), which collates these tools all in one place. DDMS can be opened from Android Studio by navigating to Tools | Android | Device Monitor, or from the command line with the command monitor. You can use Traceview and other tools inside DDMS by using handy GUI shortcuts. Here, however, we are going to use the command-line options so that you can understand the tools behind the GUI.
These tools have an advantage over other alternatives: usually, no modification to the source code is needed for simpler tasks. However, for more complex cases, some additions are needed, but they are very simple, as we will see shortly.
If you don't need precision about starting and stopping tracing, you can drive it from...