Callstack: in-process stack capture and thread sampling #5
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "Callstack"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Base:
master@d00b249b. Two commits, 3 files, +334/−91. Both commits are authored byagent.Why
Hang reports need stacks from every thread, but the old
CallStackCaptureonly captured the calling thread and resolved frames through anaddr2linesubprocess. That is slow, cannot run inside the signal handler used to sample a stalled process, and had no Android implementation.StackTraceputs capture, symbolization and sampling in one in-process primitive, andCallStackCaptureis rebuilt on top of it.How it works
captureCallingThread()uses_Unwind_Backtraceto write up to 64 return addresses into a caller-provided buffer.symbolize()usesdladdrand__cxa_demangle;describe()formats address, module, module-relative offset and demangled function.sampleAllThreads()enumerates/proc/self/task, skips the sampler and signals each target withSIGRTMIN+3viatgkill. Each target captures its own stack into a per-thread slot. The sampler waits up toanswerTimeoutMs(200 ms by default), then returns each thread's name, scheduler state, kernel wait channel,answeredflag and frames. Slots hold at most 256 threads and the signal handler is installed once.isDebuggerAttached()readsTracerPidon Linux or callsIsDebuggerPresent()on Windows, so hang reporting can avoid sampling while a debugger has the process stopped.CaptureStackBackTraceand module lookup, butcanSampleThreads()is false andsampleAllThreads()returns empty.CallStackCapturenow delegates to this implementation on Linux and Android, replacingexecinfo/backtrace_symbolsand theaddr2linesubprocess.Behavior change: symbolization reports module + offset + demangled function. Unlike the old
addr2linepath, it does not provide a source file/line becausedladdrdoes not supply them.Verification
Both sources compile with
-Wall -Wextra. A local smoke test captured the calling stack and sampled a sleeping worker:CMakeLists.txtis unchanged: the port'sMODULES_BUILD_TESTSgate does not exist onmasterand would silently disable the tests.2e7213988dtoe05fb9c714