-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
avoid deadlock by skipping sampling in libc, libgcc and pthread #85
avoid deadlock by skipping sampling in libc, libgcc and pthread #85
Conversation
Signed-off-by: YangKeao <[email protected]>
Signed-off-by: YangKeao <[email protected]>
Signed-off-by: YangKeao <[email protected]>
Signed-off-by: YangKeao <[email protected]>
6aab8f3
to
ff4e24e
Compare
Please fix warnings. I'm afraid this can mislead users. For example, symbols like |
Signed-off-by: YangKeao <[email protected]>
Signed-off-by: YangKeao <[email protected]>
I can see there are still warnings in the changes. |
Fixed 😺 |
That's why it is a feature. I left the choice to the user to trade off the deadlock possibility and the accuracy of the flamegraph |
Can you explain why there will be deadlocks? |
Because This lock is acquired during some logic inside the Actually trying to get a lock in the signal handler is (theoretically) unsafe anyway, this PR is only a possible (practical) solution. |
Signed-off-by: YangKeao <[email protected]>
0ce2dd4
to
59bad74
Compare
I've thought about shrinking the blacklist by only skipping some symbols (but not whole library). However, it's only safe to get the ip address of the nearest frame of the signal, but not a full backtrace, so trying to find all possible symbol of the nearest "deadlock" frame is quite complicated (and not stable). |
@BusyJay PTAL |
src/profiler.rs
Outdated
@@ -23,6 +26,9 @@ pub struct Profiler { | |||
sample_counter: i32, | |||
|
|||
running: bool, | |||
|
|||
#[cfg(all(feature = "ignore-libc", target_arch = "x86_64", target_os = "linux"))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a feature seems over complicated to me. Blacklist should be a common requirement. Though I don't have strong opinion on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I should make it configurable through an argument, but not a compile-time feature?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@BusyJay Now I added a ProfilerGuardBuilder
to set the configuration (though the ProfilerGuardBuilder
sounds chaos).
src/profiler.rs
Outdated
@@ -149,14 +173,60 @@ extern "C" fn perf_signal_handler(_signal: c_int) { | |||
} | |||
} | |||
|
|||
#[cfg(all(feature = "ignore-libc", target_arch = "x86_64", target_os = "linux"))] | |||
const SHLIB_BLACKLIST: [&str; 3] = ["libc", "libgcc_s", "libpthread"]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about binaries that linked statically?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They have to be handle case by case (for different libc
implementation). The musl
implementation of dl_iterate_phdr
doesn't have a lock, so the _Unwind_Backtrace
will not deadlock at this point.
But I'm not familiar with other static libc
implementation.
181bdbb
to
6e4cfea
Compare
Signed-off-by: YangKeao <[email protected]>
6e4cfea
to
1b7b26c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it will still deadlock on Arm, right?
Signed-off-by: YangKeao <[email protected]>
39518c8
to
911afb8
Compare
fac6459
to
cbfe7ea
Compare
Signed-off-by: YangKeao <[email protected]>
cbfe7ea
to
1fc974a
Compare
@BusyJay PTAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rest LGTM
Signed-off-by: YangKeao <[email protected]>
A simpler solution might be hacking |
* avoid deadlock by skipping sampling in libc, libgcc and pthread Signed-off-by: YangKeao <[email protected]> * make clippy happy Signed-off-by: YangKeao <[email protected]> * skip libc only for linux Signed-off-by: YangKeao <[email protected]> * add null check in the signal handler Signed-off-by: YangKeao <[email protected]> * add more cfg to remove blacklist on non-linux platform Signed-off-by: YangKeao <[email protected]> * fix clippy warning for test Signed-off-by: YangKeao <[email protected]> * fix clippy Signed-off-by: YangKeao <[email protected]> * use a configurable option to set blacklist Signed-off-by: YangKeao <[email protected]> * add document and don't reset blacklist_segments Signed-off-by: YangKeao <[email protected]> * support aarch64 Signed-off-by: YangKeao <[email protected]> * replace blacklist into blocklist Signed-off-by: YangKeao <[email protected]>
Signed-off-by: YangKeao [email protected]