summaryrefslogtreecommitdiffstats
path: root/docs/html/tools/help/systrace.jd
blob: 2a8e86f47264d65b831e4ef3eef1e26d84ea8f75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
page.title=Systrace
parent.title=Tools
parent.link=index.html
@jd:body


<p>The Systrace tool helps analyze the performance of your application by capturing and
  displaying execution times of your applications processes and other Android system processes. The
  tool combines data from the Android kernel such as the CPU scheduler, disk activity, and
  application threads to generate an HTML report that shows an overall picture of an Android
  device’s system processes for a given period of time.</p>

<p>The Systrace tool is particularly useful in diagnosing display problems where an
  application is slow to draw or stutters while displaying motion or animation. For more information
  on how to use Systrace, see <a href="{@docRoot}tools/debugging/systrace.html">Analyzing
  UI Performance with Systrace</a>.</p>

<h2 id="requirements">Requirements</h2>

<p>In order to run Systrace, you must have Android SDK Tools 20 or later installed. You must also
have <a href="http://www.python.org/">Python</a> installed and included in your development
computer's execution path. In order to generate a trace, you must connect a device running Android
4.1 (API Level 16) or higher to your development system using a
<a href="{@docRoot}tools/device.html#setting-up">USB debugging connection</a>.</p>

<p>The Systrace tool can be run either from one of the Android SDK's graphical user interface
tools, or from the command line. The following sections describe how to run the tool using either
of these methods.</p>


<h2 id="gui">User Interface</h2>

<p>The Systrace tool can be run from the
<a href="{@docRoot}tools/help/adt.html">Android Developer Tools</a> (ADT) in Eclipse,
<a href="{@docRoot}sdk/installing/studio.html">Android Studio</a>,
or the Android <a href="{@docRoot}tools/help/monitor.html">Device Monitor</a>.

<p>To run the Systrace capture user interface:</p>

<div class="toggle-content closed">
<p style="margin-top:5px"><a href="#" onclick="return toggleContent(this)">
  <img src="/assets/images/triangle-closed.png" class="toggle-content-img" alt=""
  />Using Eclipse</a></p>

  <div class="toggle-content-toggleme">
  <ol>
    <li>In Eclipse, open an Android application project.</li>
    <li>Switch to the DDMS perspective, by selecting <strong>Window &gt; Perspectives &gt;
      DDMS</strong>.</li>
    <li>In the <strong>Devices</strong> tab, select the device on which to run a trace. If no
      devices are listed, make sure your device is connected via USB cable and that debugging is
      enabled on the device.</li>
    <li>Click the Systrace icon <img src="{@docRoot}images/systrace/systrace-button.png"
      style="margin:0"/> at the top of the <strong>Devices</strong> panel to configure tracing.</li>
    <li>Set the tracing options and click <strong>OK</strong> to start the trace.</li>
  </ol>
  </div>
</div>

<div class="toggle-content closed">
<p style="margin-top:5px"><a href="#" onclick="return toggleContent(this)">
  <img src="/assets/images/triangle-closed.png" class="toggle-content-img" alt=""
  />Using Android Studio</a></p>

  <div class="toggle-content-toggleme">
  <ol>
    <li>In <a href="{@docRoot}sdk/installing/studio.html">Android Studio</a>, open an
      Android application project.</li>
    <li>Open the Device Monitor by selecting <strong>Tools &gt; Android &gt; Android Device
      Monitor</strong>.</li>
    <li>In the <strong>Devices</strong> tab, select the device on which to run a trace. If no
      devices are listed, make sure your device is connected via USB cable and that debugging is
      enabled on the device.</li>
    <li>Click the Systrace icon <img src="{@docRoot}images/systrace/systrace-button.png"
      style="margin:0"/> at the top of the <strong>Devices</strong> panel to configure tracing.</li>
    <li>Set the tracing options and click <strong>OK</strong> to start the trace.</li>
  </ol>
  </div>
</div>

<div class="toggle-content closed">
<p style="margin-top:5px"><a href="#" onclick="return toggleContent(this)">
  <img src="/assets/images/triangle-closed.png" class="toggle-content-img" alt=""
  />Using Device Monitor</a></p>

  <div class="toggle-content-toggleme">
  <ol>
    <li>Navigate to your SDK {@code tools/} directory.</li>
    <li>Run the {@code monitor} program.</li>
    <li>In the <strong>Devices</strong> tab, select the device on which to run a trace. If no
      devices are listed, make sure your device is connected via USB cable and that debugging is
      enabled on the device.</li>
    <li>Click the Systrace icon <img src="{@docRoot}images/systrace/systrace-button.png"
      style="margin:0"/> at the top of the <strong>Devices</strong> panel to configure tracing.</li>
    <li>Set the tracing options and click <strong>OK</strong> to start the trace.</li>
  </ol>
  </div>
</div>


<h2 id="options">Command Line Usage</h2>

<p>The Systrace tool has different command line options for devices running Android 4.3 (API
level 18) and higher versus devices running Android 4.2 (API level 17) and lower. The following
sections describe the different command line options for each version.</p>

