Only do per-frame-blocklist-check when frame-pointer is enabled #172
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.
Signed-off-by: mornyx mornyx.z@gmail.com
Related Issues
risedev ctl profile
doesn't work on Linux server risingwavelabs/risingwave#4765Background
We introduced frame-pointer based stacktrace in 567c5d0. But we cannot guarantee that all shared libraries have frame pointers enabled, and performing stacktracing directly based on frame pointers is dangerous and may cause crash.
So, we provide some protection. In general, there are two means of protection:
addr_validate
andblocklist
.addr_validate
ensures that we do not try to access unreadable addresses, andblocklist
helps us exclude stack frames belonging to specified shared libraries.Issue
But the commit above introduces a problem, here is a minimal reproduction:
To avoid deadlocks, we will block shared libraries like
libc
,pthread
, etc, but this causes an additional problem. Let's see the generated svg:It only contains samples inside the signal handler, all stack frames before the signal frame are lost.
Reason
The code in the RED BOX is newly introduced by the commit above, with frame-pointer based stacktracing. Its purpose is to do extra protection in the callback of each stack frame. But when doing stacktraces with
backtrace-rs
, there are some magical dependencies onlibc
in order to handle signal frames on the stack. So they are blocked due to the existence of blocklist.But why does it works well with
frame-pointer
feature? Because frame-pointer based stacktracing starts fromucontext
provided by OS kernel, which is an argument ofperf_signal_handler
.ucontext
holds the top stack frame before SIGPROF triggered, so we don't have to deal with signal frames at all.Solve
Only do per-frame-blocklist-check when
frame-pointer
is enabled. We will get the correct flamegraph: