Add opt-in full-value target-app instrumentation PGO to `ios_ui_test`
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 25/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- objective-c, swift
- Ambito
- build-system, mobile-dev, performance, testing-qa
Direzione di ricerca
Start with the ios_ui_test rule and PR #3037’s collection primitive, then trace the proposed XCTestObservation and XCUIApplication.terminate integration. Review the __llvm_profile_dump() flow and session-token behavior; done means the opt-in journey produces a fresh, validated Coverage.profdata with full value data before target-app termination.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Request
Add an opt-in feature that uses an existing ios_ui_test to collect a target-app PGO profile for later optimized Swift and Clang builds:
ios_ui_test(
name = "JourneyUITests",
test_host = ":App",
features = ["apple.target_app_pgo"],
deps = [":JourneyUITestsLib"],
)
Users should not need to change application source, add support dependencies, configure profile environment variables, or write custom teardown code. The test should publish a validated Coverage.profdata containing execution counters and PGO value records.
Problem
The UI-test runner and target app are separate processes. The useful profile belongs to the target app, so the app must write it before the test terminates it.
PR #3037 provides the runner-side collection and validation. The remaining problem is flushing the profile. Normal-mode LLVM instrumentation writes its data on normal exit or an explicit in-process __llvm_profile_dump() call.
Existing tests often call app.terminate(). In a local Xcode 26.0 simulator reproducer, this terminated the target app by signal. Neither applicationWillTerminate nor atexit ran, and the normal-mode profile stayed empty. Calling __llvm_profile_dump() inside the app before termination produced a valid profile with value data.
LLVM %c continuous mode avoids losing counters on forced termination, but does not serialize value profiles. Counters have a fixed layout that can be memory-mapped; value profiles are runtime-built histograms that need serialization. An explicit dump in continuous mode does not add the missing records.
Those values matter: indirect-call target records can guide indirect-call promotion, and memory-operation size records can guide specialization of operations such as memcpy. This proposal covers instrumentation PGO, not MemProf allocation or lifetime profiling.
Proposed workflow
Use normal-mode profiling and automatically request a dump before terminating the target app:
Build instrumented test host
Run existing UI test
Request a dump inside the target app
Wait for success
Terminate the app
Collect and merge profiles into Coverage.profdata
The proposed implementation would:
- Apply a configuration transition to
test_hostand its relevant dependencies, enabling Swift-profile-generateand Clang-fprofile-generate. Ordinary and release builds remain unchanged. - Inject a small profile-control endpoint into the target app and a controller into the UI-test bundle. No manually declared support dependencies are needed.
- Intercept
XCUIApplication.terminate()only for the configured test host. Request a dump, wait for acknowledgment, then call the original termination method. A timeout or failed dump fails the test. - Use an
XCTestObservationfallback to dump when a test finishes with the app still running. Provide explicit checkpoint and dump-then-terminate APIs for advanced tests. - Give both processes a unique per-run session token. Activate the endpoint only in the opt-in instrumented configuration, with
LLVM_PROFILE_FILEand a valid token. Serialize concurrent requests and avoid writing the same completed dump again. - Build on #3037 to clear stale outputs, collect only fresh profiles, merge with
llvm-profdata, validate the result, and publish raw profiles plusCoverage.profdata.
A filename such as %t/target-app-pgo/<session>/%p-%m.profraw separates processes and images. %m supports online merging when a complete dump occurs; it is not continuous mode. The runner then merges the separate outputs into the final artifact.
rules_apple owns the test-host configuration, support-library injection, runner environment, and test outputs. LLVM already provides the dump API, so a new compiler-rt protocol should not be required for the first version.
Initial scope
- Simulator
ios_ui_testwith one configured target app. - Swift and Clang normal-mode IR instrumentation, including counters and selected value records.
- Multiple launches or app processes merged into one artifact.
- Physical devices and a generic upstream compiler-rt control protocol can follow later.
Acceptance criteria
- One documented feature enables the workflow without app source changes, manual support dependencies, or custom teardown.
- Only the test-host configuration is instrumented; tests without the feature keep their existing behavior and build graph.
- Existing
app.terminate()calls wait for a successful target-app dump. Tests that leave the app running also receive a final dump. - Explicit dump and dump-then-terminate APIs are available.
- Multiple launches or processes produce non-conflicting profiles that merge successfully.
- An integration test proves the merged profile contains IR counters, an indirect-call target record, and a memory-operation size record.
- Missing, empty, stale, malformed, timed-out, or unacknowledged profiles fail deterministically.
- The control endpoint is disabled outside the opt-in profiled test configuration.
Questions for maintainers
- Is
apple.target_app_pgothe right feature name? - Should the support endpoint live in
rules_apple,apple_support, or another target? - Should explicit checkpoint APIs ship in the first version?
- Should physical-device support be required initially or follow later?
- Should a generic compiler-rt control protocol be proposed after this integration proves the approach?
Related: PR #3037 provides the collection primitive. Issue #338 covers broader Apple-platform coverage support.
AI assistance
I used AI assistance for the investigation, reproducer, compiler-rt source review, and drafting. I reviewed the reproduced behavior and proposed architecture.
- Lingua principale
- Starlark
- Stelle
- 600
- Fork
- 354
- Merge medio
- 2g 7h
- PR unite (30g)
- 8
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di bazelbuild/rules_apple
-
`ios_xctestrun_runner` skips the simulator cleanup action on early exits and signalsForse già presa @katre l’ha presa 2 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 67/100
bazelbuild/rules_apple#3163 ·
I maintainer di solito rispondono entro 1 giorno
-
register_binary_linking_action links with the GCC coverage map format under coverageForse già presa @TrapsterDK l’ha presa 6 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 30/100
bazelbuild/rules_apple#3160 ·
I maintainer di solito rispondono entro 1 giorno
-
Registered toolchains load //apple/internal and its dependencies in every buildForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 30/100
bazelbuild/rules_apple#3158 ·
I maintainer di solito rispondono entro 1 giorno
-
Simulator cleanup is skipped when the post-action failsForse già presa @vakhidbetrakhmadov l’ha presa 14 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 58/100
bazelbuild/rules_apple#3147 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
bazelbuild/rules_apple#3139 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di bazelbuild/rules_apple
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
bazelbuild/apple_support#707 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
-
blocky: new version 0.38.0Apertaout-of-date
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
CachyOS/CachyOS-PKGBUILDS#2232 ·
I maintainer di solito rispondono entro 1 giorno
-
blast/large refactor risk/low spend-dem
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
chriskelly/MusicWall#87 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 77/100