class OneApm::Agent::SampledBuffer

Attributes

captured_lifetime[R]
seen_lifetime[R]

Public Class Methods

new(capacity) click to toggle source
Calls superclass method OneApm::Agent::EventBuffer::new
# File lib/one_apm/support/event_buffer/sampled_buffer.rb, line 15
def initialize(capacity)
  super
  @captured_lifetime = 0
  @seen_lifetime     = 0
end

Public Instance Methods

append_event(x) click to toggle source
# 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!() click to toggle source
Calls superclass method OneApm::Agent::EventBuffer#reset!
# 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() click to toggle source
# 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