feat: add perf memory diagnostics#759
Conversation
|
Size Report
Startup median (7 runs, lower is better):
Top changed chunks:
|
Code reviewVerdict: minor issues — implementation is solid and well-tested, but one likely real-world failure (Apple memgraph timeout) and very high merge-conflict risk with the sibling perf PRs. Findings
Verified cleanNo command injection — host-side adb/xcrun/leaks invocations are array-arg, the remote heap path is sanitized, OverallWell-structured, reuses the perf scaffolding cleanly, good happy-path plus several failure-path tests. The biggest code concern is the 15 s Generated by Claude Code |
fb44a58 to
3f96bee
Compare
|
Review follow-up pushed in Addressed:
Validation:
Sibling PR reconciliation: no base PR is required. The branch now exposes one shared perf-kind enum for the expected trace/profile/artifact backends and keeps Metro-specific kind handling on |
Summary
Adds
perf memoryunder the consolidated perf family for compact memory diagnostics and artifact escalation.perf memory sample --jsonreturns a memory-focused payload using the same sampling sources asperf metrics, whileperf memory snapshotwrites large heap/memgraph artifacts to disk and returns only compact path/metadata.Implements Android HPROF capture with package/PID resolution, remote cleanup, artifact pull metadata, bounded
topConsumers, and actionable failure hints for non-debuggable/profileability and pull failures. Adds Apple memgraph support matrix behavior: iOS simulator/macOS attempt host-visibleleaks --outputGraph, physical iOS reports unavailable, and simulator runtimes without process tools return explicit unavailable artifact responses.Refs #698. Parent context: #694.
Touched-file count: 31. Scope expanded across perf command contract, CLI/client/MCP metadata, daemon routing, Android/Apple platform helpers, provider scenarios, docs, and SkillGym guidance because this command crosses the public command surface and artifact lifecycle.
Docs/skills impact: updated versioned CLI help, website command/debugging/client docs, and SkillGym planning guidance. Did not update
skills/**/SKILL.md; repo guidance says skills should route to versioned CLI help unless explicitly requested.Support matrix:
perf memory sample: supported for active app package sessions viadumpsys meminfo.perf memory snapshot --kind android-hprof: supported whenam dumpheapcan inspect the running app process; non-debuggable/profileability failures return actionable hints.perf memory sample: same support as existing Apple memory metric path.perf memory snapshot --kind memgraph: supported for iOS simulator/macOS app sessions when host/simulator process tools are present; physical iOS reports unavailable.heapprofd: intentionally deferred until Perfetto/heapprofd plumbing from the trace slice is available; no dependency on unmerged Add Android native CPU and Perfetto profiling under perf #696/Add Apple xctrace CPU profiling under perf #697/Add narrow debug symbols workflow for crash symbolication #699 code.Residual risk: iOS simulator memgraph depends on runtime-provided process tools (
ps/leaks) and macOS inspection permissions; unsupported environments now return explicit unavailable metadata.Validation
Automated:
pnpm formatpnpm typechecksrc/__tests__/cli-perf.test.ts,src/__tests__/client.test.ts,src/utils/__tests__/perf-args.test.ts,src/daemon/handlers/__tests__/session-observability.test.ts,src/platforms/android/__tests__/perf.test.ts,src/platforms/ios/__tests__/perf.test.ts,test/integration/provider-scenarios/android-lifecycle.test.ts(72 tests passed)pnpm check:unit(247 unit files / 2335 tests passed; 8 smoke tests passed)pnpm buildgit diff --checkSkillGym:
pnpm test:skillgym:case perf-memory-diagnosticsis blocked in this sandbox by external-runner data-export policy. The first guarded run reported sandbox network disabled; the escalated run was denied because it would send workspace-derived prompts to external Codex/Claude runners.Manual E2E evidence:
Pixel 9 Pro XL API 37, serialemulator-5554.com.justforfun.neoncity, sessionperf-memory-android:perf metrics --jsonsucceeded withmemory.totalPssKb=571406,memory.totalRssKb=578720, and bounded top consumers includingNative Heap.perf memory sample --jsonsucceeded with onlymetrics.memoryplus memory/snapshot sampling metadata; sample includedtotalPssKb=562958,totalRssKb=570304, 5 top consumers.perf memory snapshot --kind android-hprof --out /private/tmp/agent-device-neoncity.hprofreachedam dumpheapand failed withSecurityException: Process not debuggable, returning hint: use a debuggable/profileable build.host.exp.exponentwas also tried for HPROF and returned the same non-debuggable process failure. No local HPROF artifact was created in this environment.iPhone 17, UDIDD74E0B66-57EB-4EC1-92DC-DA0A30581FE7.com.callstack.agentdevicelab, sessionperf-memory-ios:perf metrics --jsonsucceeded for startup; simulator CPU/memory metric path reportedsimctl spawn psunavailable (No such file or directory).perf memory sample --jsonreturned onlymetrics.memorywith the same unavailable reason.perf memory snapshot --kind memgraph --out /private/tmp/agent-device-ios.memgraphreturned success withartifact.available=false, reason that this simulator runtime did not provideps, and a hint to retry on a simulator runtime with process tools.Manual session hygiene: opened
perf-memory-androidandperf-memory-ios; later validation reset daemon metadata, so matching close attempts initially returnedSESSION_NOT_FOUND. After final daemon cleanup/reopen,perf-memory-ioswas closed successfully.