Note: This content is outdated. Please refer to the new Systrace Series Articles for updated information.
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
ftracefeature in the Linux Kernel. Therefore, to use Systrace, the relevantftracemodules in the kernel must be enabled. - Data Collection: Android defines a
Traceclass that applications can use to output statistical information toftrace. Additionally, theatraceprogram in Android reads statistical info fromftraceand passes it to data analysis tools. - Data Analysis Tools: Android provides
systrace.py(a Python script located inAndroid SDK directory/platform-tools/systracethat callsatraceinternally) to configure data collection (such as tags, output filename, etc.), collectftracestatistics, and generate a resulting HTML file for user viewing. Essentially, Systrace is a wrapper around the Linux Kernel’sftrace. Applications need to utilize theTraceclass provided by Android to use Systrace.
Official documentation and usage for Systrace can be found here: Systrace