Introduced in Android 12, the Android build system supports optimizing native Android modules that have blueprint build rules using Automatic Feedback-Directed Optimization (AutoFDO). AutoFDO is a sampling-based optimization technique. AutoFDO captures the runtime behavior of system binaries, enabling compilers to make better performance optimizations while also reducing binary size. Android supports collecting profiles from X86, X86_64, ARM, and ARM64 devices, although the profiles can be used across architectures.
AutoFDO is the successor for instrumentation-based Profile-Guided Optimization (PGO).
Compared to other instrumentation based profiles, AutoFDO has these additional benefits:
Unobtrusive data collection: AutoFDO profiles can be collected from development or user devices without any modification to build rules.
Real-world usage representation: AutoFDO represents real-world usage behavior assuming profiles are collected from user devices, while instrumentation PGO is representative only of the synthetic collection workload. It isn't generally straightforward to create a collection workload that perfectly matches real world usage.
AOSP ships with AutoFDO profiles for most performance-critical projects. The
profiles were collected from phone and tablet devices, and are representative of
their general usage patterns. The profiles are located under
toolchain/pgo-profiles/sampling
. AFDO is enabled by default on AOSP.
Enable AutoFDO for a blueprint build rule
To enable AutoFDO for blueprint build rules, append afdo: true
to the shared
library or binary rule.
Collect profiles
The prebundled profile provided with AOSP doesn't support these specific scenarios:
- The inclusion of additional AutoFDO projects
- The presence of locally modified code
- Unique usage patterns associated with your system
If you have one of these scenarios, you must gather profiles directly from development or user devices.
For detailed instruction on how to prepare ARM devices for collecting AutoFDO profiles, refer to Collect ETM data for AutoFDO.
For information on how to enable automatic background profile collection, processing, and uploading, see Profcollect.
Analyze AutoFDO profiles
Android uses standard LLVM AutoFDO profiles. The AFDO profiles can be read
using the LLVM's llvm-profdata
tool. The afdo_summary.sh
script
(toolchain/pgo-profiles/scripts/afdo_summary.sh
)
automatically generates the most frequently executed functions according to the
AutoFDO profile.