This article is the first of Systrace series. It mainly introduces Systrace briefly and introduces its simple use method. How to see Systrace; How to analyze the phenomena in Systrace with other tools.
The purpose of this series is to use Systrace as a tool to look at the overall operation of the Android system from another perspective, and to learn about the Framework from another perspective. Maybe you read a lot of articles about the Framework, but can’t remember the code, or the process it runs through. Maybe you can understand it more deeply from the graphical perspective of Systrace.
Series of articles
- Systrace profile
- Systrace Basics – Systrace prep
- Systrace Basics – Why 60 FPS?
- Systrace basic knowledge – SystemServer interpretation
- Systrace Basics – SurfaceFlinger interpretation
- Systrace Basics – Input interpretation
- Systrace basics – Vsync interpretation
- Systrace Basics – Vsync-App: Choreographer based Rendering mechanics in detail
- Systrace Basics – MainThread and RenderThread interpretation
- Systrace Basics – Binder and lock competition interpretation
- Systrace Basics – CPU Info interpretation
The body of the
Systrace is a new performance data sampling and analysis tool for Android4.1. It can help developers to collect Android key subsystems such as SurfaceFlinger/SystemServer/Kernel/Input/Display Framework and some key module, a service, the View system, etc.) the operation of the information, To help developers more intuitive analysis of system bottlenecks, improve performance.
Systrace tracks system I/O operations, kernel work queues, CPU load, and the health of Android subsystems. In The Android platform, it is mainly composed of three parts:
- Kernel part: Systrace makes use of ftrace in the Linux Kernel. Therefore, to use Systrace, you must enable the kernel module related to ftrace.
- “Data collection part” : Android defines a Trace class. This class can be used by applications to output statistics to FTrace. Android also has an Atrace application that reads statistics from FTrace and gives them to the data analysis tool to process.
- Data Analysis Tools: Systrace. Py (python script file, located in the Android SDK directory /platform-tools/systrace, The atrace program will be called internally to configure the way of data collection (such as the label of data collection, output file name, etc.) and collect Ftrace statistics and generate a result web page file for users to view. In essence, Systrace is a wrapper around ftrace in the Linux Kernel. Application processes need to use the Trace class provided by Android to use Systrace. The official introduction and use of Systrace can be found here: Systrace[1]
Systrace is simple to use
Before using Systrace, you should first learn how to use Systrace on each platform. Since most of you use Eclipse and Android Studio, you should take a direct copy from the official website about how to use Systrace, but no matter what the tool is, the process is the same:
- Get the phone ready to grab the interface you want
- Click start fetching (command line to start executing commands)
- Start on your phone (don’t take too long)
- When the set time is up, the trace.html file will be generated and opened for analysis using Chrome
Generally, the Systrace files are as follows
Command Line Usage
The Systrace command line is flexible and fast. After being configured once, you can use the Systrace tool again in the platform- Tools directory of the Android-SDK. The following is a simple way to use the tool
$ cd android-sdk/platform-tools/systrace
$ python systrace.py
Copy the code
You can configure the corresponding path and Alias in Bash, and it’s pretty quick to use. In addition, the Systrce file captured by the User version contains less information than the ENG version or Userdebug version. It is recommended to use the machine with the Userdebug version for debugging, which not only ensures performance, but also provides more detailed output results.
After the capture is complete, the corresponding trace.html file is generated. Note that this file can only be opened by Chrome. We will discuss how to analyze Trace files in the following sections. Whatever tool you use, you can select parameters before fetching. Here’s what these parameters mean:
-
“-h”, –help Show the help message.
-
“-o” Write the HTML trace report to the specified file.
-
“-t” N, –time=N Trace activity for N seconds. The default value is 5 seconds.
-
“- b” N, –buf-size=N Use a trace buffer size of N kilobytes. This option lets you limit the total size of the data collected during a trace.
-
“-k“
-
“-ktrace” = Trace the activity of specific kernel functions, specified in a comma-separated list.
-
“-l”, –list-categories list the available category tags. The available tags are(下 载 标 签) Post the official explanation will also be more authoritative, we will see the parameters of the operation when the later analysis):
- “GFX” -graphics
- Input – input
- “View” – view
- webview – WebView
- Wm – Window Manager
- Am – Activity Manager
- audio – Audio
- video – Video
- camera – Camera
- hal – Hardware Modules
- res – Resource Loading
- Dalvik – Dalvik VM
- rs – RenderScript
- Sched – CPU Scheduling
- Freq: CPU Frequency
- Membus – Memory Bus Utilization
- Idle – CPU idle
- Disk – Disk input and output
- Load – CPU load
- Sync – Synchronization Manager
- “Workq” – Kernel Workqueues Note: Some trace categories are not supported on all devices. If you want to see the names of tasks in the trace output, you must include the sched category in your command parameters.
-
“-a“
-
“– app” = Enable tracing for applications, specified as a comma-separated list of package names. The apps must contain tracing instrumentation calls from the Trace class. For more information, see Analyzing Display and Performance.
-
“– link-assets” link to the original CSS or JavaScript resources instead of embedding them in the HTML trace report.
-
“– from-file” = Create the interactive Systrace report from a file, instead of running a live trace.
-
— asset-dir = Specify a directory for the trace report assets. This option is useful for maintaining a single set of assets for multiple Systrace reports.
-
“-e“
-
“– serial” = Conduct the trace on a specific connected device, identified by its device serial number. Although the above parameters are quite large, there is no need to consider so much when using the tool. You can check the corresponding item before the command line to manually add parameters:
We typically configure this command as Alias, as follows:
Alias st - start = 'python/SDK/platform - the tools/systrace/systrace py' alias st - start - GFX - trace = 8 GFX 'st - start - t input View Sched Freq WM am hwui workq res dalvik sync Disk Load Perf Hal RS idle MMC 'Copy the code
In this way, you can directly press “st-start”, of course, in order to distinguish and keep each file, also need to add “-o xxx.html”. The above commands and parameters do not need to be understood at once, just remember how to use them easily, and they will become familiar as you analyze them.
Generally speaking, it is more commonly used
- -o: indicates the path and name of the output file
- -t: capture time (the latest version can not be specified, press Enter to end)
- -b: Specifies the size of the buffer. (In general, the default buffer is sufficient. If you want to catch a long Trae, it is recommended to increase the buffer size.)
- -a: Specifies the app package name (if you want to Debug custom Trace points, remember to add this)
About my && blog
- About me, I really hope to communicate with you and make progress together.
- Blog Content navigation
- Excellent Blog Post record – Android performance optimization is a must
“A person can go faster, a group can go farther“
❝
For more information, check out Android Performance
❞
Reference
[1]
SysTrace official introduction: http://developer.android.com/tools/help/systrace.html
This article is formatted using MDNICE