TraceView and androidtraceview of Android Performance Tuning Tool

Source: Internet
Author: User

TraceView and androidtraceview of Android Performance Tuning Tool

Since the 16 Performance Optimization series Videos released by Google in January, many excellent articles on the optimization series have been found in major communities during this time. I have analyzed the causes of performance, shared how to optimize our applications, and introduced some tools to help us detect performance problems.


One of the tools described in the system tuning tools is TraceView.

TraceView is a good performance analysis tool on the Android platform. It allows us to understand the performance of the program we want to track in a graphical way, and can be specific to the execution time of a function method.

Because Mr. Lu has never used this tool before, he has tried it over the past two days and made a simple introduction to the simple use of this tool. We also hope to pay attention to the use of this tool and make good use of it in future work.


I. How to use this tool to collect data
1. method 1
① Add code at the beginning and end of the code snippet you need to adjust

Debug.startMethodTracing("traceView");  Debug.stopMethodTracing();
If we want to track the onCreate () and onDestory () Methods of MainActivity, the code can be as follows:
Public class MainActivity extends Activity {@ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main);/** the data performance collection file traceView will be generated in the root directory of the SD card. trace * Note: * 1. Be sure to use the mobile phone or simulator with SD card debugging * 2. Add the SD card read/write permission: <uses-permission android: name = "android. permission. WRITE_EXTERNAL_STORAGE "/> */Debug. startMethodTracing ("traceView");} @ Override protected void onStart () {super. onStart (); Debug. stopMethodTracing () ;}}< span style = "font-family: 'comic Sans Ms'; background-color: rgb (255,255,255);"> </span>
② When the program runs the preceding code, the traceView. trace file will be generated in the root directory of your mobile phone or simulator's SD card, for example:

③ Before using the traceview tool to analyze data, we use the adb command to export the traceView. trace file under the root directory of the SD card to our local computer. The adb command is as follows:

The above command exports the. trace file to my computer C: \ tmp.

④ Find traceview. bat in the {sdk}/tools/directory and double-click it to run it. The following figure is displayed:

The following message is displayed: Android Device Monitor <tools/monitor>.

⑤ But we execute the following command: traceview xxx. trace, and use traceview to access the execution. trace file.

The following figure shows the effect of a group:

Follow the prompts in the previous command:
Here, you can also run the Android Device Monitor <tools/monitor> tool to display the following interface:

In this interface, we can use file --> open file to open the exported. trace file, and then we will see the same effect:

This completes data collection and graphical display of data using traceview


2. method 2
This is much simpler than the first method.
Click Start Method Profiling (enable Method Analysis) and Stop Method Profiling (Stop Method Analysis) After selecting an application in Devices)
 
When collection is stopped, DDMS automatically triggers the Traceview tool to view collected data.


Ii. How to use this tool to analyze data
When we see the graphical trace data, we need to know how to understand the above data to make the correct analysis, finally find performance problems in the analysis, and finally solve the problem from the code.

This part mainly includes:
1. Grasp the TraceView tool panel and analyze the meaning of the to-do list in each column of the Panel, such as Name, Incl Cpu Time, Excl Cpu Time, and Incl Real Time.


2. How to locate and analyze the specific method we want to monitor (by finding at the bottom of TraceView ).
3. How to locate the Time-consuming (resulting in performance problems) methods (filter out the Time-consuming ranking of methods, such as the Incl Cpu Time column and Cpu Time/Call column ).

4. Finally, we can find out specific methods with defects in performance and optimize the code.

The content here is much more than the previous introduction to data collection tools. Mr. Lu has just collected two excellent articles on the Internet about how to use TraceView tools:
1. Android system performance tuning tool Introduction: http://blog.csdn.net/innost/article/details/9008691
2. TraceView in Android programming and its case practice: http://www.cnblogs.com/sunzn/p/3192231.html


Iii. Others
In addition to TraceView, the optimization tools for Android include Overdraw, Systrace, StrictMode, and Hierarchy Viewer.

Good English ability on Google official internet cafe: http://developer.android.com/tools/debugging/debugging-tracing.html



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.