Capture a system trace on a device | App quality | Android Developers
Devices running Android 9 (API level 28) or higher include a system-level app
called System Tracing. This app is similar to the
systrace
command-line utility, but
the app allows you to record traces directly from a test device itself, without
needing to plug in the device and connect to it over ADB. You can then use the
app to share results from these traces with your development team.
It’s particularly helpful to record traces when addressing performance-related bugs in your app, such as slow startup, slow transitions, or UI jank .
Mục Chính
Record a system trace
The System Tracing app allows you to record a system trace using a Quick Settings tile or a menu within the app itself. The following sections describe how to complete the recording process using these interfaces .
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’ve finished
recording a system trace. That way, the bug report process itself isn’t included
in the recorded trace.Record using Quick Settings tile
The Quick Settings tile is usually the more convenient way to complete the on-device system tracing process .
Set up tile
Figure 2. The Show Quick Settings tile switch in the System Tracing appIf you’re using System Tracing for the first time on your test device, or if you
don’t see the System Tracing tile in your device’s Quick Settings panel
(Figure 1), complete the following setup steps:
- Enable developer options, if you haven’t
done so already.- Open the Developer Options settings screen.
- In the Debugging section, select System Tracing. The System Tracing
app opens, showing the app menu.From the app menu, enable Show Quick Settings tile, as shown in Figure 2.
The system adds the System Tracing tile to the Quick Settings panel,
which appears in Figure 1:
Figure 1. The System Tracing tile within the
Quick Settings panelNote: By default, the system
adds the System Tracing tile as the first tile in the Quick
Settings panel. If you’d like the tile to appear in a different
position, use the panel’s edit mode to move the tile.Complete a system trace recording
To record a system trace using the Quick Settings panel, complete the
following steps:
Tap the System Tracing tile, which has the label “Record trace”. The tile
becomes enabled, and a persistent notification appears to notify you that the
system is now recording a trace, as shown in Figure 3:
Figure 3. Persistent notification that appears after
starting an on-device system trace- Perform the actions in your app that you’d like the system to inspect .
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. System Tracing saves a device’s activity to a rolling buffer, which holds 10-30 seconds ‘ worth of events .When you’ve completed these actions, stop tracing by tapping either the
System Tracing tile in the Quick Settings panel or on the System Tracing
notification.The system displays a new notification that contains the message ” Saving trace “. When saving is complete, the system dismisses the notification and displays a third notification, confirming that your trace has been saved and that you’re ready to share the system trace, as shown in Figure 4 :
Figure 4. Persistent notification that appears after
the system has finished saving a recorded trace
The app menu allows you to configure several advanced settings related to system tracing and provides a switch for starting and stopping a system trace .
To record a system trace using the System Tracing app menu, complete the following steps :
- Enable developer options, if you haven’t
done so already.Open the Developer Options settings screen. In the Debugging section,
select System Tracing. The System Tracing app opens.Alternatively, if you’ve set up the System Tracing tile,
you can long-tap on the tile to enter the System Tracing app.Make sure Trace debuggable applications is selected to include
applications that have debugging enabled in the system trace.Optionally, choose the Categories of system and sensor calls to trace,
and choose a Per-CPU buffer size (in KB). Choose categories that correspond to the
use case that you’re testing, such as the Audio category for testing
Bluetooth operations or the Memory category for heap allocations.Note:
These categories serve as app-level settings, so the system uses these categories when using the Quick Settings tile, too. In addition, these settings persist across device reboots.
Figure 5. The Record trace switch in the System
Tracing appOptionally, select Long traces to enable traces that are saved continuously
to device storage. For this option, you must set limits for the Maximum
long trace size and Maximum long trace duration.Enable the Record trace switch, highlighted in Figure 5. The tile becomes
enabled, and a persistent notification appears to notify you that the system is
now recording a trace (Figure 3).- Perform the actions in your app that you’d like the system to inspect .
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’ worth of events. If you have Long
traces enabled, the device’s activity is saved continuously to device
storage up to the limits you set.When you’ve completed these actions, stop tracing by disabling the Record
trace switch.The system displays a new notification that contains the message ” Saving trace “. When saving is complete, the system dismisses the notification and displays a third notification, confirming that your trace has been saved and that you’re ready to share the system trace, as shown in Figure 4 .
The System Tracing app helps you share system trace results as part of several
different workflows. On a device running Android 10 (API level 29)
or later, trace files are saved with the.perfetto-trace
filename extension and can be
opened in the Perfetto UI. On a
device running an earlier version of Android, trace files are saved with the
.ctrace
filename extension, which denotes the Systrace format.
System Tracing allows you to share your collected trace with other apps on your device. In doing so, you can send the trace to your development team through an email or a bug-tracking app without needing to connect a device to your development machine .
After you’ve recorded a system trace, tap on the notification that appears on the device ( see Figure 4 ). The platform’s intent picker appears, allowing you to share your trace using the messaging app of your choice .
On devices running Android 10 ( API level 29 ), traces are shown in the Files app. If desired, you can share a trace from this app .
Download report using ADB
If desired, you can also extract a system trace from a device using ADB. Connect the device that recorded the trace to your development machine, then run the following commands in a terminal window :
cd /path-to-traces-on-my-dev-machine && \ adb pull /data/local/traces/ .Converting between trace formats
You can convert Perfetto trace files to the Systrace format. See Converting between trace formats for more information .
Create an HTML report
When sharing your trace, the report itself
resides in a.perfetto-trace
file (on devices running Android 10
or higher) or a.ctrace
file (for all other versions).Create an HTML report from the trace file using a web-based UI or from the command line .
Web-based UI
Use the Perfetto UI to open
the trace file and generate the report.Xem thêm: Top 10 phần mềm quay video trên laptop
For a Perfetto file, click Open trace file. For a Systrace file, click
Open with legacy UI. The legacy UI has the same look and feel as the
Systrace report.Command line
Run the following commands in a terminal window to generate an HTML report from the trace file :
cd /path-to-traces-on-my-dev-machine && \ systrace --from-file trace-file-name{.ctrace | .perfetto-trace}
If you don’t already have the systrace
command-line program, you can download
it from the Catapult
project on GitHub, or directly from the Android Open Source
Project.
Source: https://thomaygiat.com
Category : Ứng Dụng
Máy Giặt Electrolux Lỗi E51 Làm Tăng Nguy Cơ Hỏng Nặng
Mục ChínhMáy Giặt Electrolux Lỗi E51 Làm Tăng Nguy Cơ Hỏng NặngNguyên Nhân Máy Giặt Electrolux Báo Lỗi E511. Động Cơ Hỏng2. Mạch Điều Khiển…
Hậu quả từ lỗi H-29 tủ lạnh Sharp Side by Side
Mục ChínhHậu quả từ lỗi H-29 tủ lạnh Sharp Side by SideMã Lỗi H-29 Tủ Lạnh Sharp Là Gì?Tầm Quan Trọng Của Việc Khắc Phục…
Hỏi đáp giấy dán tường chống ẩm mốc
Mục ChínhGiải Mã 25+ Hỏi Đáp Giấy Dán Tường Chống Ẩm MốcChống ẩm mốc cùng giấy dán tường1. Nguyên nhân gây ẩm mốc trong không…
Máy Giặt Electrolux Lỗi E-45 Kiểm Tra Ngay!
Mục ChínhMáy Giặt Electrolux Lỗi E-45 Kiểm Tra Ngay!Định Nghĩa Mã Lỗi E-45 Máy Giặt ElectroluxNguyên nhân lỗi E-45 máy giặt Electrolux1. Cảm biến cửa…
Hướng dẫn sửa Tủ lạnh Sharp lỗi H-28 chi tiết và an toàn
Mục ChínhHướng dẫn sửa Tủ lạnh Sharp lỗi H-28 chi tiết và an toànLỗi H-28 Trên Tủ Lạnh Sharp Là Gì?Dấu Hiệu Nhận Biết Lỗi…
Máy giặt Electrolux gặp lỗi E-44 điều bạn nên làm
Mục ChínhMáy giặt Electrolux gặp lỗi E-44 điều bạn nên làmĐịnh nghĩa mã lỗi E-44 máy giặt Electrolux5 Nguyên nhân gây ra mã lỗi E-44…