Repository navigation
Add support for attaching profiler to a PID (Linux only). - #18
Merged
Merged
Conversation
-p will be used for the newly added --pid option. Unfortunately this is a breaking change, but this allows the command line to be consistent with perf.
Previously the profiler only terminated on process exit, but with PID attach we need to stop it on user request. Allow passing-in an AtomicBool as a stop flag.
For now, support this for Linux only since on macOS hooking stuff complicates attaching.
mstange
approved these changes
Jan 28, 2023
mstange
left a comment
Owner
There was a problem hiding this comment.
Excellent, thanks! I'll merge this and then fix the macOS build. I should probably set up some macOS CI.
Comment on lines
+90
to
+98
| // When the first Ctrl+C is received, stop recording. | ||
| // The server launches after the recording finishes. On the second Ctrl+C, terminate the server. | ||
| let stop = Arc::new(AtomicBool::new(false)); | ||
| #[cfg(unix)] | ||
| signal_hook::flag::register_conditional_default(signal_hook::consts::SIGINT, stop.clone()) | ||
| .expect("cannot register signal handler"); | ||
| #[cfg(unix)] | ||
| signal_hook::flag::register(signal_hook::consts::SIGINT, stop.clone()) | ||
| .expect("cannot register signal handler"); |
Owner
There was a problem hiding this comment.
I think I've understood how this works, but it feels a bit non-obvious. It looks like register_conditional_default uses the AtomicBool as an input, whereas register uses it as an output. So on the first Ctrl+C, the first signal handler reads false and doesn't act, and the second signal handler writes true. Then on the second Ctrl+C, the first signal handler reads true and terminates. So the order of setting these handlers also matters.
I'll land this as-is, but I'm open for suggestions to make this easier to read.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This adds support for attaching to a PID by
samply record -p 12345.I only implemented (and feature flagged) this for Linux, since the attaching story seems more complicated on the macOS side.