Android Macrobenchmark and Profile Guided Optimization Harness
Author a continuous performance benchmarking script that measures frame timing, memory churn, and baseline profile generation.
Use this template when delivering client performance engagements for critical Android applications. It generates automation to orchestrate Jetpack Macrobenchmark runs, profile compilation, and metric regression tracking.
Role: Staff Android Performance Engineer specializing in runtime optimization and professional services client delivery.
Context
- Client portfolio account: {{consultancy_client}}
- Application module identifier: {{app_module_name}}
- Benchmark iteration volume: {{benchmark_iteration_count}}
- Test device serial ID: {{target_device_serial}}
- Critical user workflow: {{critical_user_journey}}
- Baseline profile destination: {{baseline_profile_path}}
Task
Generate an end-to-end Gradle Kotlin Script (KTS) and Shell execution pipeline that executes automated Jetpack Macrobenchmark tests on {{target_device_serial}}, evaluates frame render metrics (Jank and 99th percentile frame times) during {{critical_user_journey}}, compiles an optimized baseline profile to {{baseline_profile_path}}, and outputs performance regressions for {{consultancy_client}}.
Method
- Configure Android Gradle Plugin test task definitions for {{app_module_name}} with non-minified release configurations.
- Initialize ADB lock-clocks routines on {{target_device_serial}} to minimize thermal throttling skew.
- Execute the Jetpack Macrobenchmark suite with {{benchmark_iteration_count}} warmup and measurement iterations.
- Profile UI render metrics specifically capturing FrameTimingMetric and StartupTimingMetric during {{critical_user_journey}}.
- Extract raw Perfetto trace files and dump summary metrics to a consolidated CSV and JSON file.
- Generate an updated baseline profile file and copy it into {{baseline_profile_path}}.
- Evaluate metric deltas against historical thresholds and trigger exit code 1 if jank frames exceed 5%.
Constraints
- MUST write valid Gradle KTS and Shell automation scripts with complete syntax.
- MUST NOT use deprecated Android Performance Tuner APIs or unpinned benchmark plugin versions.
- Baseline profile generation steps MUST strictly compile using dex2oat compilation modes (speed-profile).
- Script MUST fail gracefully if {{target_device_serial}} is disconnected or unrooted for lock-clocks.
Output format
- Section 1: Gradle KTS Benchmark Configuration Block (30-50 lines)
- Section 2: Complete Shell Benchmark Orchestration Script (60-100 lines)
- Section 3: Automated Metric Regression Parser Script (Python, 40-60 lines)
- Section 4: CI/CD Pipeline Integration Steps (maximum 200 words)
Self-review
- Confirm that {{consultancy_client}}, {{app_module_name}}, {{benchmark_iteration_count}}, {{target_device_serial}}, {{critical_user_journey}}, and {{baseline_profile_path}} are correctly referenced.
- Validate that ADB thermal clock locking commands contain restoration fallback logic upon script termination.
- Ensure Perfetto trace extraction paths handle spaces and special characters safely.
Explicit role, a named task, and discrete steps the model can follow.
Background, inputs and variables the model needs before it starts.
Hard boundaries — what the model must and must not do.
A named, field-level shape for the response.
Ordered work items that force analysis before an answer.
Length and structure that travel across frontier models.
Signal density — instruction weight without padding.
Documented variables so the scaffold adapts to new inputs.
Quality bar, assumptions and behaviour when inputs are thin.
How much real usage the template has behind it.