1page.title=Traceview Walkthrough 2meta.tags="android, performance, profiling, tools, compute, traceview" 3page.tags="android", "performance", "profiling", "tools", "compute", "traceview" 4page.metaDescription=Log method execution over time and inspect execution data, per-thread timelines, and call stacks to track down performance issues in your source code. 5page.image=tools/performance/thumbnails/tools_traceview.png 6page.article=true 7 8@jd:body 9 10<style> 11 .no-bullet { 12 list-style-type: none; 13 } 14 .padded { 15 padding-left: 10px; 16 } 17</style> 18 19<div id="tb" style="margin-left: 7px; margin-bottom: 5px;"> 20 21<h2>In this document</h2> 22<ul> 23 <li><a href="#WhatYouNeed">Prerequisites</a></li> 24 <li><a href="#WorkingWithTraceview">Working with Traceview</a></li> 25</ul> 26 27<h2>You should also read</h2> 28<ul> 29 <li><a href="{@docRoot}tools/performance/heap-viewer/index.html"> 30 Heap Viewer Walkthrough</a></li> 31 <li><a href="{@docRoot}tools/performance/systrace/index.html"> 32 Systrace Walkthrough</a></li> 33</ul> 34 35</div> 36 37 <p>This walkthrough shows the basic usage and workflow for the Traceview tool. Traceview logs 38 method execution over time and shows execution data, per-thread timelines, and call stacks.</p> 39 40 <p>What it's good for:</p> 41 42 <ul> 43 <li>Tracking down performance problems in your source code.</li> 44 </ul> 45 46 <h2 id="WhatYouNeed">Prerequisites</h2> 47 48 <ul> 49 <li>A mobile device with <a href= 50 "http://developer.android.com/tools/device.html#developer-device-options">Developer Options</a> 51 enabled.</li> 52 53 <li>Application code. Use your own code, or the <a href= 54 "https://github.com/udacity/Sunshine-Version-2">Sunshine</a> sample app from the <a href= 55 "https://www.udacity.com/course/ud853">Android Fundamentals Udacity course</a>.</li> 56 </ul> 57 58<h2 id="WorkingWithTraceview">Working with Traceview</h2> 59 60<ul class="no-bullet"> 61<!-- this also hides bullet, by default outside box --> 62 <li><div style="overflow:hidden"> 63 <ol class="padded"> 64 65 <div class="figure" style=""> 66 <img src="{@docRoot}images/tools/performance/traceview/gettingstarted_image001.png" 67 alt="" 68 width="400px" /> 69 <p class="img-caption"> 70 <strong>Figure 1. </strong>Steps for starting Android Device Monitor. 71 </p> 72 </div> 73 74 <li>Connect your mobile device to your computer.</li> 75 76 <li>Open your application in Android Studio, build the source, and run it on your device.</li> 77 78 <li>Start the Android Device Monitor from Android Studio: <b>Tools -> Android -> Android 79 Device</b> <b>Monitor</b>. 80 81</ol> 82</div></li> 83 84<li><div style="overflow:hidden"> 85<hr> 86 <ol class="padded" start="4"> 87 88 <div class="figure" style=""> 89 <img src="{@docRoot}images/tools/performance/traceview/gettingstarted_image002.png" 90 alt="" 91 width="400px" /> 92 <p class="img-caption"> 93 <strong>Figure 2. </strong>Steps for starting Traceview. 94 </p> 95 </div> 96 97 <li>Make sure your device 98 and the package for your application are showing in the <b>Devices</b> (DDMS mode) or 99 <b>Windows</b> (Hierarchy Viewer mode) tab. 100 101 <p>If necessary choose <b>Window > Reset 102 Perspective</b> to get back to the default pane arrangement.</p></li> 103 104 <li>Click the <b>DDMS</b> button, because Traceview is one of the DDMS tools.</li> 105 106 <li>Select the app you want to profile. 107</ol> 108</div></li> 109 110<li><div style="overflow:hidden"> 111<hr> 112 <ol class="padded" start="7"> 113 114 <div class="figure" style=""> 115 <img src="{@docRoot}images/tools/performance/traceview/gettingstarted_image004.png" 116 alt="" 117 width="400px" /> 118 <p class="img-caption"> 119 <strong>Figure 3. </strong>Starting profiling. 120 </p> 121 </div> 122 123 <li>Click the Start method profiling 124 <img src="{@docRoot}images/tools/performance/traceview/gettingstarted_image003.png"> 125 button. 126 </li> 127 128</ol> 129</div></li> 130 131<li><div style="overflow:hidden"> 132<hr> 133 <ol class="padded" start="8"> 134 135 <div class="figure" style=""> 136 <img src="{@docRoot}images/tools/performance/traceview/gettingstarted_image005.png" 137 alt="" 138 width="400px" /> 139 <p class="img-caption"> 140 <strong>Figure 4. </strong>Choosing profiling options. 141 </p> 142 </div> 143 144 <li>In the <b>Profiling Options</b> popup: 145 146 <ul> 147 <li>Choose <b>Sample based profiling</b></li> 148 149 <li>Keep the default sampling rate of 1000 microseconds.</li> 150 151 <li>Click <b>OK</b>.</li> 152 </ul> 153 </li> 154</ol> 155</div></li> 156 157<li><div style="overflow:hidden"> 158<hr> 159 <ol class="padded" start="9"> 160 161 <div class="figure" style=""> 162 <img src="{@docRoot}images/tools/performance/traceview/gettingstarted_image007.png" 163 alt="" 164 width="400px" /> 165 <p class="img-caption"> 166 <strong>Figure 5. </strong>Stopping profiling. 167 </p> 168 </div> 169 170 171 <li>Interact with your application. If you are aware of performance issues that 172 your users experience, perform those actions.</li> 173 174 <li>Click the Stop method profiling 175 <img src="{@docRoot}images/tools/performance/traceview/gettingstarted_image006.png"> 176 button.</li> 177 178 <li>Wait for the trace to load. This may take a few seconds if you recorded for a 179 long time.</li> 180</ol> 181</div></li> 182 183<li><div style="overflow:hidden"> 184<hr> 185 <ol class="padded" start="12"> 186 187 <div class="figure" style=""> 188 <img src="{@docRoot}images/tools/performance/traceview/gettingstarted_image008.png" 189 alt="" 190 width="440px" /> 191 <p class="img-caption"> 192 <strong>Figure 6. </strong>Traceview output panes. 193 </p> 194 </div> 195 196 <li>Traceview has two panels: <b>Timeline</b> pane and <b>Profile</b> pane, which 197 are described below.</li> 198 199 <li>Use the <b>Find</b> box at the bottom to filter your profile results. For 200 example, if you are interested in finding the running time for a function, you can 201 search for it, and the tool will highlight it in the timeline. 202</ol> 203</div></li> 204 205<li><div style="overflow:hidden"> 206<hr> 207 <ol class="padded" start="14"> 208 209 <div class="figure" style=""> 210 <img src="{@docRoot}images/tools/performance/traceview/gettingstarted_image009.png" 211 alt="" 212 width="400px" /> 213 <p class="img-caption"> 214 <strong>Figure 7. </strong>Annotated timeline panel. 215 </p> 216 </div> 217 218 <li>The <b>Timeline</b> pane visualizes how your code executes over time. 219 220 <ul> 221 <li>Each row shows a thread.</li> 222 223 <li>Each bar on the timeline is a method executing.</li> 224 225 <li>Each color is for a different method; every time a method executes, you see 226 a the same color bar.</li> 227 228 <li>The width of its bar indicates how long the method takes to execute.</li> 229 </ul> 230 </li> 231 232 <li>When you are zoomed out, a bar indicates when a method is executing.</li> 233 234 </ol> 235</div></li> 236 237<li><div style="overflow:hidden"> 238<hr> 239 <ol class="padded" start="16"> 240 241 <div class="figure" style=""> 242 <img src="{@docRoot}images/tools/performance/traceview/gettingstarted_image010.png" 243 alt="" 244 width="300px" /> 245 <p class="img-caption"> 246 <strong>Figure 8. </strong>Segment for method on the timeline. 247 </p> 248 </div> 249 250 <li>Zoom into the graph, and the bar for each method expands into a colored 251 U-shape, where the left side of the U indicates the start, and the right side 252 the end of the method's execution.</li> 253</ol> 254</div></li> 255 256<li><div style="overflow:hidden"> 257<hr> 258 <ol class="padded" start="17"> 259 260 <div class="figure" style=""> 261 <img src="{@docRoot}images/tools/performance/traceview/gettingstarted_image011.png" 262 alt="" 263 width="440px" /> 264 <p class="img-caption"> 265 <strong>Figure 9. </strong>Traceview Profiling pane with callstack. 266 </p> 267 </div> 268 269 <li>The <b>Profiling</b> pane shows a list of methods. 270 271 <ul> 272 <li>Select a method to see who called it (Parent) and who it's 273 calling (Children).</li> 274 275 <li>The selected method is also highlighted in the <b>Timeline</b> pane.</li> 276 277 <li>The columns show exclusive and inclusive CPU and real times, percentages, 278 ratios, and how often a method was called.</li> 279 280 <li>The <em>exclusive time</em> is the time spent just in the method itself, which can 281 help you find issues within that specific method.</li> 282 283 <li>The <em>inclusive time</em> is for the method and all methods it calls, which 284 can help you find problems with your call tree.</li> 285 286 <li>The <b>Calls+Rec</b> column shows how many times a method was called recursively, 287 which can help you track down performance issues.</li> 288 </ul> 289 </li> 290 </ol> 291</div></li> 292</ul> 293