ATrace 使用外部 crate tracing_android_trace 对 HAR 执行性能跟踪。
为 HAR 启用跟踪
如需为参考 harry-app 启用性能跟踪,请启用 Cargo 功能 harry-app-platform-specific/tracing-android。
# crates/reference/harry-app/Cargo.toml
harry-sdv = ["harry-app-platform-specific/tracing-android", ...]
向 HAR 添加自定义跟踪记录
let custom_trace = tracing::info_span!("custom_trace_span").entered()
// code here will be traced
drop(custom_trace)

图 1. Perfetto 界面,显示了来自 harry 进程 (HAR) 的示例轨迹
DriverUI 的性能跟踪
DriverUI 使用 Android 系统跟踪,无需进行额外配置。
向 DriverUI 添加自定义轨迹
收集轨迹
我们建议使用 Torq 在 AAOS 上收集轨迹。
使用 Torq
Torq 是一款用于在 AAOS 和 SDV 上收集性能轨迹的 CLI 工具。
克隆 Torq 代码库。
按照代码库中的说明进行构建,然后运行:
export ANDROID_SERIAL=<your_device_serial>
# Collect a 7 second trace
torq -d 7000
收集两个虚拟机的统一性能跟踪记录
由于显示安全功能在两个虚拟机上运行,因此同时从这两个虚拟机收集轨迹有助于发现问题。
- Torq 通过 Perfetto 的
traced_relay支持统一跟踪。 - 如需捕获统一轨迹,请先确定两个虚拟机的 cid:
# Get the cid for SDV Media VM. For example: 3
adb -s <sdv_media_vm_serial> shell getprop ro.sdv.vsock_local_cid
# Get the cid for SDV IVI VM. For example: 4
adb -s <sdv_ivi_vm_serial> shell getprop ro.sdv.vsock_local_cid
在此示例中,使用 SDV-Media 虚拟机 (cid=3) 作为中继。
# Configure your VMs for unified tracing
torq vm configure --primary <sdv_ivi_vm_serial> --primary-cid 4 --secondary <sdv_media_vm_serial>
# Collect a 7 second trace from the SDV IVI VM, it will now collect a unified trace
torq --serial <sdv_ivi_vm_serial> -d 7000
例如:

图 2. Perfetto 界面,其中显示了一个示例统一轨迹,包含来自两个虚拟机的两个进程:harry (HAR) 和 com.android.car.driverui (DriverUI)。
收集启动轨迹
如需收集启动轨迹以分析启动性能,您必须启用一些标志。
为启动轨迹设置 SDV 特有的持久性标志。
export ANDROID_SERIAL=<your_device_serial> adb root adb shell setprop persist.debug.sdv.boottrace 1 adb shell setprop persist.debug.perfetto.boottrace 1设置内核 cmdline 参数
androidboot.fastboot.boottrace=enabled。
# For Cuttlefish, set when creating CVD
cvd create -extra_kernel_cmdline=androidboot.fastboot.boottrace=enabled
使用 record_android_trace
执行以下操作:
# Set your adb device serial
export ANDROID_SERIAL=<your_device_serial>
# Run record_android_trace from the Android repo
cd /<your_repo_path>
build/envsetup.sh
$ANDROID_BUILD_TOP/external/perfetto/tools/record_android_trace --config $ANDROID_BUILD_TOP/system/software_defined_vehicle/core_services/samples/tracing/config/trace_cfg.pbtx