Skip to content
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

[PROF-4756] Simplify profiling Forking monkey patch, making it less generic #2149

Merged
merged 1 commit into from
Jul 13, 2022

Conversation

ivoanjo
Copy link
Member

@ivoanjo ivoanjo commented Jul 13, 2022

What does this PR do?:

Simplify the profiling Forking monkey patch, by removed the unused :prepare and :parent stages for callbacks.

Motivation:

The profiling Forking monkey patch only has a single customer: the Datadog::Profiling::Tasks::Setup class, which uses it to add an at_fork(:child) that takes care of restarting the profiler and fixing up the thread ids after a fork happened.

Since the Forking monkey patch affects core Ruby classes, I decided to simplify it, as we're not using the added complexity, and I prefer it being as simple as possible.

My additional motivation is that I'm working on support for monkey patching Process.daemon, and this simplifies the amount of code and tests needed to implement the needed functionality.

(We can always undo this if later we find a need for the other callbacks, but in the ~2 years of life of this monkey patch, we haven't needed the extra functionality, so I'll take that as a signal).

How to test the change?:

  • Validate that test suite is still green
  • Run an example application that forks (for instance DD_PROFILING_ENABLED=true DD_TRACE_DEBUG=true bundle exec ddtracerb exec ruby -e 'fork { sleep }; sleep') and validate that the profiler successfully restarts in the child process after the fork

The profiling `Forking` monkey patch only has a single customer:
the `Datadog::Profiling::Tasks::Setup` class, which uses it to
add an `at_fork(:child)` that takes care of restarting the profiler
and fixing up the thread ids after a fork happened.

Since the `Forking` monkey patch affects core Ruby classes, I decided
to simplify it, as we're not using the added complexity, and I prefer
it being as simple as possible.

My additional motivation is that I'm working on support for monkey
patching `Process.daemon`, and this simplifies the amount of code
and tests needed to implement the needed functionality.

(We can always undo this if later we find a need for the other
callbacks, but in the ~2 years of life of this monkey patch, we
haven't needed the extra functionality, so I'll take that as a signal).
@ivoanjo ivoanjo requested a review from a team July 13, 2022 08:28
@ivoanjo
Copy link
Member Author

ivoanjo commented Jul 13, 2022

Thanks Tony for the quick review, mergin'! :)

@ivoanjo ivoanjo merged commit de420d5 into master Jul 13, 2022
@ivoanjo ivoanjo deleted the ivoanjo/prof-4756-simplify-forking-monkey-patch branch July 13, 2022 12:43
@github-actions github-actions bot added this to the 1.3.0 milestone Jul 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants