Class: Catpm::StackSampler::SamplingLoop
- Inherits:
-
Object
- Object
- Catpm::StackSampler::SamplingLoop
- Defined in:
- lib/catpm/stack_sampler.rb
Overview
Single global thread that samples all active requests. Avoids creating a thread per request.
Instance Method Summary collapse
-
#initialize ⇒ SamplingLoop
constructor
A new instance of SamplingLoop.
- #register(sampler) ⇒ Object
- #unregister(sampler) ⇒ Object
Constructor Details
#initialize ⇒ SamplingLoop
Returns a new instance of SamplingLoop.
13 14 15 16 17 18 |
# File 'lib/catpm/stack_sampler.rb', line 13 def initialize @mutex = Mutex.new @samplers = [] @thread = nil @stop = false end |
Instance Method Details
#register(sampler) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/catpm/stack_sampler.rb', line 20 def register(sampler) @mutex.synchronize do @samplers << sampler @stop = false start_thread unless @thread&.alive? end end |
#unregister(sampler) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/catpm/stack_sampler.rb', line 28 def unregister(sampler) @mutex.synchronize do @samplers.delete(sampler) @stop = true if @samplers.empty? end end |