refactor(platform-apple): dedupe xctrace logic behind perf-xctrace and split perf.ts - #2823
Conversation
Size Report
Startup median (7 runs, lower is better):
|
|
Reviewed at 709524a. The refactor looks sound, but merge readiness depends on evidence this PR does not yet have. I looked for a smaller design and did not find one. The perf-target move looks like the minimum split needed to get perf.ts under 1,000 lines and break the perf.ts/perf-xctrace.ts cycle, the record-attempt callback looks like the smallest seam that lets the timed and background retry loops share one implementation, and the devicectl change is in scope because issue #2795 requires it. Does that match the intent, or is there a narrower cut I'm missing? Not blocking: readDirectXmlProcess is not byte-equivalent to either old resolver (trim-before-suffix-strip changes 'Foo (12) ' to 'Foo', a placeholder child element now resolves to null instead of the old fmt name, and empty pid text now gives null instead of 0), runIosDevicectlJsonRequest's cleanup-on-throw and failure-payload paths have no test coverage, and the readiness probe's reordered Two things still need a live run on a physical iOS device. One call through ensureCoreDeviceReady (for example No live device was available for this review, so the reordered devicectl argv is not confirmed to work. I did not run the test suite myself; the PR reports it passed at 709524a. CI was still pending at review time: all non-passing jobs were queued or in progress, none had failed, and the diff touches perf and devicectl code that Typecheck, Coverage, Integration, and Bundle Size exercise, while Smoke Tests do not drive physical-device perf or CoreDevice readiness. The next step is a live run on a physical iOS device showing ensureCoreDeviceReady return ready with the reordered probe, followed by green CI. |
|
Reviewed at 07c5a53. The CoreDevice readiness probe now goes through Not blocking: the three new forwarders in The Smoke Tests failure at The next step is the physical-device run above. |
…checks behind perf-xctrace perf.ts now delegates timed xctrace recording, table export and the trace-has-data check to perf-xctrace.ts, which owns one record-argv builder, one retry loop, one export implementation and one data check. Process-target resolution moves to perf-target.ts so perf-xctrace no longer imports perf.ts, bringing perf.ts under 1,000 lines. perf.ts and perf-frame.ts share one xctrace XML reference resolver in perf-xml.ts. physical-device-coredevice.ts reads device details through the shared devicectl --json-output helper, which now carries the failure payload and cleans up its temp file when the command throws. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…hared process-name reader Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
… facade perf-facade.ts, perf.ts, and perf-xctrace.ts all statically imported the newly split perf-target.ts, adding it as a genuinely new eager module to the facade's closure. Load it on demand at each call site instead, the same pattern already used by simctl-facade.ts and runner-operations-facade.ts, keeping the facade's process-target path implementation-lazy.
…from the perf facade readAppleProcessSamples, resolveAppleExecutable and resolveIosDevicePerfTarget had no importer through @agent-device/platform-apple/perf; perf.ts and perf-xctrace.ts load perf-target.ts directly. The package is private and the async forwarders were added on this unreleased branch, so remove them and their .fallowrc.json entries instead of keeping them alive by allowlist. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
07c5a53 to
c5681af
Compare
|
Addressed at 1. CoreDevice readiness argv (blocking). A physical-device run is still outstanding: this host has no physical iOS device attached, only simulators. To close it on a physical iPhone, run What I could check without a device (Xcode 27.0, devicectl 651.13.4):
2. Facade forwarders (non-blocking). Removed Simulator perf, partial xctrace coverage. On the iPhone 17 Pro simulator with Settings:
🤖 Generated with Claude Code |
|
This is clean at c5681af. The Smoke failure I saw at the earlier head is fixed by #2832, and this branch is now rebased onto fa3b729 so it picks that fix up. All 18 checks are green, and the facade deletion here does not touch any route that was failing. The devicectl argv question from the earlier review is closed on your host evidence: real devicectl returned ready on a CoreDevice-visible simulator, parsing matched for bogus ids, and an unknown-option control failed differently. That does not cover a physical iPhone, where the only different payload content is tunnelState, and its parser is unchanged, so the residual risk there is small. The timed I did not run tests or fallow, and I did not check Nothing here needs to happen before merge. If you want extra confidence, a maintainer could still run |
|
|
Physical-device run at Readiness (
perf (same session)
One caveat: the phone was locked. The first two
The AgentDeviceTester numbers come from its process showing the Expo dev-client launcher, because Metro on localhost is unreachable from the device. They prove the attach, record and export plumbing, not the app's own frame or memory profile. The argv is identical in the locked and unlocked runs, so this PR is not involved. Session closed and daemon stopped with 🤖 Generated with Claude Code |
Summary
Closes #2795. No change to perf output shapes, messages or error details.
perf.ts(1,111 → 690 lines) hands timed xctrace recording, table export and the trace-has-data check toperf-xctrace.ts. That file now has one record-argv builder, one retry loop (used by both timed and background recording), oneexportAppleXctraceData, and one data check.perf-target.ts, with itsparseApplePsOutputtest moved unchanged intoperf-target.test.ts. This removes theperf.ts↔perf-xctrace.tsimport cycle. The@agent-device/platform-apple/perffacade exports the same names as before.perf.tsandperf-frame.tsshare one XML ref resolver inperf-xml.ts.physical-device-coredevice.tsnow callsrunIosDevicectlJsonRequest. That helper now returns the failure payload, which keepstunnelStateon not-ready errors, and removes its temp file when the command throws.Where the issue doesn't match current code: the four export wrappers were split two in
perf-xctrace.tsand two inperf.ts, and line numbers have moved.11 files. Gross diff is 1,253 lines: about 400 are the required
perf-targetmove and the net change is −131.Validation
Tested at
c5681af5e(rebased ontoorigin/mainfa3b7291ffor the #2832 Smoke fix).pnpm check:affected --run: passed..fallowrc.jsonfails open to the full local set; vitest-related ran 419 files and 2,961 tests.pnpm check:fallow --base origin/main: no issues. The three removed forwarders' entries were deleted by hand; baselines are unchanged.readAppleProcessSamples,resolveAppleExecutableandresolveIosDevicePerfTargetare removed.@agent-device/platform-appleisprivate, and the async forwarders came from07c5a537b, which no tag contains.devicectl651.13.4 on Xcode 27.0 (27A5252f):devicectl device info details --device <id> --json-output <path> --timeout 15.devicectl device info details --device <id> --timeout 15 --json-output <path>. This is the orderdevicectl device info details --helpgives in USAGE.00000000-…), both orders exit 1 withThe specified device was not found(CoreDeviceError 1000). Both write the same JSON; only the order ofinfo.argumentsdiffers. For comparison, an unknown option exits 64 withUnknown option.ensureCoreDeviceReadyfromorigin/mainand from this branch through realdevicectl(argv captured by anxcrunshim): a bogus id gives identicalnot_readydetails on both, and a simulator visible to CoreDevice returns ready on both. Temp JSON files were removed afterwards.perf memory samplereturnedps-process-snapshot(lazyperf-targetpath).perf cpu profile start/stop --kind xctracerecorded a trace (shared record argv, retry loop, trace-data check).perf cpu profile reportexported--tocand thetime-profiletable, then ended withApple xctrace CPU report contained no samples.origin/mainparses the same XML to the same zero, because Xcode 27 emits<tagged-backtrace>and the parser only reads<backtrace>. That is a pre-existing issue and not part of this PR.recordAppleXctraceTimedTrace(Animation Hitches / Activity Monitor with--time-limit), the device target resolution through devicectl, andperf frames.open <app> --debug, thenperf framesandperf memory samplein the same session.🤖 Generated with Claude Code