TraceView of the Android Performance tuning tool

Source: Internet
Author: User

From January Google released 16 series of video on performance optimization, this period of time in the major communities have seen a lot of excellent articles about the optimization series. We have analyzed the causes of performance, shared how to optimize our applications, and introduced tools to help us detect performance issues.


One of the tools that is described in some of the system performance tuning tools: TraceView

TraceView is an Android platform equipped with a good performance analysis tool. It can be graphically let us understand the performance of the program we want to track, and can be specific to a function method of execution time.

Because the small LU did not use the tool before, so these two days also play a hand, the simple use of the tool to do a simple graphic introduction. Also hope that in the future work should pay attention to the use of the tool, good use of the tool.


First, how to use the tool to collect data
1, the first mode of use
① add code to the end of the code snippet you need to tune

Debug.startmethodtracing ("TraceView");  Debug.stopmethodtracing ();
If we want to trace between Mainactivity's OnCreate () and Ondestory () methods, 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);          /         * * will generate data performance in the SD card root directory capture file traceview.trace         * Note:         *     1, must be in the SD card debug phone or simulator use         *     2, add SD card access to read and Write permissions: <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 above the code will be on your phone or emulator SD card root directory generated file traceview.trace, such as:

③, before formally using the TraceView tool to analyze the data, we use the ADB command to export the Traceview.trace file under the SD card root directory to our local computer, the ADB command is as follows:

As above, I export the. trace file under My Computer C:\tmp

④, find our tool in {sdk}/tools/directory Traceview.bat, double-click to run him, it will be shown as follows:

Tip We use Android Device monitor<tools/monitor>.

   ⑤, but we execute the following command: TraceView Xxx.trace, Use TraceView to access the Execute. trace file
        
        The gang appears as follows:    & nbsp &NBSP;&NBSP
        
        based on previous commands:
      & nbsp Here we can also use the Execute Android Device monitor<tools/monitor> tool to see the following interface

        In this interface we can file--& Gt Open file opens the. trace file that you exported before, and you will see the same effect:

        Here we have done the data collection and use the TraceView tool to graphically display the data


  2, the second way of using
      This is much simpler than the first way
      by selecting the app in Devices and clicking the button Start Method Profiling (Open methods Analysis) and click Stop Method Profiling (Stop methods Analysis)  
 
      When the collection is stopped, DDMS automatically triggers the TraceView tool to explore the data collection


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

This part mainly includes:
1, TraceView tool Panel Mastery, analysis panel each column to do meaning such as: Name, incl CPU time, EXCL CPU time, incl Real time and so on.


2, how to locate the analysis we want to monitor the specific method (through the TraceView bottom of find to look for).
3, how to locate those time-consuming (leading to performance problems) method (filter out the method time-consuming, such as: Incl CPU, CPU time/call column).

4, finally according to find out the performance of the specific method, to do code optimization.

The content is far more than the above about the use of tool data collection, small Lu Yegang on the internet has collected two excellent information about the use of TraceView tools:
1, Android System Performance Tuning Tool Introduction: http://blog.csdn.net/innost/article/details/9008691
2, Android programming TraceView Introduction and the case of the actual combat: http://www.cnblogs.com/sunzn/p/3192231.html


Third, other
About Android Tuning tools in addition to TraceView, there are overdraw,systrace,strictmode,hierarchy Viewer and so on.

Good English skills on the Google official Internet café: http://developer.android.com/tools/debugging/debugging-tracing.html



TraceView of the Android Performance tuning tool

Related Article

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.