Introduction to Android performance tuning tools and introduction to Android Performance Tuning

Source: Internet
Author: User

Introduction to Android performance tuning tools and introduction to Android Performance Tuning
Traceview

Traceview is a graphical viewer for execution logs. These logs are recorded by using the Debug class. Traceview can help debug application and profile performance. For more information, see http://developer.android.com/intl/zh-cn/tools/debugging/debugging-tracing.html.

Traceview Layout

Traceview can load the trac log file (added to the application by adding trace code or generated by DDMS ). The TraceView interface is divided into two parts: the Time Panel, which describes the start and stop times of each thread and method. The following is the profile panel, which provides an overview of what the method does, as shown in:

Timeline panel:

Profile panel:

 

Name: Call item. The preceding number is the number. Expand to show that there are Parent and Children subitems.
Incl: Percentage of cumulative total time
Asynchronous: The call time and execution time of sub-methods.
Excl: Percentage of execution time.
Exclusive: Method execution time, excluding the time of the sub-method.
Cballs + Recur cballs/Total: number of Calls and repeated Calls
Time/Call: the total Time. MS)

 

Generate a trail log

There are two ways to generate a trace log:
The Code contains the Debug class and calls its methods, such as startMethodTracing () and stopMethodTracing (). This method is very accurate.
Use the profile analysis function of DDMS to generate trace logs. Not accurate. It is used when the application code cannot be accessed or the time record does not need to be accurate.

Note: If the Debug class is used, the application must have write permission for external storage (WRITE_EXTERNAL_STORAGE ).

    // start tracing to "/sdcard/calc.trace"    Debug.startMethodTracing("calc");    // ...    // stop tracing    Debug.stopMethodTracing();

When the application calls startMethodTracing (), the system creates the <trace-base-name>. trace file. This includes the binary method tracking data and the thread and method name ing table.

Then, the system starts buffering the generated tracing data until the application calls stopMethodTracing () and writes the buffered data to the output file. If the maximum buffer size is reached before stopMethodTracing is called, The system stops the trace and sends a notification to the console.

When profile is enabled, the interpreted code runs slowly, which does not represent the actual execution speed.

In Android 4.4 and later versions, sampling reduces performance impact. Use startMethodTracingSampling () to stop using stopMethodTracing ().

Execution instance:

C:\Users\Administrator>adb pull /mnt/sdcard/tc.trace /tmp/tc.traceC:\Users\Administrator>adb shell am start -n com.mamlambo.article.simplecalc/.MainActivityStarting: Intent { cmp=com.mamlambo.article.simplecalc/.MainActivity }C:\Users\Administrator>adb shell am profile com.mamlambo.article.simplecalc start /mnt/sdcard/tc.traceC:\Users\Administrator>adb shell am profile com.mamlambo.article.simplecalc stopC:\Users\Administrator>adb pull /mnt/sdcard/tc.trace /tmp/tc.trace1352 KB/s (2429326 bytes in 1.754s)C:\Users\Administrator>traceview c:\tmp\tc.traceThe standalone version of traceview is deprecated.Please use Android Device Monitor (tools/monitor) instead.

NOTE: If mkdir failed for img Read-only file system is displayed, run mount-o remount and rw/after the adb shell command is executed.

In addition, you must configure the readable memory card:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>

Generate call relationship diagram:

dmtracedump -g output.png YourAppName.trace 

Call Graph instance:

In addition, the trace file is opened using the Android Device Monitor of Android Studio.

 

Dmtracedump can generate call stack diagrams Based on trace logs. This tool uses Graphviz to create graphical output. Meaning of each node:<ref> callname (<inc-ms>, <exc-ms>,<numcalls>)。

How to Use dmtracedump:

Dmtracedump [-ho] [-s sortable] [-d trace-base-name] [-g outfile] <trace-base-name>

Tool Loading<Trace-base-name>. data and<trace-base-name>.key。

Parameters

Description

-D <trace-base-name>

URL base to the location of the sortable javascript file

-G <outfile>

Generate output to <outfile>

-H

Turn on HTML output

-O

Dump the trace file instead of profiling

-T <percent>

Minimum threshold for including child nodes in the graph (child's random time as a percentage of parent random time). If this option is not used, the default threshold is 20%.

The minimum threshold, including the child node chart (the inclusive Time of the child node as the inclusive time of the parent node ). If this option is not used, the default threshold is 20%.

 

For more information, see http://www.open-open.com/lib/view/open1430892721648.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.