Android Performance Detection--traceview tool The meaning of each parameter

Source: Internet
Author: User
<span id="Label3"></p><p><p>Android Performance Detection</p></p><p><p>How to use TraceView</p></p><p><p>1. Add the Android-sdk-windows\tools path to path</p></p><p><p></p></p><p><p>2. Write the test code:</p></p><p><p></p></p><strong><strong>[java]</strong></strong>View Plaincopy <ol class="dp-j" start="1"> <li class="alt"><li class="alt"><span class="keyword">Package com.wwj.traceview;</span></li></li> <li><li></li></li> <li class="alt"><li class="alt"><span class="keyword">Import java.util.ArrayList;</span></li></li> <li><li><span class="keyword">Import java.util.List;</span></li></li> <li class="alt"><li class="alt"></li></li> <li><li><span class="keyword">Import android.app.Activity;</span></li></li> <li class="alt"><li class="alt"><span class="keyword">Import android.os.Bundle;</span></li></li> <li><li><span class="keyword">Import android.os.Debug;</span></li></li> <li class="alt"><li class="alt"><span class="keyword">Import android.view.View;</span></li></li> <li><li><span class="keyword">Import android.widget.Toast;</span></li></li> <li class="alt"><li class="alt"></li></li> <li><li><span class="keyword">Public <span class="keyword">class Mainactivity <span class="keyword">extends Activity {</span> </span></span></li></li> <li class="alt"><li class="alt"><span class="keyword">private List<integer> List1 = <span class="keyword">new arraylist<integer> (); </span></span></li></li> <li><li><span class="annotation">@Override</span></li></li> <li class="alt"><li class="alt"><span class="keyword">public <span class="keyword">void OnCreate (Bundle Savedinstancestate) {</span> </span></li></li> <li><li><span class="keyword">super.oncreate (savedinstancestate); </span></li></li> <li class="alt"><li class="alt">Setcontentview (r.layout.activity_main);</li></li> <li><li>}</li></li> <li class="alt"><li class="alt"></li></li> <li><li></li></li> <li class="alt"><li class="alt"><span class="comment">//first test Method</span></li></li> <li><li><span class="keyword">public <span class="keyword">void test1 () {</span> </span></li></li> <li class="alt"><li class="alt"><span class="comment">//add 10,000 numbers to a List1 object</span></li></li> <li><li>for <span class="keyword">(<span class="keyword">int i = <span class="number">0; i < <span class="number">10000; I++) {</span> </span> </span> </span></li></li> <li class="alt"><li class="alt">List1.add (i);</li></li> <li><li>}</li></li> <li class="alt"><li class="alt">}</li></li> <li><li></li></li> <li class="alt"><li class="alt"><span class="comment">//second test Method</span></li></li> <li><li><span class="keyword">public <span class="keyword">void test2 () {</span> </span></li></li> <li class="alt"><li class="alt"><span class="comment">//get The elements in the list object sequentially</span></li></li> <li><li>for <span class="keyword">(<span class="keyword">int i = <span class="number">0; i < <span class="number">10000; I++) {</span> </span> </span> </span></li></li> <li class="alt"><li class="alt">List1.get (i);</li></li> <li><li>}</li></li> <li class="alt"><li class="alt">}</li></li> <li><li></li></li> <li class="alt"><li class="alt"><span class="keyword">public <span class="keyword">void Onclick_test (view view) {</span> </span></li></li> <li><li><span class="keyword">try {</span></li></li> <li class="alt"><li class="alt"><span class="comment">/*//gets The point in time (in Milliseconds) before the Test1 method is executed</span></li></li> <li><li><span class="comment">Long Start1 = System.currenttimemillis ();</span></li></li> <li class="alt"><li class="alt"><span class="comment">Test1 ();</span></li></li> <li><li><span class="comment">Long End1 = System.currenttimemillis ();</span></li></li> <li class="alt"><li class="alt"><span class="comment">Gets the point in time (in Milliseconds) before the Test2 method is executed</span></li></li> <li><li><span class="comment">Long Start2 = System.currenttimemillis ();</span></li></li> <li class="alt"><li class="alt"><span class="comment">Test2 ();</span></li></li> <li><li><span class="comment">Long End2 = System.currenttimemillis ();</span></li></li> <li class="alt"><li class="alt"><span class="comment">Show test results</span></li></li> <li><li><span class="comment">Toast.maketext (this, "execution Time of the Test1 method:" + (end1-start1) + "milliseconds \ntest2 The execution time of the method:"</span></li></li> <li class="alt"><li class="alt"><span class="comment">+ (end2-start2) + "milliseconds", toast.length_long). show (); */</span></li></li> <li><li></li></li> <li class="alt"><li class="alt"><span class="comment">//get memory before calling the Test1 method</span></li></li> <li><li><span class="comment">/*long start1 = memory.used ();</span></li></li> <li class="alt"><li class="alt"><span class="comment">Test1 ();</span></li></li> <li><li><span class="comment">Gets the memory after calling the Test1 method</span></li></li> <li class="alt"><li class="alt"><span class="comment">Long End1 = memory.used ();</span></li></li> <li><li><span class="comment">Gets the memory before calling the Test1 method</span></li></li> <li class="alt"><li class="alt"><span class="comment">Long Start2 = memory.used ();</span></li></li> <li><li><span class="comment">Test2 ();</span></li></li> <li class="alt"><li class="alt"><span class="comment">Gets the memory after calling the Test1 method</span></li></li> <li><li><span class="comment">Long End2 = memory.used ();</span></li></li> <li class="alt"><li class="alt"><span class="comment">Toast.maketext (this, "test1 Method consumes memory:" + (end1-start1) + "bytes \ntest2 memory used by method:"</span></li></li> <li><li><span class="comment">+ (end2-start2) + "bytes", toast.length_long). show ();</span></li></li> <li class="alt"><li class="alt"><span class="comment">*/</span></li></li> <li><li></li></li> <li class="alt"><li class="alt"><span class="comment">//start Monitoring Method</span></li></li> <li><li>Debug.startmethodtracing (<span class="string">"wwj_trace"); </span></li></li> <li class="alt"><li class="alt">Test1 ();</li></li> <li><li>Test2 ();</li></li> <li class="alt"><li class="alt">Debug.stopmethodtracing ();</li></li> <li><li></li></li> <li class="alt"><li class="alt">} <span class="keyword">catch (Exception e) {</span></li></li> <li><li>E.printstacktrace ();</li></li> <li class="alt"><li class="alt">}</li></li> <li><li>}</li></li> <li class="alt"><li class="alt"></li></li> <li><li>}</li></li> </ol><p><p></p></p><p><p></p></p><p><p></p></p><p><p></p></p><p><p><br>3. Remember to set permissions:</p></p><p><p></p></p><strong><strong>[html]</strong></strong>View Plaincopy <ol class="dp-xml" start="1"> <ol class="dp-xml" start="1"> <li class="alt"><span class="tag"><<span class="tag-name">span <span class="attribute">style=<span class="attribute-value">"font-size:24px;" <span class="tag">> <span class="tag"><<span class="tag-name">uses-permission <span class="attribute">android:name=<span class="attribute-value">"android.permission.MOUNT_UNMOUNT_FILESYSTEMS"<span class="tag">/ ></span> </span> </span> </span> </span> </span> </span> </span> </span></span></li> <li><span class="tag"><<span class="tag-name">uses-permission <span class="attribute">android:name=<span class="attribute-value">"android.permission.WRITE_EXTERNAL_STORAGE"<span class="tag">/> <span class="tag"> </<span class="tag-name">span<span class="tag">></span> </span> </span> </span> </span> </span> </span> </span></li> </ol> </ol><p><p></p></p><p><p><br><br></p></p><p><p></p></p><p><p>When you click the button, a file suffix trace is generated in the SD card root directory.</p></p><p><p></p></p><p><p></p></p><p><p>4. Export This file to the location you want to put it for example: C:\wwj_trace.trace</p></p><p><p></p></p><p><p></p></p><p><p>5. TraceView View appears after running TraceView c:\wwj_trace.trace command</p></p><p><p></p></p><p><p></p></p><p><p>Touch Android for some time the children's shoes will be aware of TraceView this tool, I also recently need to perform performance testing, so just to learn the use of this tool, very simple, the following is mainly introduced this tool some important parameters of the meaning, is based on their understanding to write, I don't know if it's right.</p></p><p><p></p></p><p><p>The meaning of each parameter:</p></p><p><p>INL Cpu time%: The percentage of the total time that the method was called during run Time.</p></p><p><p>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.</p></p><p><p>Excl Cpu time%: The percentage of the total time consumed by the method itself, excluding the time it takes to invoke other METHODS.</p></p><p><p>Excl Cpu Time: How long the method itself Consumes.</p></p><p><p>incl Real Time%: The percentage of total time that the method actually executes.</p></p><p><p>incl Real Time: How long the method was actually executed.</p></p><p><p>EXCL Real Time%: The percentage of total time that the method was actually executed</p></p><p><p>EXCL Real Time: How long the method is actually being executed</p></p><p><p>Calls+recurcalls/total: number of times the method was called + number of repeated calls</p></p><p><p>Cpu Time/call: How long the method is executed each time</p></p><p><p>Real Time/call: The time the method was actually executed</p></p><p><p></p></p><p><p>The learning record about the TraceView tool is here, if there are children shoes found wrong place, trouble to help Correct.</p></p><p><p>Android Performance Detection--traceview tool The meaning of each parameter</p></p></span>

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.