Class: OneApm::Agent::SampledBuffer
- Inherits:
-
EventBuffer
- Object
- EventBuffer
- OneApm::Agent::SampledBuffer
- Extended by:
- Forwardable
- Defined in:
- lib/one_apm/support/event_buffer/sampled_buffer.rb
Instance Attribute Summary collapse
-
#captured_lifetime ⇒ Object
readonly
Returns the value of attribute captured_lifetime.
-
#seen_lifetime ⇒ Object
readonly
Returns the value of attribute seen_lifetime.
Attributes inherited from EventBuffer
Instance Method Summary collapse
- #append_event(x) ⇒ Object
-
#initialize(capacity) ⇒ SampledBuffer
constructor
A new instance of SampledBuffer.
- #reset! ⇒ Object
- #sample_rate_lifetime ⇒ Object
Methods inherited from EventBuffer
#<<, #append, #full?, #note_dropped, #num_dropped, #num_seen, #sample_rate, #size, #to_a
Constructor Details
#initialize(capacity) ⇒ SampledBuffer
Returns a new instance of SampledBuffer.
15 16 17 18 19 |
# File 'lib/one_apm/support/event_buffer/sampled_buffer.rb', line 15 def initialize(capacity) super @captured_lifetime = 0 @seen_lifetime = 0 end |
Instance Attribute Details
#captured_lifetime ⇒ Object (readonly)
Returns the value of attribute captured_lifetime.
12 13 14 |
# File 'lib/one_apm/support/event_buffer/sampled_buffer.rb', line 12 def captured_lifetime @captured_lifetime end |
#seen_lifetime ⇒ Object (readonly)
Returns the value of attribute seen_lifetime.
12 13 14 |
# File 'lib/one_apm/support/event_buffer/sampled_buffer.rb', line 12 def seen_lifetime @seen_lifetime end |
Instance Method Details
#append_event(x) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/one_apm/support/event_buffer/sampled_buffer.rb', line 27 def append_event(x) if @items.size < @capacity @items << x return x else m = rand(@seen) # [0, @seen) if m < @capacity @items[m] = x return x else # discard current sample return nil end end end |
#reset! ⇒ Object
21 22 23 24 25 |
# File 'lib/one_apm/support/event_buffer/sampled_buffer.rb', line 21 def reset! @captured_lifetime += @items.size @seen_lifetime += @seen super end |
#sample_rate_lifetime ⇒ Object
44 45 46 |
# File 'lib/one_apm/support/event_buffer/sampled_buffer.rb', line 44 def sample_rate_lifetime @captured_lifetime > 0 ? (@captured_lifetime.to_f / @seen_lifetime) : 0.0 end |