Module: Datadog::Profiling::Ext::WrapThreadStartFork
- Defined in:
- lib/ddtrace/profiling/ext/cthread.rb
Overview
Threads in Ruby can be started by creating a new instance of ‘Thread` (or a subclass) OR by calling `start`/`fork` on `Thread` (or a subclass).
This module intercepts calls to ‘start`/`fork`, ensuring that the `update_native_ids` operation is correctly called once the new thread starts.
Note that unlike CThread above, this module should be prepended to the ‘Thread`’s singleton class, not to the class.
Instance Method Summary collapse
- #start(*args) ⇒ Object (also: #fork)
Instance Method Details
#start(*args) ⇒ Object Also known as: fork
138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/ddtrace/profiling/ext/cthread.rb', line 138 def start(*args) # Wrap the work block with our own # so we can retrieve the native thread ID within the thread's context. wrapped_block = proc do |*t_args| # Set native thread ID & clock ID ::Thread.current.send(:update_native_ids) yield(*t_args) end wrapped_block.ruby2_keywords if wrapped_block.respond_to?(:ruby2_keywords, true) super(*args, &wrapped_block) end |