<p>The general syntax for running Systrace from the command line is as follows.</p>

<pre>
$ python systrace.py [options] [category1] [category2] ... [categoryN]
</pre>

<p>See the sections below for example Systrace sessions.</p>


<h3 id="options-4.3">Android 4.3 and higher options</h3>

<p>When you use Systrace on devices running Android 4.3 and higher, you can omit trace category tags
to get the defaults, or you may manually specify tags for inclusion. Here is an example execution
run that sets trace tags and generates a trace from a connected device.</p>

<pre>
$ cd <em>android-sdk</em>/platform-tools/systrace
$ python systrace.py --time=10 -o mynewtrace.html sched gfx view wm
</pre>

<p class="note">
  <strong>Tip:</strong> If you want to see the names of tasks in the trace output, you <em>must</em>
  include the {@code sched} category in your command parameters.
</p>

<p>The table below lists the Systrace command line options for devices running Android 4.3
(API level 18) and higher.</p>

<table>
  <tr>
    <th>Option</th>

    <th>Description</th>
  </tr>

  <tr>
    <td><nobr><code>-h, --help</code></nobr></td>

    <td>Show the help message.</td>
  </tr>

  <tr>
    <td><code>-o&nbsp;&lt;<em>FILE</em>&gt;</code></td>

    <td>Write the HTML trace report to the specified file.</td>
  </tr>

  <tr>
    <td><code>-t N, --time=N</code></td>

    <td>Trace activity for <em>N</em> seconds. The default value is 5 seconds.</td>
  </tr>

  <tr>
    <td><code>-b N, --buf-size=N</code></td>

    <td>Use a trace buffer size of <em>N</em> kilobytes. This option lets you limit the total size
    of the data collected during a trace.</td>
  </tr>

  <tr>
    <td><code>-k&nbsp;&lt;<em>KFUNCS</em>&gt;<br>
        --ktrace=&lt;<em>KFUNCS</em>&gt;</code></td>

    <td>Trace the activity of specific kernel functions, specified in a comma-separated list.</td>
  </tr>

  <tr>
    <td><code>-l, --list-categories</code></td>

    <td>List the available tracing category tags. The available tags are:

      <ul>
        <li><code>gfx</code> - Graphics</li>
        <li><code>input</code> - Input</li>
        <li><code>view</code> - View</li>
        <li><code>webview</code> - WebView</li>
        <li><code>wm</code> - Window Manager</li>
        <li><code>am</code> - Activity Manager</li>
        <li><code>audio</code> - Audio</li>
        <li><code>video</code> - Video</li>
        <li><code>camera</code> - Camera</li>
        <li><code>hal</code> - Hardware Modules</li>
        <li><code>res</code> - Resource Loading</li>
        <li><code>dalvik</code> - Dalvik VM</li>
        <li><code>rs</code> - RenderScript</li>
        <li><code>sched</code> - CPU Scheduling</li>
        <li><code>freq</code> - CPU Frequency</li>
        <li><code>membus</code> - Memory Bus Utilization</li>
        <li><code>idle</code> - CPU Idle</li>
        <li><code>disk</code> - Disk input and output</li>
        <li><code>load</code> - CPU Load</li>
        <li><code>sync</code> - Synchronization Manager</li>
        <li><code>workq</code> - Kernel Workqueues</li>
      </ul>

      <p class="note"><strong>Note:</strong> Some trace categories are not supported on all
      devices.</p>

      <p class="note"><strong>Tip:</strong> If you want to see the names of tasks in the trace
      output, you <em>must</em> include the {@code sched} category in your command parameters.</p>

    </td>
  </tr>

  <tr>
    <td><code>-a&nbsp;&lt;<em>APP_NAME</em>&gt;<br>
        --app=&lt;<em>APP_NAME</em>&gt;</code></td>

    <td>Enable tracing for applications, specified as a comma-separated list of
    <a href="{@docRoot}guide/topics/manifest/manifest-element.html#package">package names</a>.
    The apps must contain tracing instrumentation calls from the {@link android.os.Trace} class.
    For more information, see <a href="{@docRoot}tools/debugging/systrace.html#app-trace">Analyzing
    UI Performance with Systrace</a>.
    </td>
  </tr>

  <tr>
    <td><code>--from-file=&lt;<em>FROM_FILE</em>&gt;</code></td>

    <td>Create the interactive Systrace report from a file, instead of running a live trace.</td>
  </tr>

  <tr>
    <td style="white-space:nowrap">
    <code>-e &lt;<em>DEVICE_SERIAL</em>&gt;<br>
    --serial=&lt;<em>DEVICE_SERIAL</em>&gt;</code></td>

    <td>Conduct the trace on a specific connected device, identified by its
      <a href="{@docRoot}tools/help/adb.html#devicestatus">device serial number</a>.</td>
  </tr>

</table>


<h3 id="options-pre-4.3">Android 4.2 and lower options</h3>

<p>Using Systrace on the command line with devices running Android 4.2 and lower is typically a
two-step process. You must first set the trace tags you want to capture and then run the trace.
Here is an example execution run that sets trace tags and generates a trace from a connected
device.</p>

