[Android] Android TraceView Tool Use

Source: Internet
Author: User

One, select the tracking range

Use the following two lines of code between the code snippets that you want to base

    1. Debug.startmethodtracing ("Love_world_");
    2. Debug.stopmethodtracing ();

For example, the method trace between the OnCreate and the OnStart method

    1. public class mainactivity extends activity {
    2.      @Override
    3.     protected void oncreate (Bundle  savedinstancestate)  {
    4.         super.oncreate ( Savedinstancestate);
    5.         setcontentview (r.layout.activity_main);
    6.         debug.startmethodtracing ("Love_world_");
    7.     }
    8.      @Override
    9.     protected void  OnStart ()  {
    10.         super.onstart ();
    11.         debug.stopmethodtracing ();
    12.     }
    13. }

Second, add SD card access rights

    1. <uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/>
    2. <uses-permission android:name= "Android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>

If you do not add, the following exception occurs when you execute the project

    1. java.lang.RuntimeException:Unable to open trace file '/mnt/sdcard/love_world_.trace ': Permission denied

Third, export the TraceView file

1 Execute the project first to see if the trace file is generated
Enter Shell mode

    1. ADB shell

See if this file has been generated

    1. LS Sdcard/love_world_.trace

Ctrl + C exits adb shell mode

2 Exporting trace files

    1. ADB pull Sdcard/love_world_.trace

Iv. Opening trace files

Opening the trace file requires Android to provide the Traceview.bat tool, the directory where the tool is located: Sdk\tools\traceview.bat, which is performed in two ways:
1) switch to this directory on the command line
2) Add this directory to the system environment variable

    1. CMD executes in the directory where Calc.trace is located
    2. TraceView C:\Users\YourName\Desktop\Love_World_.trace

where "C:\Users\YourName\Desktop\" means that the trace is located in the directory on your system, this tool needs to enter the absolute path of the trace file.

V. Use of TraceView Tools

There are two ways to use:

1 Review the execution time of the tracking code and analyze what is a time-consuming operation

2 can be used to track calls to methods, especially the method call relationships of the Android framework layer

Get the call order of a method

1. The method name of the search response in TraceView cannot use uppercase letters

2. The search method is automatically expanded, which contains two sets of information, parents and children

3. Click on the method name under parents and jump directly to the method where you are calling. Children opposite

Vi. Exception Handling
1 Exception handling

    1. ' C:\Windows\system32\java.exe ' is not an internal or external command, nor is it a running program
    2. or batch file.
    3. SWT folder ' does not exist.
    4. Please set ANDROID_SWT-to-the folder containing Swt.jar for your PLATFO
    5. Rm.

Configure Java environment variables to add Java bin to the system environment variable path

2 Exception information

    1. the standalone version of traceview is deprecated.
    2. please use android device monitor  (Tools/monitor)  instead.
    3. Failed to read the trace filejava.io.ioexception: key section does  not have an *
    4. end marker
    5.          at com.android.traceview.dmtracereader.parsekeys (dmtracereader.java:420)
    6.         at com.android.traceview.dmtracereader.generatetrees ( Dmtracereader.java:
    7. ()
    8.         at  Com.android.traceview.dmtracereader.<init> (dmtracereader.java:87)
    9.          at com.android.traceview.mainwindow.main (mainwindow.java:286)

Usually the trace file has an exception, and then it is rebuilt and exported try

Vii. Related information:

Android Code debugging tool TraceView and Dmtracedump's twist deduction

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.