Android performance Optimization--tools

Source: Internet
Author: User

Android performance optimization is a frequently encountered problem in Android development, next will be the Android performance optimization of knowledge points to do a simple comb and summary, will be from the tools and code two aspects of combing. The so-called 工欲善其事 its prerequisite, this article first look at the Android performance optimization has what powerful tools.


Traceviewtraceview is a tool that comes with the Android SDK, and it's a very important tool for Android performance optimization and analysis when it's time-consuming to make statistical analysis of method calls in your application. TraceView is located in the Tools directory under the SDK, can be used in the CMD window to run the TraceView command, can also be used in Ddms, I personally prefer the latter way, more convenient and easy to operate, do not need to modify the code.
How to use:
    • Method One: Call the Startmethodtracing and Stopmethodtracing methods respectively at the beginning and end of the corresponding TraceView analysis, as shown in the following example code:
public class Mainactivity extends Activity {@Overrideprotected void onCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main);D ebug.startmethodtracing ();} @Overrideprotected void OnDestroy () {Super.ondestroy ();D ebug.stopmethodtracing ();}}
The. trace file is generated after the end and the data file is parsed by the command TraceView *.trace. Startmethodtracing has a total of 6 overloaded methods that can be called as needed when called. If a method with no parameters is used, the resulting ". Trace" file is stored by default to the external memory root (/sdcard/), named "Dmtrace.trace", to facilitate the proposed custom trace name (Startmethodtracing ( String tracename)).
    • Method Two: TraceView can also be used directly in the DDMS, that is, in the DDMS in the selection of a process to be monitored, click on the small icon to start monitoring, at the end of the monitoring to click the small icon again, DDMS will automatically open TraceView view:


These two ways of use, each have advantages and disadvantages: The first monitoring process is more accurate, but need to modify the code, the second monitoring easy to use, do not need to modify the code, but step into the first precision. I am personally in the use of the general preference for the second way of use.
Visual schematic read: The following view is generated by monitoring the COM.TENCENT.MOBILEQQ process (randomly selected) in Ddms. It can be seen that the whole TraceView view is divided into two parts, the upper half being called Timeline Panels (Timeline panel), the lower part is referred to as the analysis panel.
    • Time Axis Panel
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: line widthRepresents the operation of the function itself. Time。 NOTE 2: The function that is called by the Sub-function time lineinclusion in the function itself OperationBetween the time lines used. Note 3: The Time Line HeightDo not know what is the point. Note 4: The function itself is NestingOf Note 5: The thick segments below each line mark the time period consumed by the selected function call in the profile panel. Each segment corresponds to the run of the function once.
    • Analysis Panel
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. Double click Name of function, you can see that the upper half of the interface is the time axis surface graph (Timeline Panel) to see what time period he is consuming. (marked with a coarse line). Double-click the function name to the left of the +"When you expand, you can see that the function's" Parentsand Children" column 2: "incl%"Represents the function's Inclusive TimeIn the whole methodtracingTime accounted for percentage。 Column 3:" Inclusive"represents Inclusive Time。 Column 4:" excl%"Represents the function's Exclusive TimeIn the whole methodtracingTime accounted for percentage。 Column 5:" Exclusive"represents Exclusive Time。 Column 6: "Calls+recurcalls/total" indicates the function's number of calls( 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 (e.g. 2.1) also has " Time/calls"represents avg. Call Time(i.e. inclusive time/total calls). 3. Figure 2 from Google Docs feels old. Note: If function A calls function B then function A is called function B. Parents", function B is called function A." children."

Google's introduction to TraceView tools can be consulted http://developer.android.com/intl/zh-cn/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.