TraceView is a good performance analysis tool equipped with Android platform. It can be graphically used to let us know the performance of the program we want to track, and can be specific to method.
Version restrictions for TraceView
For Android 1.5 and the following versions: not supported .
For Android 1.5 above 2.1 (with 2.1) version: Limited support . Trace files can only be generated to an SD card , and you must include code in the program.
For Android 2.2 (with 2.2) version: full support. Can not use the SD card , do not add code in the program, directly with their own DDMS can process TraceView.
One, Android 1.5 above 2.1 under (including 2.1) version of the use of TraceView
First, the code must be added to the program to generate the trace file that we can convert to a graph with this trace file.
1.1. Start tracking
Use the following static method method of debug to start:
static void startmethodtracing(String tracename)
Start method tracing, specifying the trace log file name.
Start the tracing of the method using the name of the specified trace file and the default maximum capacity (8M)
static void startmethodtracing()
Start method tracing with default log name and buffer size.
Start the tracing of the method using the default trace file name (dmtrace.trace) and the default maximum capacity (8M)
static void startmethodtracing(String tracename, int buffersize, int flags)
Start method tracing, specifying the trace log file name and the buffer size.
Starts the tracing of the method using the name of the specified trace file and the maximum capacity. And you can specify flags.
NOTE: int flags doesn't seem to make sense. It is usually used in 0.
static void startmethodtracing(String tracename, int buffersize)
Start method tracing, specifying the trace log file name and the buffer size.
Starts the tracing of the method using the name of the specified trace file and the maximum capacity.
Note 1: The above method of the file will be created under the SD card, that is, "/sdcard/", the default file name is "/sdcard/dmtrace.trace"
If there is no SD card, the above method will throw abnormal cause the program crash.
NOTE 2: If the file name does not specify a type, the system adds a type to it. Trace
1.2. Stop Tracking
Use the static method method of debug to stop:
public static void stopmethodtracing ().
For example, add debug.startmethodtracing () to the activity's OnCreate (), and add debug.stopmethodtracing () to OnDestroy (),
As follows:
@Override
public void onCreate(Bundle savedinstancestate) {
Debug.startmethodtracing ();
Super.oncreate (savedinstancestate);
..............................
}
protected void OnDestroy() {
Super.ondestroy ();
.................
Debug.stopmethodtracing ();
}
For the simulator we also have to create an AVD with an SD card so that the trace file can be saved to/sdcard/... Of
They can be created separately in the command, or they can be created together with the sdcard when creating the AVD. After creation through the Ddms file explore we can see a trace file under the/sdcard/directory, and the default is Dmtrace.trace if the name is not set in the debug statement.
1.3. copy trace files from SD card to computer
Now we copy this file to the specified directory on our computer:
ADB pull/sdcard/dmtrace.trace D:
1.4. Start TraceView Visual interface
You can now execute TraceView from the command line. After entering the tools directory of the SDK, execute the TraceView as follows:
TraceView D:\dmtrace.trace.
After that, you can see the graphical interface.
1.5. Analysis of traceview results
Timeline Panel
The top half of the window is the timeline plane (Timeline Panel)
The image below shows a close up of the timeline panel. Each thread's execution is shown in it own row, with time increasing to the right.
Each method is shown in another color (colors be reused in a round-robin fashion starting with the methods that has the Most inclusive time).
The thin lines underneath the first row show the extent (entry to exit) of the calls to the selected method.
The ruler above the interface represents the time period of the methodtracing (from Debug.startmethodtracing () to Debug.stopmethodtracing ().
function execution for each thread Time Chart in and Line Cheng Row to the right.
Note 1: The line width represents the time taken to perform the operation of the function itself.
NOTE 2: The function calls a sub-function that is interspersed between the time lines that the function itself operates on.
Note 3: The height of the timeline does not know what the meaning is.
Note 4: The function itself is nested .
Note 5: the coarse segment below each line marks the time period consumed by the selected function call in the profile panel. Each segment corresponds to the run of the function once.
In the figure below we can see that there are 11 calls to loadlistener.nativefinished (), one of which is particularly time-consuming. Here are 11 times and Figure 2 is not consistent, it should be Google's negligence.
Figure 1 The Traceview Timeline Panel
Profile Panel
The bottom half of the window is a summary of each function call the profile Panel
Figure 2 shows the Profiles pane, a summary of all the time spent in a method.
The table shows both the inclusive and exclusive times (as well as the percentage of the total time).
Exclusive time is the time spent in the method.
Inclusive time is the time spent in the method plus the time spent in any called functions.
We refer to calling methods as "parents" and called methods as "children." When a method was selected (by clicking on it),
It expands to show the parents and children. Parents is shown with a purple background and children with a yellow background.
The last column, the table shows the number of calls to this method plus the number of recursive calls.
The last column shows the number of calls out of the total number of calls made to the.
In this view, we can see that there were-calls to loadlistener.nativefinished ();
Looking at the timeline panel shows that one of the those calls took an unusually long time.
Figure 2 is a summary of the individual function calls to the profile Panel. The table gives the inclusive and exclusive times and their percentages.
Exclusive Time is the time of the basic operation of the function itself ( excluding child function calls).
Inclusive Time is the time that the function call took ( including the child function call).
column 1: "name" indicates the function name.
By double-clicking the function name , you can see that the upper half of the interface is the time axis of the timeline (Timeline Panel) to see what time period he is consuming. (marked with a coarse line).
When you double-click the "+" extension to the left of the function name, you can see that the function's "parents" and "children"
column 2:"incl%" represents the percentage of the function's Inclusive time for the entire methodtracing .
column 3: "Inclusive" represents Inclusivetime.
column 4: "excl%" represents the percentage of the function's Exclusive time for the entire methodtracing .
column 5: "Exclusive" represents Exclusivetime.
column 6: "Calls+recurcalls/total" indicates the number of calls to the function ( including recursive calls ). The 2 nativefinished () that is listed as "14+0" represents 14 non-recursive calls and 0 recursive calls.
Column 7: The new version (for example, 2.1) and "time/calls" mean the average call time (that is, inclusive time/total calls). 3. Figure 2 from Google Docs feels old.
Note : If function A calls function B then function A is called "parents" of function B, and function B is called "children" of function A.
Here is the translation
English |
Chinese |
Incl |
Call method Elapsed Time Percentage |
Inclusive |
Call method Time (MS) (including calls to all methods) |
Excl |
Percentage of execution method occupation time |
Exclusive |
Execution method Elapsed Time (ms) (not including calls to child methods) |
Calls+recur Calls/total |
Number of calls and repeated calls |
Time/call |
Total time (MS) |
Figure 2: ProfilePanel
Figure 3: ProfilePanel
Second, Android more than 2.2 (including 2.2) version of the simplified use of traceview.
Android 2.2, in addition to using traceview like 2.1, can also use TraceView in Ddms, much simpler than before.
* The trace log files is streamed directly to your development.
You can use the SD card after Android 2.2. Traceview The file stream is directed directly to the host that is developing the debug (that is, the computer where DDMS resides)
To Start method profiling:
1. On the Devices tab, select the process so you want to enable method profiling for.
2. Click the Start Method Profiling button.
3. Interact with your application-to-start the methods that's want to profile.
4. Click the Stop Method Profiling button. DDMS stops profiling your application and opens Traceview with the method profiling information it was collected between The time clicked on Start method Profiling and Stop method Profiling.
How to do TraceView in DDMS.
1, in the device table, Select the process you want to make method trace.
2, click the method Profiling button to Start method trace. The button is at the top left of the window, which is on the left side of the stop button, just below the device menu.
3, method trace is in progress .
4. Click the method Profiling button to stop the method trace. The system automatically pops up the TraceView window to display the method trace results just now.
Iii.. traceview file format
For TraceView file format please refer to http://developer.android.com/guide/developing/debugging/debugging-tracing.html
Four, How to use TraceView tools
TraceView has three kinds of start-up methods, which are described below:
1. Start in code
Can be added in code
Debug.startmethodtracing ("TraceLog");
Debug.stopmethodtracing ();
Use this method to ensure that the read and write permissions for the SD card in the application's androidmainfest.xml are open, i.e.
After the application runs, a tracelog file is generated under the SD card, the file is copied to the XP system using ADB pull, and the TraceView TraceLog is executed under the tools directory of the Android SDK, a graphical interface pops up. Through this graphical interface, we can analyze the performance bottleneck of the application;
2. Launch in Eclipse
Eclipse startup TraceView and its simplicity, click on the following button in DDMS for the application process that needs analysis
If you click the same button where you need to stop TraceView, Eclipse will automatically pop up a graphical interface similar to 1;
3. ADB command line Startup
ADB shell AM profile start
ADB Shell AM profile stop
PROCESS_ID is the application's process number, which can be obtained with the PS command, Trace_file is the Trcaelog file that needs to be stored.
After executing the above command, a corresponding Trace_file is generated, the file is copied to the XP system using ADB pull, and the TraceView TraceLog is executed under the tools directory of the Android SDK, a graphical interface pops up. Through this graphical interface, we can analyze the performance bottleneck of the application;
This article references the source:
http://wbdban.javaeye.com/blog/564309
Http://developer.android.com/guide/developing/debugging/debugging-tracing.html
Http://developer.android.com/guide/developing/debugging/ddms.html#profiling
About Android TraceView