feat(ios-profiler): attributable memory leaks via malloc_stack_logging#351
Open
latekvo wants to merge 4 commits into
Open
feat(ios-profiler): attributable memory leaks via malloc_stack_logging#351latekvo wants to merge 4 commits into
latekvo wants to merge 4 commits into
Conversation
native-profiler-start gains an opt-in `malloc_stack_logging` flag. When set, it cold-launches the target app under xctrace with `--env MallocStackLogging=1` instead of attaching, so Instruments records allocation backtraces and leaks carry a real responsible frame + library. Without it leaks are detected but unattributable — Instruments reports "<Call stack limit reached>". Default behaviour is unchanged: attach to the running app, no relaunch, no overhead. The report now relabels unattributable leaks with a hint to re-run with malloc_stack_logging rather than surfacing the raw placeholder. - split detectRunningApp into reusable AppInfo helpers - resolve the .app bundle path via `simctl get_app_container` for --launch - terminate the running instance first for a clean cold start - tests: launch+env vs attach argv, and the unattributable-leak render
Reference + native-profiler skill now explain the attach-vs-cold-launch trade-off and how to get attributable leaks.
e341e7d to
58a8d62
Compare
…ingUserApps enumerateRunningUserApps inlined the same simctl listapps | plutil | JSON.parse block that the new getInstalledApps helper already provides. Route it through the helper so the two can't drift.
…-leaks # Conflicts: # packages/tool-server/src/utils/ios-profiler/render.ts
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.
What
Opt-in
malloc_stack_loggingflag onnative-profiler-startthat makes iOS memory leaks attributable — they come back with a real responsible frame + library instead of<Call stack limit reached>.Why
native-profiler-startattaches to the already-running app. iOS records malloc allocation backtraces only whenMallocStackLoggingis set at process launch, so an attached app has none: Instruments' Leaks scanner finds the leaked blocks but can't attribute them and emits the placeholder<Call stack limit reached>(that string is Instruments', not ours).How
When
malloc_stack_logging: true, the profiler cold-launches the app under xctrace instead of attaching:.apppath resolved viasimctl get_app_container; the running instance is terminated first for a clean cold start.malloc_stack_logging: true, instead of surfacing the raw placeholder.Evidence (real iPhone 16 sim, same scroll workload)
Before (attach) — every leak row:
After (
--env MallocStackLogging=1 --launch) — same Leaks export:itanium_demangle::OutputBuffer::grow(...)hermes::vm::JSTypedArrayBase::createBuffer(...)Tests
test/ios-instruments/malloc-stack-logging.test.ts— asserts launch +--env MallocStackLogging=1+--launch -- <app>argv vs default--attach(and terminate-first / get_app_container).test/ios-instruments/leak-attribution-render.test.ts— unattributable vs attributed leak rendering.test/ios-instruments/suite green (7 files / 39 tests);tsc --noEmitclean on tool-server.Notes
Draft. Not yet exercised through a live tool-server end-to-end (running a modified tool-server would clobber the local
~/.argent/tool-server.json); the mechanism, the assembled argv, and the export→parse→render pipeline are each verified independently. Docs updated:IOS_PROFILER_REFERENCE.mdand theargent-native-profilerskill.