Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you want to profile your application to find performance bottlenecks you can <a href="https://developer.android.com/studio/profile/traceview.html" rel="nofollow noreferrer">use the <code>traceview</code> tool</a>. This gives you a graphical view of performance traces of your application.</p> <p><a href="https://content.screencast.com/users/davweb/folders/Snagit/media/03df8bcc-606c-4ebb-8330-ab206ae30099/12.24.2009-08.57.51.png" rel="nofollow noreferrer" title="Click for full size"><img src="https://content.screencast.com/users/davweb/folders/Snagit/media/03df8bcc-606c-4ebb-8330-ab206ae30099/12.24.2009-08.57.51.png" width="300"></a></p> <p>To create a trace add the following to your code where you want to start tracing:</p> <pre><code>Debug.startMethodTracing("myapp"); </code></pre> <p>and then put the following when you want to stop tracing:</p> <pre><code>Debug.stopMethodTracing(); </code></pre> <p>This will create a trace file call <code>myapp.trace</code> in the root directory of the SD Card. As it is written to the SD Card:</p> <ul> <li>If you're using the emulator you'll need to <a href="https://stackoverflow.com/questions/1952345/how-do-i-simulate-that-the-emulator-has-as-an-sd-card/1952358#1952358">add an SD card to your AVD</a>.</li> <li><p>You'll need to give you app permission to write the SD card by adding the following to your Manifest:</p> <p><code>&lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;</code></p></li> </ul> <p>Once the file has been created you'll need to copy it to your PC. You can do this using the <code>adb</code> command:</p> <pre><code>adb pull /sdcard/myapp.trace c:/my/dir/myapp.trace </code></pre> <p>Finally, start <code>traceview</code> giving it the <strong>full path</strong> to the trace file:</p> <pre><code>traceview c:/my/dir/myapp.trace </code></pre> <p>I did have some problems with <code>traceview</code> failing with <code>OutOfMemory</code> exceptions. I fixed this on Windows by changing the last line of <code>traceview.bat</code> from:</p> <pre><code>call java -Djava.ext.dirs=%javaextdirs% -Dcom.android.traceview.toolsdir= -jar %jarpath% %* </code></pre> <p>to:</p> <pre><code>call java -Xmx1g -Djava.ext.dirs=%javaextdirs% -Dcom.android.traceview.toolsdir= -jar %jarpath% %* </code></pre> <p>Adding the <code>-Xmx1g</code> option allows <code>traceview</code> to use more memory.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload