自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
自動根據意見回饋進行最佳化 (12 以上版本)
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Android 12 推出的 Android 建構系統,可使用自動回饋導向最佳化 (AutoFDO) 技術,針對具有設計圖建構規則的原生 Android 模組進行最佳化。AutoFDO 是一種以取樣為基礎的最佳化技巧。AutoFDO 會擷取系統二進位檔的執行階段行為,讓編譯器進行更佳的效能最佳化,同時縮減二進位檔大小。Android 支援從 X86、X86_64、ARM 和 ARM64 裝置收集設定檔,但這些設定檔可跨架構使用。
AutoFDO 是基於檢測的設定檔引導最佳化 (PGO) 的後繼者。
與其他以檢測為基礎的設定檔相比,AutoFDO 具有以下額外優點:
AOSP 會為大部分效能至關重要的專案提供 AutoFDO 設定檔。這些設定檔是從手機和平板電腦裝置收集而來,代表使用者一般使用模式。設定檔位於 toolchain/pgo-profiles/sampling
下方。AOSP 預設會啟用 AFDO。
為藍圖建構規則啟用 AutoFDO
如要為藍圖建構規則啟用 AutoFDO,請將 afdo: true
附加至共用程式庫或二進位規則。
收集設定檔
AOSP 提供的預先內含設定檔不支援以下特定情況:
- 納入其他 AutoFDO 專案
- 是否有本機修改的程式碼
- 與系統相關的獨特使用模式
如果您遇到上述任一情況,就必須直接從開發人員或使用者的裝置收集設定檔。
如需詳細的操作說明,瞭解如何準備 ARM 裝置以收集 AutoFDO 設定檔,請參閱「收集 AutoFDO 的 ETM 資料」。
如要進一步瞭解如何準備 X86 裝置以收集 AutoFDO 設定檔,請參閱「收集 AutoFDO 的 LBR 資料」。
如要進一步瞭解如何啟用自動背景剖析資料收集、處理和上傳功能,請參閱「Profcollect」。
分析 AutoFDO 設定檔
Android 使用標準 LLVM AutoFDO 設定檔。您可以使用 LLVM 的 llvm-profdata
工具讀取 AFDO 設定檔。afdo_summary.sh
指令碼 (toolchain/pgo-profiles/scripts/afdo_summary.sh
) 會根據 AutoFDO 設定檔自動產生執行頻率最高的函式。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[[["容易理解","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-07-27 (世界標準時間)。"],[],[],null,["# Automatic Feedback-Directed Optimization (12 or higher)\n\nIntroduced in Android 12, the Android build system supports optimizing native\nAndroid modules that have blueprint build rules using *Automatic\nFeedback-Directed Optimization (AutoFDO)*. AutoFDO is a sampling-based\noptimization technique. AutoFDO captures the runtime behavior of system\nbinaries, enabling compilers to make better performance optimizations while also\nreducing binary size. Android supports collecting profiles from X86, X86_64,\nARM, and ARM64 devices, although the profiles can be used across architectures.\n\nAutoFDO is the successor for instrumentation-based Profile-Guided Optimization\n(PGO).\n\nCompared to other instrumentation based profiles, AutoFDO has these additional\nbenefits:\n\n- Unobtrusive data collection: AutoFDO profiles can be collected from\n development or user devices without any modification to build rules.\n\n- Real-world usage representation: AutoFDO represents real-world usage behavior\n assuming profiles are collected from user devices, while instrumentation PGO\n is representative only of the synthetic collection workload. It isn't\n generally straightforward to create a collection workload that perfectly\n matches real world usage.\n\nAOSP ships with AutoFDO profiles for most performance-critical projects. The\nprofiles were collected from phone and tablet devices, and are representative of\ntheir general usage patterns. The profiles are located under\n`toolchain/pgo-profiles/sampling`. AFDO is enabled by default on AOSP.\n\nEnable AutoFDO for a blueprint build rule\n-----------------------------------------\n\nTo enable AutoFDO for blueprint build rules, append `afdo: true` to the shared\nlibrary or binary rule.\n\nCollect profiles\n----------------\n\nThe prebundled profile provided with AOSP doesn't support these specific\nscenarios:\n\n- The inclusion of additional AutoFDO projects\n- The presence of locally modified code\n- Unique usage patterns associated with your system\n\nIf you have one of these scenarios, you must gather profiles directly from\ndevelopment or user devices.\n\nFor detailed instruction on how to prepare ARM devices for\ncollecting AutoFDO profiles, refer to\n[Collect ETM data for\nAutoFDO](https://android.googlesource.com/platform/system/extras/+/refs/heads/android16-release/simpleperf/doc/collect_etm_data_for_autofdo.md).\n\nFor detailed instruction on how to prepare X86 devices for\ncollecting AutoFDO profiles, refer to [Collect LBR data for\nAutoFDO](https://android.googlesource.com/platform/system/extras/+/refs/heads/android16-release/simpleperf/doc/collect_lbr_data_for_autofdo.md).\n\nFor information on how to enable automatic background profile collection,\nprocessing, and uploading, see\n[Profcollect](https://android.googlesource.com/platform/system/extras/+/refs/heads/android16-release/profcollectd/README.md).\n\nAnalyze AutoFDO profiles\n------------------------\n\nAndroid uses standard LLVM AutoFDO profiles. The AFDO profiles can be read\nusing the LLVM's `llvm-profdata` tool. The `afdo_summary.sh` script\n([`toolchain/pgo-profiles/scripts/afdo_summary.sh`](https://cs.android.com/android/platform/superproject/+/android-latest-release:toolchain/pgo-profiles/scripts/afdo_summary.sh))\nautomatically generates the most frequently executed functions according to the\nAutoFDO profile."]]