fix(native-profiler): fall back to host all-processes Time Profiler when the simulator Instruments tap is broken#312
Draft
filip131311 wants to merge 1 commit into
Draft
Conversation
…hen the simulator Instruments tap is broken On Xcode 26.x / Instruments 16, xctrace can no longer package a `--device <udid> --attach <app>` simulator trace (coreprofilesessiontap fails), which breaks native profiling on the simulator entirely. When device-attach fails on a simulator, transparently fall back to a host `--all-processes` Time Profiler recording and scope the results to the app's host PID. This path is CPU-only by construction — Leaks and Allocations cannot target "All Processes" — so hangs/leaks export is skipped and their absence is no longer reported as a failure. - start: detect the app's host PID, retry device-attach, then fall back to a host-wide Time Profiler scoped to that PID. Clears stale .trace bundles between attempts. Only falls back on simulators. - pipeline: filterSamplesByPid scopes a host-wide trace to the app via the `(AppName, pid: N)` thread fmt tag. - analyze: emit an "Analysis Inconclusive" report (never "All clear") when the only data source produced no readable/app-matching samples. - metadata sidecar: persist mode/pid/appProcess next to the trace so a different tool-server process can reconstruct app-scoped analysis on profiler-load. - export: ExportOptions.keys to restrict export to CPU in fallback mode. - tests: host-fallback PID scoping + inconclusive reporting; update stop-recovery for the new export signature.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On Xcode 26.x / Instruments 16,
xctracecan no longer package a--device <udid> --attach <app>simulator trace —coreprofilesessiontapfails during packaging. This breaks native profiling on the simulator entirely:native-profiler-starteither errors out or produces an unusable trace.Fix
When the device-attach recording fails on a simulator, transparently fall back to a host
--all-processesTime Profiler recording and scope the results to the app's host PID.Because Leaks/Allocations cannot target "All Processes", this fallback path is CPU-only by construction — hangs/leaks are intentionally not captured, and their absence is no longer surfaced as an export failure. Physical devices keep the original behavior (their processes aren't host processes, so there's nothing to fall back to — the original error is surfaced).
What changed
native-profiler-start— resolve the app's host PID, retry device-attach (bounded, for cold-start races), then fall back to a host-wide Time Profiler scoped to that PID. Clears stale.tracebundles between attempts. Returnsmode+processFilterPid.pipeline—filterSamplesByPidscopes a host-wide trace down to the app using the(AppName, pid: N)thread-fmt tag (anchored on the closing paren so111never matches1110).native-profiler-analyze— emits an "Analysis Inconclusive" report (never "All clear") when the only data source produced no readable / app-matching samples, so an empty fallback trace isn't mistaken for a clean run. Suppresses hangs/leaks "export failed" noise in fallback mode.metadata.ts) — persistsmode/processFilterPid/appProcessnext to the trace, so a different tool-server process can reconstruct app-scoped analysis onprofiler-load load_native.export—ExportOptions.keysrestricts export to CPU in fallback mode.native-profiler-stop— writes the sidecar and threads mode/pid through the result.Tests
host-fallback.test.ts— PID scoping (drops unrelated host processes) + inconclusive reporting when CPU is empty/unreadable.stop-recovery.test.ts— updated for the newexportIosTraceDatasignature.🤖 Generated with Claude Code