[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-08-21 (世界標準時間)。"],[],[],null,["# Capture a system trace on a device\n\nDevices running Android 9 (API level 28) or higher include a system-level app\ncalled System Tracing. This app is similar to the\n[`systrace`](/topic/performance/tracing/command-line) command-line utility, but\nthe app lets you record traces directly from a test device itself, without\nneeding to plug in the device and connect to it over `adb`. You can then use the\napp to share results from these traces with your development team.\n\nDevices running Android 10 and higher record traces in Perfetto format, whereas\nearlier devices record them in Systrace format. We recommend using the [Perfetto\ntrace viewer](https://ui.perfetto.dev/) to open both formats and\nthen analyze traces.\n\nIt helps to record traces when addressing performance-related bugs in your app,\nsuch as slow startup, slow transitions, or UI jank.\n\nRecord a system trace\n---------------------\n\nThe System Tracing app lets you record a system trace using **Quick Settings\ntile** or a menu within the app itself. The following sections describe how to\ncomplete the recording process using these interfaces.\n| **Note:** As part of your development workflow, you might submit an on-device bug report. It's important to file this type of bug report after you finish recording a system trace. That way, the bug report process itself isn't included in the recorded trace.\n\n### Record using Quick Settings tile\n\n**Quick Settings tile** is usually the more convenient way to complete the\non-device system tracing process.\n\n#### Set up tile\n\nIf you're using System Tracing for the first time on your test device, or if you\ndon't see the **System Tracing** tile in your device's **Quick Settings** panel,\nas shown in figure 2, complete the following setup steps:\n\n1. [Enable developer options](/studio/debug/dev-options#enable).\n2. Open the **Developer Options** settings screen.\n3. In the **Debugging** section, select **System Tracing**. The System Tracing app opens, showing the app menu.\n4. From the app menu, enable **Show Quick Settings tile** , as shown in figure 1.\n The system adds the **System Tracing** tile to the **Quick Settings** panel,\n as shown in figure 2:\n\n **Figure 1.** The **Show Quick Settings tile** switch in the System Tracing app. **Figure 2.** The **System Tracing** tile within the **Quick Settings** panel.\n\n **Note:** By default, the system\n adds the **System Tracing** tile as the first tile in the **Quick\n Settings** panel. If you want the tile to appear in a different position,\n use the panel's edit mode to move the tile.\n\n#### Complete a system trace recording\n\nTo record a system trace using the **Quick Settings** panel, complete the\nfollowing steps:\n\n1. Tap the **System Tracing** tile, which has the label **Record trace**. The\n tile becomes enabled, and a persistent notification appears to notify you\n that the system is recording a trace, as shown in figure 3:\n\n **Figure 3.** Persistent notification that appears after starting an on-device system trace.\n2. Perform the actions in your app that you want the system to inspect.\n\n | **Note:** You can record bugs that are difficult to reproduce by leaving System Tracing running in the background and then stopping System Tracing soon after the bug occurs. System Tracing saves a device's activity to a rolling buffer, which holds 10-30 seconds of events.\n3. Stop tracing by tapping either the **System Tracing** tile in the **Quick\n Settings** panel or on the System Tracing notification.\n\n The system displays a new notification that contains the message \"Saving\n trace\". When saving is complete, the system dismisses the notification and\n displays a third notification, confirming that your trace is saved and that\n you're ready to [share the system trace](#share-trace), as shown in figure\n 4:\n **Figure 4.** Persistent notification that appears after the system finishes saving a recorded trace.\n\n### Record using app menu\n\nThe app menu lets you configure several advanced settings related to system\ntracing and provides a switch for starting and stopping a system trace.\n\nTo record a system trace using the System Tracing app menu, complete the\nfollowing steps:\n\n1. [Enable developer options](/studio/debug/dev-options#enable).\n2. Open the **Developer Options** settings screen. In the **Debugging** section,\n select **System Tracing**. The System Tracing app opens.\n\n Alternatively, if you [set up the **System Tracing** tile](#set-up-tile),\n you can tap and hold the tile to enter the System Tracing app.\n3. Make sure **Trace debuggable applications** is selected to include apps that\n have debugging enabled in the system trace.\n\n4. Optionally, choose the **Categories** of system and sensor calls to trace,\n and choose a **Per-CPU buffer size** in KB. Choose categories that correspond\n to the use case that you're testing, such as the **Audio** category for\n testing Bluetooth operations or the **Memory** category for heap allocations.\n\n | **Note:** These categories serve as app-level settings, so the system uses these categories when [using the **Quick Settings** tile](#quick-settings), too. In addition, these settings persist across device reboots.\n5. Optionally, select **Long traces** to enable traces that are saved\n continuously to device storage. For this option, set limits for the **Maximum\n long trace size** and **Maximum long trace duration**.\n\n6. Enable the **Record trace** switch, highlighted in figure 5. The tile becomes\n enabled, and a persistent notification appears to notify you that the system\n is recording a trace, as shown in [figure 3](#systrace-start).\n\n **Figure 5.** The **Record trace** switch in the System Tracing settings.\n7. Perform the actions in your app that you want the system to inspect.\n\n | **Note:** You can record bugs that are difficult to reproduce by leaving System Tracing running in the background, then stopping System Tracing soon after the bug occurs. By default, System Tracing saves a device's activity to a rolling buffer, which holds 10-30 seconds of events. If **Long traces** is enabled, the device's activity is saved continuously to device storage up to the limits you set.\n8. Stop tracing by disabling the **Record trace** switch.\n\n The system displays a new notification that contains the message \"Saving\n trace\". When saving is complete, the system dismisses the notification and\n displays a third notification, confirming that your trace is saved and that\n you're ready to [share the system trace](#share-trace), as shown in\n [figure 4](#systrace-saved).\n\nShare a system trace\n--------------------\n\nThe System Tracing app helps you share system trace results as part of several\ndifferent workflows. On a device running Android 10 (API level 29) or higher, trace\nfiles are saved with the `.perfetto-trace` filename extension and can be opened\nin the [Perfetto UI](https://ui.perfetto.dev/#!/). On a device\nrunning an earlier version of Android, trace files are saved with the `.ctrace`\nfilename extension, which denotes the Systrace format.\n\n### Share as a message\n\nSystem Tracing lets you share your collected trace with other apps on your\ndevice. You can send the trace to your development team through an email or a\nbug-tracking app without needing to connect a device to your development\nmachine.\n\nAfter you record a system trace, tap on the notification that appears on\nthe device, like the one shown in [figure 4](#systrace-saved). The platform's\nintent picker appears, letting you share your trace using the messaging app of\nyour choice.\n\n### Share from the Files app\n\nOn devices running Android 10 (API level 29) or higher, traces are shown in the\nFiles app. You can share a trace from this app.\n\n### Download report using ADB\n\nYou can also extract a system trace from a device using `adb`. Connect the\ndevice used to record the trace to your development machine, then run the\nfollowing commands in a terminal window: \n\n```\ncd /path-to-traces-on-my-dev-machine && \\\n adb pull /data/local/traces/ .\n```\n\nConvert between trace formats\n-----------------------------\n\nYou can convert Perfetto trace files to the Systrace format. See [Converting\nbetween trace formats](https://docs.perfetto.dev/#/traceconv.md)\nfor more information.\n\nCreate an HTML report\n---------------------\n\nWhen sharing your trace, the report itself is in a `.perfetto-trace` file on\ndevices running Android 10\nor higher, or a `.ctrace` file for all other versions.\n\nCreate an HTML report from the trace file using a [web-based UI](#web-ui) or\nfrom the [command line](#command-line).\n\n### Web-based UI\n\nUse the [Perfetto UI](https://perfetto.dev/#/running.md) to open\nthe trace file and generate the report.\n\nFor a Perfetto file, click **Open trace file** . For a Systrace file, click\n**Open with legacy UI** . The legacy UI has the same look and feel as the\n[**Systrace report**](/topic/performance/tracing/navigate-report).\n\n### Command line\n\nRun the following commands in a terminal window to generate an HTML report\nfrom the trace file: \n\n```\ncd /path-to-traces-on-my-dev-machine && \\\n systrace --from-file trace-file-name{.ctrace | .perfetto-trace}\n```\n\nIf you don't already have the `systrace` command-line program, you can download\nit from the\n[Catapult](https://github.com/catapult-project/catapult/tree/main/systrace)\nproject on GitHub, or directly from the [Android Open Source\nProject](https://android.googlesource.com/platform/external/chromium-trace/+/main/catapult/systrace/systrace/).\n\nRecommended for you\n-------------------\n\n- Note: link text is displayed when JavaScript is off\n- [Benchmark in Continuous Integration](/topic/performance/benchmarking/benchmarking-in-ci)\n- [Capture a system trace on the command line](/topic/performance/tracing/command-line)"]]