Module: Datadog::Profiling::Ext::Forking
- Defined in:
- lib/datadog/profiling/ext/forking.rb
Overview
Monkey patches ‘Kernel#fork`, adding a `Kernel#at_fork` callback mechanism which is used to restore profiling abilities after the VM forks.
Known limitations: Does not handle ‘BasicObject`s that include `Kernel` directly; e.g. `Class.new(BasicObject) { include(::Kernel); def call; fork { }; end }.new.call`.
This will be fixed once we moved to hooking into ‘Process._fork`
Defined Under Namespace
Modules: Kernel, ProcessDaemonPatch
Class Method Summary collapse
Class Method Details
.apply! ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/datadog/profiling/ext/forking.rb', line 16 def self.apply! return false unless supported? [ ::Process.singleton_class, # Process.fork ::Kernel.singleton_class, # Kernel.fork ::Object, # fork without explicit receiver (it's defined as a method in ::Kernel) # Note: Modifying Object as we do here is irreversible. During tests, this # change will stick around even if we otherwise stub `Process` and `Kernel` ].each { |target| target.prepend(Kernel) } ::Process.singleton_class.prepend(ProcessDaemonPatch) end |
.supported? ⇒ Boolean
12 13 14 |
# File 'lib/datadog/profiling/ext/forking.rb', line 12 def self.supported? Process.respond_to?(:fork) end |