I. Brief introduction of TraceView tools
TraceView is a good performance analysis tool equipped with Android platform. It allows us to understand the performance of the program we are tracking through a graphical interface and can be specific to method.
Second, TraceView tool use method
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;
Three, TraceView interface description
The graphical interface generated by the above steps is as follows:
Iv. TraceView Tool Example usage instructions
This example provides an example of how to use the TraceView tool in the process of selecting a set of listings in a city for a collection.
The procedure is as follows:
1. Start Eclipse and connect to the simulator;
2, in the simulator to start the home application, and open DDMS, check the process;
3, click the Start Profile Method button;
4, in the home to open a set of housing, waiting for the successful opening of the listing to view the large map and collection;
5. Clicking the Stop Profile Method button in Ddms will automatically pop up a graphical interface in Eclipse.
Sort by average call time (Time/calls) from large to small, see:
It is known that the average call time of the Detailactivityforpicture.oncreat () function is 4.034 seconds, a total of 1 calls, a relatively long call time, and the sub-functions it calls. Where the call time of the child function Detailactivityforpicture.initinfo () is 0.9s. The relative time is longer, and if you need to optimize performance, you need to optimize the initinfo () execution time.
Here's a look at the Detailactivityforpicture.initinfo () function's sub-function,
Further analysis of the Initfavoritebutton () call time is up to 0.4s. Go through the query in turn, see:
Dialogboxutil.getfavoritewindow () and Favoritepropertymodel. Functions can be optimized. As a result of the performance analysis, it is available for developers to refer to and to optimize performance.
Using TraceView for Android performance testing (GO)