One, select the tracking range
Use the following two lines of code between the code snippets that you want to base
- Debug.startmethodtracing ("Love_world_");
- Debug.stopmethodtracing ();
For example, the method trace between the OnCreate and the OnStart method
- public class mainactivity extends activity {
-
- @Override
- protected void oncreate (Bundle savedinstancestate) {
- super.oncreate ( Savedinstancestate);
- setcontentview (r.layout.activity_main);
-
- debug.startmethodtracing ("Love_world_");
- }
-
- @Override
- protected void OnStart () {
- super.onstart ();
-
- debug.stopmethodtracing ();
- }
-
- }
Second, add SD card access rights
- <uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/>
- <uses-permission android:name= "Android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
If you do not add, the following exception occurs when you execute the project
- 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
- ADB shell
See if this file has been generated
- LS Sdcard/love_world_.trace
Ctrl + C exits adb shell mode
2 Exporting trace files
- 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
- CMD executes in the directory where Calc.trace is located
- 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
- ' C:\Windows\system32\java.exe ' is not an internal or external command, nor is it a running program
- or batch file.
- SWT folder ' does not exist.
- Please set ANDROID_SWT-to-the folder containing Swt.jar for your PLATFO
- Rm.
Configure Java environment variables to add Java bin to the system environment variable path
2 Exception information
- the standalone version of traceview is deprecated.
- please use android device monitor (Tools/monitor) instead.
- Failed to read the trace filejava.io.ioexception: key section does not have an *
- end marker
- at com.android.traceview.dmtracereader.parsekeys (dmtracereader.java:420)
-
-
- at com.android.traceview.dmtracereader.generatetrees ( Dmtracereader.java:
- ()
- at Com.android.traceview.dmtracereader.<init> (dmtracereader.java:87)
- 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