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 consolidatedperffamily for token-efficient memory diagnostics and artifact escalation.Before, agents had to choose between broad
perf metricspayloads or raw platform output such asdumpsys meminfo,am dumpheap, andleaks, which is noisy, platform-specific, easy to over-fetch, and risky to paste into model context. After this change, agents get a compact first-pass memory view and can escalate to heap/memgraph files without dumping large artifacts into CLI/MCP/default JSON output.Examples:
Compact sample shape:
{ "metrics": { "memory": { "available": true, "totalPssKb": 562958, "totalRssKb": 570304, "topConsumers": [{ "name": "Dalvik Heap", "pssKb": 213456 }] } } }Default snapshot output:
Why this is helpful:
perf memory samplekeeps arrays bounded, reports top offenders compactly, preserves the same memory source asperf metrics, and omits unrelated startup/CPU/frame data.perf memory snapshotreturns path, size, kind, method, and support metadata while heap/memgraph data stays as a file for external inspection.artifact.available=falsewith stable reason/hint instead of pretending a heap or memgraph was captured.leaks --outputGraphtimeout, cleans partial local artifacts on nonzero/timeout/empty files, and reports physical iOS or missing simulator process tools as unavailable.--kindnow uses one perf-kind model forxctrace,simpleperf,perfetto,android-hprof, andmemgraph;perf memory snapshotdeliberately narrows that toandroid-hprof|memgraph.--kindvalues no longer trigger deferred Metro config or confusing Metro errors.Refs #698. Parent context: #694.
Docs/skills impact: updated versioned CLI help, website command/debugging/client docs, and SkillGym planning guidance. Agents can discover this through
agent-device help, wherehelp debuggingnow calls out perf memory, andagent-device help debuggingincludes commands, example output, and guidance on why this is better than raw memory dumps.skills/**/SKILL.mdwas not updated; repo guidance routes command behavior through versioned CLI help.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.Touched-file count: 35. Scope spans perf command contracts, 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.
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
Latest branch validation:
pnpm exec vitest run src/utils/__tests__/args.test.ts(111 tests passed)pnpm formatpnpm check:quickgit diff --checkReview follow-up validation:
git rebase origin/mainsucceeded against3780ca6ed.src/__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,src/__tests__/remote-connection.test.ts(8 files / 106 tests passed)pnpm check:unit(247 unit files / 2381 tests passed; 8 smoke tests passed)pnpm buildEarlier 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.SkillGym:
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.