HAR 的效能追蹤

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 中新增自訂追蹤記錄

  • 如要新增自訂 span,請使用 tracing crate 的 span。
    let custom_trace = tracing::info_span!("custom_trace_span").entered()
    // code here will be traced
    drop(custom_trace)

圖 1. Perfetto UI 顯示 harry 程序 (HAR) 的追蹤記錄範例

DriverUI 的效能追蹤

DriverUI 使用 Android 系統追蹤,不需要額外設定。

在 DriverUI 中新增自訂追蹤記錄

您可以參閱開發人員指南,在 Kotlin 程式碼中加入自訂事件。

收集追蹤記錄

建議使用 Torq 收集 AAOS 的追蹤記錄。

使用 Torq

Torq 是 CLI 工具,用於收集 AAOS 和 SDV 的效能追蹤記錄。

  1. 複製 Torq 存放區。

  2. 請按照存放區中的操作說明建構,然後執行:

export ANDROID_SERIAL=<your_device_serial>
# Collect a 7 second trace
torq -d 7000

收集兩個 VM 的統一效能追蹤記錄

由於 Display Safety 會在兩個 VM 上執行,因此同時從兩個 VM 收集追蹤記錄,有助於找出問題。

  • Torq 透過 Perfetto 的 traced_relay 支援統一追蹤記錄。
  • 如要擷取統一追蹤記錄,請先找出兩個 VM 的 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 VM (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 UI 顯示統一追蹤記錄範例,其中包含兩個 VM 的程序:harry (HAR) 和 com.android.car.driverui (DriverUI)。

收集開機追蹤記錄

如要收集啟動追蹤記錄來分析啟動效能,您必須啟用一些標記。

  1. 設定開機追蹤記錄的 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
    
  2. 設定核心 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