to top

Systrace

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.

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 Analyzing Display and Performance.

Requirements

In order to run Systrace, you must have Android SDK Tools 20 or later installed. You must also have Python 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 USB debugging connection.

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.

User Interface

The Systrace tool can be run from the Android Developer Tools (ADT) in Eclipse, Android Studio, or the Android Device Monitor.

To run the Systrace user interface:

Using Eclipse

  1. In Eclipse, open an Android application project.
  2. Switch to the DDMS perspective, by selecting Window > Perspectives > DDMS.
  3. In the Devices 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.
  4. Click the Systrace icon at the top of the Devices panel to configure tracing.
  5. Set the tracing options and click OK to start the trace.

Using Android Studio

  1. In Android Studio, open an Android application project.
  2. Open the Device Monitor by selecting Tools > Android > Monitor.
  3. In the Devices 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.
  4. Click the Systrace icon at the top of the Devices panel to configure tracing.
  5. Set the tracing options and click OK to start the trace.

Using Device Monitor

  1. Navigate to your SDK tools/ directory.
  2. Run the monitor program.
  3. In the Devices 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.
  4. Click the Systrace icon at the top of the Devices panel to configure tracing.
  5. Set the tracing options and click OK to start the trace.

Command Line Usage

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.

The general syntax for running Systrace from the command line is as follows.

$ python systrace.py [options] [category1] [category2] ... [categoryN]

See the sections below for example Systrace sessions.

Android 4.3 and higher options

When you use Systrace on devices running Android 4.3 and higher, you must specify at least one trace category tag. Here is an example execution run that sets trace tags and generates a trace from a connected device.

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

Tip: If you want to see the names of tasks in the trace output, you must include the sched category in your command parameters.

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

Option Description
-h, --help Show the help message.
-o <FILE> Write the HTML trace report to the specified file.
-t N, --time=N Trace activity for N seconds. The default value is 5 seconds.
-b N, --buf-size=N Use a trace buffer size of N kilobytes. This option lets you limit the total size of the data collected during a trace.
-k <KFUNCS>
--ktrace=<KFUNCS>
Trace the activity of specific kernel functions, specified in a comma-separated list.
-l, --list-categories List the available tracing category tags. The available tags are:
  • gfx - Graphics
  • input - Input
  • view - View
  • webview - WebView
  • wm - Window Manager
  • am - Activity Manager
  • audio - Audio
  • video - Video
  • camera - Camera
  • hal - Hardware Modules
  • res - Resource Loading
  • dalvik - Dalvik VM
  • rs - RenderScript
  • sched - CPU Scheduling
  • freq - CPU Frequency
  • membus - Memory Bus Utilization
  • idle - CPU Idle
  • disk - Disk input and output
  • load - CPU Load
  • sync - Synchronization Manager
  • workq - Kernel Workqueues

Note: Some trace categories are not supported on all devices.

Tip: If you want to see the names of tasks in the trace output, you must include the sched category in your command parameters.

-a <APP_NAME>
--app=<APP_NAME>
Enable tracing for applications, specified as a comma-separated list of package names. The apps must contain tracing instrumentation calls from the Trace class. For more information, see Analyzing Display and Performance.
--link-assets Link to the original CSS or JavaScript resources instead of embedding them in the HTML trace report.
--from-file=<FROM_FILE> Create the interactive Systrace report from a file, instead of running a live trace.
--asset-dir=<ASSET_DIR> Specify a directory for the trace report assets. This option is useful for maintaining a single set of assets for multiple Systrace reports.
-e <DEVICE_SERIAL>
--serial=<DEVICE_SERIAL>
Conduct the trace on a specific connected device, identified by its device serial number.

Android 4.2 and lower options

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.

$ cd android-sdk/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

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

Option Description
-h, --help Show the help message.
-o <FILE> Write the HTML trace report to the specified file.
-t N, --time=N Trace activity for N seconds. The default value is 5 seconds.
-b N, --buf-size=N Use a trace buffer size of N kilobytes. This option lets you limit the total size of the data collected during a trace.
-d, --disk Trace disk input and output activity. This option requires root access on the device.
-f, --cpu-freq 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.
-i, --cpu-idle Trace CPU idle events.
-l, --cpu-load Trace CPU load. This value is a percentage determined by the interactive CPU frequency governor.
-s, --no-cpu-sched Prevent tracing of the CPU scheduler. This option allows for longer trace times by reducing the rate of data flowing into the trace buffer.
-u, --bus-utilization Trace the bus utilization levels. This option requires root access on the device.
-w, --workqueue Trace kernel work queues. This option requires root access on the device.
--set-tags=<TAGS> Set the enabled trace tags in a comma separated list. The available tags are:
  • gfx - Graphics
  • input - Input
  • view - View
  • webview - WebView
  • wm - Window Manager
  • am - Activity Manager
  • sync - Synchronization Manager
  • audio - Audio
  • video - Video
  • camera - Camera

Note: When setting trace tags from the command line, you must stop and restart the framework ($ adb shell stop; adb shell start) for the tag tracing changes to take effect.

--link-assets Link to the original CSS or JS resources instead of embedding them in the HTML trace report.

You can set the trace tags for Systrace on your Android 4.2 and lower device by navigating to Settings > Developer options > Monitoring > Enable traces.

Trace Viewing Shortcuts

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

Key Description
w Zoom into the trace timeline.
s Zoom out of the trace timeline.
a Pan left on the trace timeline.
d Pan right on the trace timeline.
e Center the trace timeline on the current mouse location.
g Show grid at the start of the currently selected task.
Shift+g Show grid at the end of the currently selected task.
Right Arrow Select the next event on the currently selected timeline.
Left Arrow Select the previous event on the currently selected timeline.
Double Click Zoom into the trace timeline.
Shift+Double Click Zoom out of the trace timeline.