Some of the previous articles introduced some of the tools commonly used in Android, the tools presented today are more practical and convenient, it can be used to quantify the indicators to tell us which method executes the longest, is called the most times, there is no duplicate call. Let's take a look at how it's used for us.
A code area for labeling tests
What if we want to test the GridView Setup adapter code? It's easy to clip it in two lines of code ~
The original code:
Mphotowall.setadapter (Madapter);
Code labeled as test:
Debug.startmethodtracing ("My_trace_file" mphotowall.setadapter (madapter); debug.stopmethodtracing ();
So we're going to show that our test starts before setadapter and ends with it. Here is a filename, my_trace_file, this is our test, get the name of the test report, a later.
PS: Remember to add permissions:
<android:name= "Android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/> <android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/ >
Second, review the test report
After running the program, we will find our test report files under the SDcard folder.
If we want to see it, we can move it to the D-Drive via the command line.
ADB pull/sdcard/my_trace_file.trace d:/
Then call
ADB pull/sdcard/my_trace_file.trace d:/
You can open the graphical interface of the test report:
The meaning of each parameter in the table header
nl Cpu time%: The percentage of the total time that the method was called during run time.
incl Cpu time: The total number of times the method was executed (including the time it takes to invoke the child function): The time required to invoke the method per time * execution count.
Excl Cpu time%: The percentage of the total time consumed by the method itself, excluding the time it takes to invoke other methods.
Excl Cpu Time: How long the method itself consumes.
incl Real Time%: The percentage of total time that the method actually executes.
incl Real time: How long the method was actually executed.
Excl Real time%: The percentage of total time that the method was actually executed
Excl Real Time: How long the method is actually being executed
Calls+recurcalls/total: number of times the method was called + number of repeated calls
Cpu time/call: How long the method is executed each time
Real Time/call: The time the method was actually executed
PS: Generally add debug.startmethodtracing ("Test") in the activity's OnCreate (), and call Debug.stopmethodtracing () in OnStop (). So when we switch to other activity or click on the Home button OnStop () will be called, we can also get the complete trace file.
Reference from:
http://blog.csdn.net/wwj_748/article/details/8913862
Android Performance Detection Tool--traceview