This is a 2015 introduction to the Systrace tool. The workflows that mention Eclipse, Device Monitor, sdk/tools/systrace, and User builds being unable to capture traces are no longer the default path today. What remains useful is the basic idea: Systrace showed SurfaceFlinger, WindowManager, View, CPU scheduling, and other system behavior on one timeline. For current trace capture and analysis, start from the Android Perfetto Series Catalog.
The workflow has changed like this:
| Old flow |
Current flow |
| Click Systrace in Eclipse / Android Studio Device Monitor |
Use System Tracing from Developer Options, or run adb shell perfetto |
python systrace.py --time=10 -o trace.html ... |
adb shell perfetto -t 10s -b 64mb ... --out /data/misc/perfetto-traces/trace.perfetto-trace |
| Generate HTML and open it in Chrome |
Generate .perfetto-trace and open it in Perfetto UI or trace_processor |
| Mainly zoom and click inside the HTML view |
Read tracks and slices first, then narrow evidence with search, SQL, and metrics |
| User builds were treated as mostly unusable |
User builds can capture limited information; system-level detail still benefits from Userdebug/eng |
This is the first article in the Android Performance Optimization Tools series. This series mainly introduces the tools used during the Android performance optimization process, how to use these tools to discover problems, and how to solve them. In terms of performance optimization, Android provides many performance tools for everyone to use. Following our consistent “discover problem - solve problem” thinking, discovering the problem is the most important part. Trying to solve a problem without first identifying it properly often leads to half the effort for twice the result.
In this article, we’ll start with a brief introduction to the Systrace tool.
Introduction to Systrace
Systrace is a performance data sampling and analysis tool introduced in Android 4.1. It helps developers collect execution information from key Android subsystems (such as SurfaceFlinger, WindowManagerService, and other critical Framework modules, services, and the View system), allowing for a more intuitive analysis of system bottlenecks and performance improvements.
Systrace’s capabilities include tracking system I/O operations, kernel workqueues, CPU load, and the health of various Android subsystems. On the Android platform, it’s composed of three main parts:
- Kernel Space: Systrace leverages the
ftrace feature in the Linux Kernel. Therefore, to use Systrace, the relevant ftrace modules in the kernel must be enabled.
- Data Collection: Android defines a
Trace class that applications can use to output statistical information to ftrace. Additionally, the atrace program in Android reads statistical info from ftrace and passes it to data analysis tools.
- Data Analysis Tools: Android provides
systrace.py (a Python script located in Android SDK directory/platform-tools/systrace that calls atrace internally) to configure data collection (such as tags, output filename, etc.), collect ftrace statistics, and generate a resulting HTML file for user viewing. Essentially, Systrace is a wrapper around the Linux Kernel’s ftrace. Applications need to utilize the Trace class provided by Android to use Systrace.
Official documentation and usage for Systrace can be found here: Systrace