How btrace-harmony implements tracing on HarmonyOS
masterbtrace-harmony provides a high-performance tracing tool for HarmonyOS that supports both ArkTS and Native mixed-language stacks. It uses a dual-approach engine:
- Synchronous Tracing: Uses the official
HiDebug_Backtrace_ObjectAPI to unwind mixed ArkTS and Native frames in a single pass using the frame pointer (fp). - Asynchronous Tracing: Acts as a fallback for when threads are stuck in long-running functions or slow system calls. It uses a timer to periodically send real-time signals (
tgkill) to target threads to trigger stack sampling.
To prevent signal interference with slow system calls (like epoll_wait, recv, or nanosleep), btrace-harmony uses a SlowSysCallProxy to transparently hook these calls, masking sampling signals before entry and restoring them upon exit.