<pre>
$ cd <em>android-sdk</em>/platform-tools/systrace
$ python systrace.py --set-tags gfx,view,wm
$ adb shell stop
$ adb shell start
$ python systrace.py --disk --time=10 -o mynewtrace.html
</pre>

<p>The table below lists the Systrace command line options for devices running Android 4.2
(API level 17) and lower.</p>

<table>
  <tr>
    <th>Option</th>

    <th>Description</th>
  </tr>

  <tr>
    <td><nobr><code>-h, --help</code></nobr></td>

    <td>Show the help message.</td>
  </tr>

  <tr>
    <td><code>-o&nbsp;&lt;<em>FILE</em>&gt;</code></td>

    <td>Write the HTML trace report to the specified file.</td>
  </tr>

  <tr>
    <td><code>-t N, --time=N</code></td>

    <td>Trace activity for <em>N</em> seconds. The default value is 5 seconds.</td>
  </tr>

  <tr>
    <td><code>-b N, --buf-size=N</code></td>

    <td>Use a trace buffer size of <em>N</em> kilobytes. This option lets you limit the total size
    of the data collected during a trace.</td>
  </tr>

  <tr>
    <td><code>-d, --disk</code></td>

    <td>Trace disk input and output activity. This option requires root access on the device.</td>
  </tr>

  <tr>
    <td><code>-f, --cpu-freq</code></td>

    <td>Trace CPU frequency changes. Only changes to the CPU frequency are logged, so the initial
    frequency of the CPU when tracing starts is not shown.</td>
  </tr>

  <tr>
    <td><code>-i, --cpu-idle</code></td>

    <td>Trace CPU idle events.</td>
  </tr>

  <tr>
    <td><code>-l, --cpu-load</code></td>

    <td>Trace CPU load. This value is a percentage determined by the interactive CPU frequency
    governor.</td>
  </tr>

  <tr>
    <td><nobr><code>-s,&nbsp;--no-cpu-sched</code></nobr></td>

    <td>Prevent tracing of the CPU scheduler. This option allows for longer trace times by reducing
    the rate of data flowing into the trace buffer.</td>
  </tr>

  <tr>
    <td><nobr><code>-u, --bus-utilization</code></nobr></td>

    <td>Trace the bus utilization levels. This option requires root access on the device.</td>
  </tr>

  <tr>
    <td><code>-w, --workqueue</code></td>

    <td>Trace kernel work queues. This option requires root access on the device.</td>
  </tr>

  <tr>
    <td id="tags"><code>--set-tags=&lt;<em>TAGS</em>&gt;</code></td>

    <td>Set the enabled trace tags in a comma separated list. The available tags are:
      <ul>
        <li><code>gfx</code> - Graphics</li>
        <li><code>input</code> - Input</li>
        <li><code>view</code> - View</li>
        <li><code>webview</code> - WebView</li>
        <li><code>wm</code> - Window Manager</li>
        <li><code>am</code> - Activity Manager</li>
        <li><code>sync</code> - Synchronization Manager</li>
        <li><code>audio</code> - Audio</li>
        <li><code>video</code> - Video</li>
        <li><code>camera</code> - Camera</li>
      </ul>
      <p class="note"><strong>Note:</strong> When setting trace tags from the command line, you
      must stop and restart the framework ({@code $ adb shell stop; adb shell start}) for the
      tag tracing changes to take effect.</p>
    </td>
  </tr>

</table>

<p>You can set the trace <a href="#tags">tags</a> for Systrace on
your Android 4.2 and lower device by navigating to <strong>Settings &gt; Developer options &gt;
Monitoring &gt; Enable traces</strong>.</p>


<h2 id="viewing-options">Trace Viewing Shortcuts</h2>

<p>The table below lists the keyboard shortcuts that are available while viewing a Systrace
trace HTML report.</p>

<table>
  <tr>
    <th>Key</th>

    <th>Description</th>
  </tr>

  <tr>
    <td><strong>w</strong></td>

    <td>Zoom into the trace timeline.</td>
  </tr>

  <tr>
    <td><strong>s</strong></td>

    <td>Zoom out of the trace timeline.</td>
  </tr>

  <tr>
    <td><strong>a</strong></td>

    <td>Pan left on the trace timeline.</td>
  </tr>

  <tr>
    <td><strong>d</strong></td>

    <td>Pan right on the trace timeline.</td>
  </tr>

  <tr>
    <td><strong>e</strong></td>

    <td>Center the trace timeline on the current mouse location.</td>
  </tr>

  <tr>
    <td><strong>g</strong></td>

    <td>Show grid at the start of the currently selected task.</td>
  </tr>

  <tr>
    <td><strong>Shift+g</strong></td>

    <td>Show grid at the end of the currently selected task.</td>
  </tr>

  <tr>
    <td><strong>Right Arrow</strong></td>

    <td>Select the next event on the currently selected timeline.</td>
  </tr>

  <tr>
    <td><strong>Left Arrow</strong></td>

    <td>Select the previous event on the currently selected timeline.</td>
  </tr>

</table>