Skip to content

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
mainfrom
fix/native-profiler-sim-fallback
Draft

fix(native-profiler): fall back to host all-processes Time Profiler when the simulator Instruments tap is broken#312
filip131311 wants to merge 1 commit into
mainfrom
fix/native-profiler-sim-fallback

Conversation

@filip131311

Copy link
Copy Markdown
Collaborator

Problem

On Xcode 26.x / Instruments 16, xctrace can no longer package a --device <udid> --attach <app> simulator trace — coreprofilesessiontap fails during packaging. This breaks native profiling on the simulator entirely: native-profiler-start either errors out or produces an unusable trace.

Fix

When the device-attach recording 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.

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 .trace bundles between attempts. Returns mode + processFilterPid.
  • pipelinefilterSamplesByPid scopes a host-wide trace down to the app using the (AppName, pid: N) thread-fmt tag (anchored on the closing paren so 111 never matches 1110).
  • 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 sidecar (metadata.ts) — persists mode / processFilterPid / appProcess next to the trace, so a different tool-server process can reconstruct app-scoped analysis on profiler-load load_native.
  • exportExportOptions.keys restricts 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 new exportIosTraceData signature.

🤖 Generated with Claude Code

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant