Repository navigation
RFC-0048: RFC-0048: Linux Unwinding Abstraction Layer for traced_perf and heapprofd #7283
Replies: 10 comments
|
The overall proposal is sensible but the phrasing of the "problem" section could be clearer. Currently it reads as if we're trying to remove libunwindstack dependency on all platforms, which we're not. We want to add an abstraction layer to:
The mentions of memory optimisations are also irrelevant to this proposal imo. The scope is purely improving maintainability and allowing for a choice of the unwinder/symboliser. The RFC proposes modeling all headers and classes after the existing use of libunwindstack, but it's unclear how well that would fit other unwinding libraries. It'd be helpful if the RFC included a sketch of how e.g. libunwind's remote unwinding API [1] could be abstracted over by the proposed classes. Figuring out the abstraction layer is the most important part of this RFC since if we over-specialise on libunwindstack, it might make adding future unwinders more difficult. Misc notes on the existing usage section:
[1] https://www.nongnu.org/libunwind/man/unw_create_addr_space(3).html |
|
📝 RFC Document Updated View changes: Commit History |
|
Thanks for the feedback @rsavitski! I have revised the RFC :
I will get the numbers with the |
|
📝 RFC Document Updated View changes: Commit History |
|
📝 RFC Document Updated View changes: Commit History |
|
📝 RFC Document Updated View changes: Commit History |
|
📝 RFC Document Updated View changes: Commit History |
|
Focusing on section 3, one small question, but otherwise the proposal
PS. Personal opinion on the doc structure: it doesn't focus enough on the part Structure I would've expected:
In other words, sections 1, 2, 3 would've been enough. The rest feels like it |
|
📝 RFC Document Updated View changes: Commit History |
|
Thanks Ryan for the feedback.
Thanks for pointing this out. SymbolStatus (
Thanks, I am preparing the pull requests |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
📄 RFC Doc: 0048-backend-agnostic-unwind-interface.md
RFC-0048: Linux Unwinding Abstraction Layer for traced_perf and heapprofd
Authors: @safayat-google
Status: In Review
Discussion: https://github.com/google/perfetto/discussions/7283\
Proof of concept: patch
1. Problem Statement & Motivation
Currently, callstack unwinding in Perfetto (
traced_perfandheapprofd) is tightly coupled to Android'slibunwindstacklibrary (buildtools/android-unwinding).On Android
libunwindstackis essential due to its support for ART Dex files, ART JIT debug frames (JitDebug), and Bionic integration. However, for standalone Linux builds, coupling tolibunwindstackintroduces several significant drawbacks:libunwindstackfrequently cause build breakages in Perfetto. Maintaining a standalone copy oflibunwindstackfor Linux host/target builds is costly.perf) rely onlibunwindorlibdw, which are standard across Linux distributions, actively maintained by the Linux toolchain community, and well-integrated with distribution debug packages and remote unwinding.traced_perfdirectly include<unwindstack/*.h>.Scope
libunwindstackby default. Full support for ART Dex files and JIT frames is preserved without regression.libunwindstack. The abstraction allows Linux builds to use alternative unwinding backends without depending on Android-specific libraries.2. Proposed Unwinding Libraries for Standalone Builds
For standalone Linux builds, we propose two complementary unwinding options:
2.1 Primary DWARF Unwinder:
libunwindperfand GNU tools. It provides a stable C API (unw_create_addr_space,unw_init_remote,unw_step), has an MIT/LLVM-compatible license, and supports remote unwinding across all standard Linux architectures (x86_64, ARM64, ARM32, RISC-V).2.2 Built-in Zero-Dependency Frame Pointer Unwinder:
FramePointerUnwinder3. Proposed Interface Types
We introduce a high-level, backend-agnostic unwinding interface that encapsulates the entire unwinding and process-context lifecycle.
3.1
CpuRegisters(Zero-Allocation Register Representation)Previously,
traced_perfallocatedstd::unique_ptr<unwindstack::Regs>on the heap for every sample in the queue. Incpu_registers.h, this is replaced by a flat, stack-allocated POD struct:3.2
Unwinder&ProcessUnwindContext3.3 Output Types (
UnwindFrame&UnwindResult)4. Other Considerations
4.1 Making "Live" Symbolization Optional
traced_perf: Does not perform live symbolization during sampling. It emits raw PCs and mapping information (build_id,rel_pc), leaving symbolization to Trace Processor offline.heapprofd: Optionally performs live symbolization when usinglibunwindstack.4.2 Handling Library Divergences (File Opening & DWARF Discovery)
Unwinding libraries differ in how they locate DWARF unwind tables and access process memory:
libunwindstackopens files, parses/proc/<pid>/maps, and loads DWARF internally via its ownMemoryandElfclasses.libunwinduses callback hooks (access_mem,access_reg) andunw_create_addr_spaceoperating over stack snapshots and/proc/<pid>/mem.frame_pointerrequires zero ELF or DWARF discovery, operating purely on the stack buffer.These differences are completely encapsulated within each backend's
ProcessUnwindContextimplementation. The caller only provides the sampled stack buffer and register state to unwind.4.3 Dwarf table Caching on abstract API
5. Proof of Concept & Other References
libunwindstackmigration, zero-dependencyframe_pointer, andlibunwindbackend.traced_perfandheapprofd.💬 Discussion Guidelines:
All reactions