Traceview of Android debugging tools

Source: Internet
Author: User
Traceview is a good performance analysis tool on the Android platform. It allows us to understand what we want to track in a graphical way.ProgramAnd can be specific to the method. Traceview version restrictions For Android 1.5 And the following versions: Not Supported . For For Android 1.5 Above 2.1 Versions below (including 2.1: Limited support . The trace file can only be generated SD card And must be added to the program Code . For For Android 2.2 Version above (including 2.2): all supported. Yes No SD card You do not need to add code in the program. You can use ddms to trace the process. 1. Use traceview in Android 1.5 or above 2.1 (including 2.1) versions First, you must add code to the program to generate a trace file. With this trace file, we can convert it into a graph. 1.1,Start tracing Use the following static method of DEBUG to start: static void Startmethodtracing (String tracename) Start Method Tracing, specifying the trace log file name. Trace static void by specifying the trace file name and default maximum capacity (8 MB) Startmethodtracing () Start Method Tracing with default log name and buffer size. Use the default trace file name (dmtrace. Trace) and default maximum capacity (8 Mb) to start Method Tracing static void Startmethodtracing (String tracename, int buffersize, int flags) Start Method Tracing, specifying the trace log file name and the buffer size. start tracing by specifying the trace file name and the maximum capacity. You can also specify flags. Note: int flags seems meaningless. Generally, 0. Static void is used. Startmethodtracing (String tracename, int buffersize) Start Method Tracing, specifying the trace log file name and the buffer size. Trace the method by specifying the trace file name and maximum capacity. NOTE 1: The above method files are created under the SD card, that is, under "/sdcard/", the default file name is "/sdcard/dmtrace. trace "if there is no SD card, the above method will throw an exception and cause the program crash. NOTE 2: If the file name does not specify a type, the system adds the type to it. trace 1.2,Stop Tracing Use the static Debug Method to stop: public static void Stopmethodtracing (). For example, add Debug. startmethodtracing () to oncreate () of the activity, 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 have to create an AVD with an SD card so that the trace file can be saved to/sdcard. You can create sdcard separately in the command, or you can create sdcard together when creating AVD. After the creation, we can see a trace file in the/sdcard/directory through the ddms file named E. If the name is not set in the debug statement, the default value is dmtrace. Trace. 1.3,Copy the trace file from the SD card to your computer. Now we copy this file to the specified directory on our computer: ADB pull/sdcard/dmtrace. Trace D: 1.4,Start the traceview Visual Interface Now you can run traceview through the command line. Go to the SDK tools directory and run traceview as follows: traceview D: \ dmtrace. Trace. Then you can see the graphical interface. 1.5,AnalysisTraceview results Timeline panel The upper part of the window is the Timeline panel) The image below shows a close up of The Timeline panel. each thread's execution is shown in its own row, with time increasing to the right. each method is shown in another color (colors are reused in a round-robin fashion starting with the methods that have the most random time ). the thin lines underneath the first row show the extent (entry to exit) of all the callto the selected method. The ruler at the top of the interface represents the time period of methodtracing (from Debug. startmethodtracing () to debug. stopmethodtracing ). Function execution in each thread Time chart In and Thread name in the same row . Note 1 : Line width Used to execute the function itself. Time . Note 2 : Subfunction timeline Included in this function Operations Between the time series used. Note 3 : Timeline Height I don't know what it means. Note 4 : The function itself is Nesting . Note 5 : The rough line segments under each line indicate the time period consumed by the selected function call in the profile panel. Each line segment corresponds to the running of the functions. In the figure below, we can see 11 calls to loadlistener. nativefinished (), one of which consumes a lot of time. The 11 times here are inconsistent with Figure 2. It should be Google's negligence. Figure 1 The traceview Timeline panel

 

profile panel The lower half of the window is a summary of each function call. Profile panel Figure 2 shows the profile 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. implicit 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 is selected (by clicking on it), it expands to show the parents and children. parents are shown with a purple background and children with a yellow background. the last column in The table shows the number of callto this method plus the number of recursive CILS. the last column shows the number of callout of the total number of callmade to that method. in this view, we can see that there were 14 callto loadlistener. nativefinished (); looking at the Timeline panel shows that one of those CILS took an unusually long time. figure 2 calls each function Summary Figure profile panel. This table shows the full and exclusive times and their percentages. Exclusive time Is the function itself Basic operations( Not includedThe time when the sub-function is called. Hybrid time Is the time ( IncludingThe time when the sub-function is called. Column 1 :" Name "Indicates the function name. Double-click Function Name In the upper part of the page, you can see that the time consumed by the Timeline panel is displayed. (Marked with a rough line segment ). Double-click" + "After expansion, you can see that the function's" Parents "And" Children " Column 2 : "Incl % "Indicates the function's Hybrid time In Entire methodtracing Time Percentage . Column 3 :" Comprehensive "Indicates Hybrid time . Column 4 :" Excl % "Indicates the function's Exclusive time In Entire methodtracing Time Percentage . Column 5 :" Exclusive "Indicates Exclusive time . Column 6 : "CILS + recurcils/total" indicates Number of calls ( Including recursive calls ). The nativefinished () column of 2 "14 + 0" indicates 14 non-recursive calls and 0 recursive calls. Column 7 : New versions (such as 2.1) and" Time/CILS "Indicates Average Call time (That is, random time/total cballs ). 3. Figure 2 from the Google documentation feels old. Note : If function a calls function B, function a is called function B" Parents ", Function B is called function" Children. "

Below is the translation

English Chinese
Incl Call method usage time percentage
Comprehensive Call method time (MS) (including calls to all methods)
Excl Percentage of time consumed by the execution Method
Exclusive Time used for method execution (MS) (excluding calls to sub-methods)
Cballs + recur cballs/Total Number of calls and repeated calls
Time/call Total time (MS)
Figure 2 : Profile panel Figure 3 : Profile panel

  Ii. simplify the use of traceview in Android 2.2 or later versions. In addition to using traceview as in Android 2.2 Use traceview for ddms , Much simpler than before. * The trace log files are streamed directly to your development machine. SD cards are not required after Android 2.2. Traceview File streams direct to the Development and debugging host. (That is, the computer where ddms is located) To start method profiling: 1. On the devices tab, select the process that you want to enable method profiling. 2. Click the start method profiling button. 3. interact with your application to start the methods that you want to profile. 4. Click the stop method profiling button. ddms stops profiling your application and opens traceview with the method profiling information that was collected between the time you clicked on start method profiling and stop method profiling. How to perform traceview in ddms. 1 , In the device table Selected You want to perform method Trace Process . 2 , Click Method profiling Start method Trace. The button is in the upper left corner of the window. It is in the left corner of the "stop" button and is in the lower right corner of the device menu ".3 , Method Trace In progress . 4 , Click method profiling Button stop Method trace. Then the traceview window is automatically displayed to display the method Trace result. Iii. traceview File Format For details about the traceview file format, refer to examples.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.