I knew I was in trouble, so I did.
What problems can Systrace analyze?
- Systrace is a platform provided tool for recording device activity over a short period of time. The tool generates a report that summarizes data from the Android kernel, such as CPU schedulers, disk activity, and application threads. This report can help you understand how best to improve the performance of your app or game.
- The Systrace report provides an overview of the system process on the Android device over a given period of time, and also examines the captured trace information to highlight issues it observes (such as interface lag or high power consumption).
- Recording traces is especially useful when addressing performance-related errors in your application, such as slow startup, slow conversion, or interface stuttering.
Systrace and Cpu profilers
Systrace and Cpu profiler are typically used together to analyze problems. The Systrace tool does not collect information about code execution in the application process. To get a detailed idea of what methods your application is executing and how much CPU resources it is consuming, use the CPU Profiler in AS. You can also use CPU profilers to generate trace logs, and then import and examine those logs.
Field experience
(1) Practical operation environment
- Optional, use your own environment and code as well
- SamplePop code download
- The SamplePop environment is as follows:
Android Studio 4.0 Gradle Version 6.1.1 Android API Version 30
(2) Use the command line to capture trace information
- Capture system trace information on the command line
- The systrace command is provided in the Android SDK Tools toolkit and is located in android-sdk/platform-tools/systrace/. The android-SDK path can be viewed in AS (File -> Project Structure) AS follows:
- Systrace / > systrace/ > systrace/ > systrace/ > systrace/ > systrace
$ python systrace.py --list-categories
Copy the code
- Run the systrace command line to generate an HTML report:
$ python systrace.py [options] [categories]
Copy the code
- If you are not familiar with the instructions in [], you can view the supported options:
$ python systrace.py --help
Copy the code
- Here’s an example: For applications with the package name com.kejiyuanren.systrace, log for 5 seconds and place the log report in the testSystrace01.html file in the root directory (if the -o option is not specified, Android-sdk /platform-tools/systrace/
$ python systrace.py -t 5 -a com.kejiyuanren.systrace -o ~/testSystrace01.html
Copy the code
- Ok, so you’ve got the command line to capture system information
(3) Use equipment to capture tracking records
- System trace records are captured directly on the device
Watch the above command line recording, some partners are not happy, command line does not like. Devices running Android 9 (API level 28) or later include a system-level application called System Trace. This application is similar to the Systrace command-line utility above, but allows you to record traces directly from the test device itself without having to plug in the device and connect to it through ADB. You can then use this application to share the results from these traces with the development team.
- System tracking function recording
- Share system trace records
1. Message sharing: By clicking on a notification, tracing records can be sent to the development team via email or an error-tracking app, without the need to connect the device to the development computer.
2. Use ADB to download the report (pull command) :
The Perfetto tool is recommended (you can import directly, so you don’t need to create HTML reports)
3. Create HTML reports
$python systrace.py --from-file=<pull. Perfetto-trace > -o < HTML report path >Copy the code
(4) Custom events
- Systrace only displays information about progress at the system level, so it is sometimes difficult to know which methods of the application or game are being executed relative to system events at a given time. The Android platform provides a trace API that can be used to tag specific code snippets.
- Then specify the package name on the command line
-a
Otherwise, the added custom event cannot be captured.
$ python systrace.py -t 5 -a com.kejiyuanren.systrace -o ~/testSystrace02.html
Copy the code
- Systrace User-defined events Precautions:
When you call beginSection() more than once, calling endSection() only terminates the most recently called beginSection() method. Therefore, for nested calls (as in the following code snippet), make sure that each call to beginSection() matches the call to endSection() correctly. You cannot call beginSection() on one thread and terminate it from another thread; You must call both methods in the same thread.
Xiaobian extension links
- SamplePop code download
- Android Performance Optimization family Bucket
Refer to the link
- Google -> Command line reference
- Google official website -> “System Tracking” system application
- Google official website -> Define custom events
Everywhere golden fragrant, a party of spring drunk qianshan
❤ ❤ than heart