自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
自动反馈导向优化(12 或更高版本)
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Android 12 中引入的 Android 构建系统支持使用自动反馈导向优化 (AutoFDO) 来优化具有蓝图构建规则的原生 Android 模块。AutoFDO 是一种基于采样的优化技术。AutoFDO 会捕获系统二进制文件的运行时行为,使编译器能够优化性能,同时缩减二进制文件的大小。Android 支持从 X86、X86_64、ARM 和 ARM64 设备收集配置文件,尽管配置文件可以跨架构使用。
AutoFDO 是基于插桩的配置文件引导型优化 (PGO) 的继任产品。
与其他基于插桩的配置文件相比,AutoFDO 具有以下额外优势:
对于大多数性能至关重要的项目,AOSP 附带 AutoFDO 配置文件。配置文件收集自手机和平板电脑设备,代表了它们的常规使用模式。这些配置文件位于 toolchain/pgo-profiles/sampling
下。AFDO 在 AOSP 上默认处于启用状态。
为蓝图构建规则启用 AutoFDO
如需为蓝图构建规则启用 AutoFDO,请将 afdo: true
附加到共享库或二进制文件规则。
收集配置文件
AOSP 提供的预捆绑配置文件不支持以下特定场景:
- 添加其他 AutoFDO 项目
- 存在本地修改的代码
- 与您的系统相关的独特使用模式
如果您遇到以下任一情况,必须直接从开发设备或用户设备收集配置文件。
如需详细了解如何准备 ARM 设备以收集 AutoFDO 配置文件,请参阅为 AutoFDO 收集 ETM 数据。
如需了解如何启用自动后台配置文件收集、处理和上传功能,请参阅 Profcollect。
分析 AutoFDO 配置文件
Android 使用标准 LLVM AutoFDO 配置文件。您可以使用 LLVM 的 llvm-profdata
工具读取 AFDO 配置文件。afdo_summary.sh
脚本 (toolchain/pgo-profiles/scripts/afdo_summary.sh
) 会根据 AutoFDO 配置文件自动生成最频繁执行的函数。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-04-06。
[null,null,["最后更新时间 (UTC):2025-04-06。"],[],[],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."]]