Skip to content

fix(profiler): demangle native C++ symbols in profiler reports#339

Merged
latekvo merged 4 commits into
mainfrom
fix/native-stack-demangle
Jun 17, 2026
Merged

fix(profiler): demangle native C++ symbols in profiler reports#339
latekvo merged 4 commits into
mainfrom
fix/native-stack-demangle

Conversation

@latekvo

@latekvo latekvo commented Jun 15, 2026

Copy link
Copy Markdown
Member

Summary

profiler-stack-query Android stacks come straight from perf, which stores frame names mangled — so function_callers / hang_stacks output reads like:

_ZN16GrDrawingManager5flushE6SkSpan... <- _ZL25libutil_thread_trampolinePv.__uniq.2265... <- __start_thread

This adds a conservative, best-effort Itanium demangler and applies it when rendering those stacks (display-only — SQL matching upstream still uses the raw mangled names). The same stack now reads:

GrDrawingManager::flush <- libutil_thread_trampoline <- __start_thread

What it handles

  • Nested names (_ZN...E) and plain function names; the argument list is dropped.
  • Strips LLVM/GCC internal suffixes (.__uniq.*, .llvm.*, .part.*, .cold).
  • Conservative: templates, substitutions, and kernel C symbols it can't confidently parse are returned verbatim — it never corrupts a name.

Test plan

  • New test/android-perfetto/demangle.test.ts (10 cases incl. fallbacks).
  • Updated function-callers.test.ts to expect the demangled leaf in the substring-match note.
  • npm test -w @argent/tool-server — all pass; build + typecheck:tests clean.

Part of a set of native-profiler fixes. Note: this and #338 both touch the hang_stacks sample renderer — whichever merges second needs a trivial rebase.

latekvo added 2 commits June 15, 2026 14:19
Perf stores frame names mangled, so profiler-stack-query stacks read like
`_ZN16GrDrawingManager5flushE6SkSpan...` - accurate but hard to read. Add a
conservative, best-effort Itanium demangler (nested names + plain function
names, argument list dropped, internal `.__uniq`/`.llvm` suffixes stripped)
and apply it when rendering function_callers and hang_stacks output. Anything
it can't confidently parse - templates, substitutions, kernel C symbols - is
returned verbatim, so it never corrupts a name. SQL matching upstream still
uses the raw mangled names, so this is display-only.
The drill-downs (function_callers / hang_stacks) were demangled, but the
CPU Hotspots table, its detail headings, and the Suggested Improvements
bullets still showed the raw mangled leaf name (e.g.
`_ZN16GrDrawingManager5flushE...`) — the most visible output. Apply
demangleSymbol at those human-facing display sites. The Next Steps
copy-paste `function_callers` suggestion deliberately keeps the raw symbol:
it's matched as a SQL substring of the mangled frame, and the demangled
name (args dropped) isn't a substring of it.

Also dedup overloaded leaf symbols AFTER demangling in the function_callers
substring note, so two overloads (`_ZN3foo3barEv`/`_ZN3foo3barEi`, both
`foo::bar`) collapse to one bullet instead of printing the same line twice
while the count says 2.
Comment thread packages/tool-server/src/utils/ios-profiler/render.ts
… too

The detail-block heading was demangled but the call chains right under it
(topCallChains, and the single-chain fallback) still rendered raw frames.
On Android those chains are built from the same mangled leaf_function as the
heading, so the report showed `GrDrawingManager::flush` over a chain reading
`_ZN16GrDrawingManager5flushE...` for the very same function.

Map each frame through demangleSymbol (display-only; the function_callers
suggestion still keeps the raw mangled name for its SQL substring match).
Cover both chain-render paths in render-demangle.test.ts.
@latekvo latekvo marked this pull request as ready for review June 16, 2026 14:57
@latekvo latekvo marked this pull request as draft June 16, 2026 17:58
@latekvo latekvo changed the title fix(profiler): demangle native C++ symbols in Android stack output fix(profiler): demangle native C++ symbols in profiler reports Jun 16, 2026
@latekvo latekvo marked this pull request as ready for review June 16, 2026 19:11
@latekvo latekvo requested review from filip131311 and hubgan June 17, 2026 11:39
@latekvo latekvo merged commit 9fc1810 into main Jun 17, 2026
3 checks passed
@latekvo latekvo deleted the fix/native-stack-demangle branch June 17, 2026 18:24
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.

2 participants