This page explains how to use Traceview inside Android Studio.
Starting with version 0.2.10, Android Studio includes a built in viewer for viewing Dalvik VM traces. This is intended as a replacement for traceview
tool that is part of DDMS/Monitor and ADT.
Within Android Studio, you can launch this viewer in one of two ways:
- If you already have a trace file that was generated programmatically on the device, then pull that file from the device to your host and then open it in Android Studio (File | Open...)
- If you don't have a trace file, then:
- open the DDMS tool window in Studio (Alt + 6)
- select your application
- Click on the "Start Method Tracing" icon as shown in screenshot 1 below.
- Then exercise your app to trace the relevant sections of your app that need to be benchmarked/traced.
- Click on the "Stop Method Tracing" icon. This will automatically obtain the trace from the device and load it up in the viewer.
When a trace file is opened, it launches a viewer that looks like this:
This view comprises of two parts:
- Visualization of the application execution over time by displaying the application stack over time (for a particular thread). This type of visualization is typically called a “flamechart”.
- A tabular view that provides summary statistics for each method in the thread.
The flamechart visualization is interpreted as follows: The horizontal axis indicates time and at any point in time, you can look at the current stack by tracing the list of calls vertically from top to bottom.
By default, each method is colored based on its exclusive time (i.e. the time spent in that method only, excluding all the methods in its callees). If there are any hotspots in your code, you’ll see them right away by looking at the colors.
Use your mouse wheel to zoom in/out at any particular point.
At the top of the view, there are a few controls that are displayed:
- If your trace contains execution information from multiple threads, you can pick which thread is displayed using the drop down control at the top.
- On devices that support it, you can visualize by either the wall clock time (real time) or the thread time (cpu time).
- Rather than coloring methods by using their exclusive time, you can choose to use their inclusive time to assign method colors. Using inclusive time for coloring implies that the top level method (the equivalent of main()) that runs everything takes up 100% of the time, and will look the darkest, and all methods below it will receive slightly brighter values depending on how much time was spent in them.
- Zoom fit: fits the entire trace visualization in the current viewport.
- Find: This action can also be invoked by pressing Ctrl+F when the view is in focus. This brings up a find dialog that can be used to search for particular methods. The methods matching the patterns are highlighted in a different color.
Finally, there are a few features that are still missing in this version of traceview that will be added in subsequent releases. You can view the list of known issues and missing features at b.android.com under the traceview subcomponent.