1. Must be opened with chrome
2. On Mac computers, it may be that chrome is open and blank, the solution is: enter "Chrome:tracing" in the Chrome address bar, then click the Load button to load your trace.html file.
Systrace Brief Introduction
Systrace is the new performance data sampling and analysis tool in Android4.1. It helps developers to gather operational information from key Android subsystems (such as Surfaceflinger, Windowmanagerservice, and other framework-critical modules, services, view systems, etc.) to help developers more intuitively analyze system bottlenecks. Improve performance.
The Systrace features include tracking system I/O operations, kernel work queues, CPU load, and the health of various Android subsystems. In the Android platform, it consists mainly of 3 parts:
- Kernel part: Systrace leverages the Ftrace functionality in Linux kernel. Therefore, if you want to use Systrace, you must turn on kernel and ftrace related modules.
- Data Acquisition Section: Android defines a Trace class. The application can use this class to output statistics to ftrace. At the same time, Android also has a atrace program, which can read statistics from the ftrace and then hand it to the data analysis tool to handle.
- Data Analysis Tool: Android provides a systrace.py (Python script file, located in the Android SDK directory/tools/systrace, which internally calls the Atrace program) to configure how data is collected, such as the label Output file name, etc.) and collect ftrace statistics and generate a result page file for users to view. Essentially, Systrace is the encapsulation of ftrace in Linux kernel. The application process needs to use the Trace class provided by Android to Systrace.
The official introduction and use of Systrace can be seen here: systrace
Systrace Simple to use
Before using Systrace, you should first understand the use of systrace on each platform, given the majority of people using Eclipse and Android studio, so directly excerpt from the official website about this method of use, but no matter what tool, the process is the same:
- Your phone is ready for the interface you want to crawl
- Click to start crawling (command line is to start executing commands)
- Start operation on the phone
- After the set time is up, the trace file will be generated and the file will be opened for analysis using Chrome.
Using Eclipse
-
In Eclipse, open an Android application project.
- Switch to the DDMS perspective, by selecting Window > Perspectives > DDMS.
- In the Devices tab, select the device on which to run a trace. If no devices was listed, make sure your device was connected via USB cable and that debugging was enabled on the device.
- Click the Systrace icon at the top of the Devices panel to configure tracing.
- Set The tracing options and click OK to start the trace.
Using Android Studio
-
In Android Studio, open an Android application project.
- Open the Device Monitor by selecting Tools > Android > Monitor.
- In the Devices tab, select the device on which to run a trace. If no devices was listed, make sure your device was connected via USB cable and that debugging was enabled on the device.
- Click the Systrace icon at the top of the Devices panel to configure tracing.
- Set The tracing options and click OK to start the trace.
Using Device Monitor
-
Navigate to your SDK tools/directory.
- Run the monitor program.
- In the Devices tab, select the device on which to run a trace. If no devices was listed, make sure your device was connected via USB cable and that debugging was enabled on the device.
- Click the Systrace icon at the top of the Devices panel to configure tracing.
- Set The tracing options and click OK to start the trace.
Command Line Usage
The command line form is more flexible, the speed is also relatively fast, once the configuration is good, later in the use of the time will soon be the result (highly recommended)
12 |
$ cd android-sdk/platform-tools/systrace$ python systrace. py--time=10-o mynewtrace. HTML sched GFX View WM |
From the above command you can see the location of the Systrace tool, just configure the corresponding path and alias in Bash, which is very fast to use. In addition, the user version is not to catch trace, only the ENG version or Userdebug version can be.
After the crawl is finished, the corresponding trace file is generated, noting that the file can only be opened by Chrome. For an analysis of trace files, we will talk about them in the following chapters. Regardless of which tool you use, you'll have to choose parameters before crawling, and here's what these parameters mean:
- -h,–help Show the help message.
- -O Write the HTML trace report to the specified file. (that is, the output file name,)
- -T n,–time=n Trace activity for N seconds. The default value is 5 seconds. (Trace fetch time, typically:-T 8)
- -B n,–buf-size=n Use a trace buffer size of N kilobytes. This option lets your 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 tracing category tags. The available tags are (the following parameters do not have to translate the estimate you can also understand, the official interpretation will be more authoritative, the analysis later when we will see these parameters of the job):
- 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 VMS
- 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 is not supported on all devices. Tip:if want to see the names of the "the" in the "Trace" output, you must include the Sched category in your command parame Ters.
-
-A
- -app= Enable Tracing for applications, specified as a comma-separated list of the 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 was useful for maintaining a single set of assets for multiple Systrace reports.
- -E
- -serial= conduct the trace on a specific connected device, and identified by its device serial number.
Although the above parameters are more, but the use of tools do not need to consider so much, in the corresponding project before the hook can be, command line when the manual parameter:
We will typically configure this command as alias, configured as follows:
alias st-start= ' python/home/gaojianwu/software/android-studio/sdk/platform-tools/systrace/systrace.py ' Span class= "line" >alias st-start-gfx-trace = ' St-start-t 8 gfx input span class= "keyword" >view sched freq wm am Hwui workq res dalvik sync disk loa D perf Hal Rs idle mmc '
This way in use, you can directly knock st-start-gfx-mx4, of course, in order to distinguish and maintain each file, but also need to add-o xxx. Trace. The above commands and parameters do not need to be understood at once, just remember how to use them easily, and in the process of analysis, these things will be familiar.
Transferred from: http://blog.csdn.net/hard_working1/article/details/50602345
Android Performance Optimization Systrace tool Introduction (i) _&& Systrace generated trace.html open Blank or cannot open the solution