Sha256: ad8e363d992d3419f1ce7e1f7cf94e3f240557303a1d580a965ed536add0069a
Contents?: true
Size: 958 Bytes
Versions: 39
Compression:
Stored size: 958 Bytes
Contents
# encoding: utf-8 # http://xlinux.nist.gov/dads/HTML/reservoirSampling.html require 'one_apm/support/event_buffer' module OneApm module Agent class SampledBuffer < EventBuffer attr_reader :seen_lifetime, :captured_lifetime def initialize(capacity) super @captured_lifetime = 0 @seen_lifetime = 0 end def reset! @captured_lifetime += @items.size @seen_lifetime += @seen super end 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 def sample_rate_lifetime @captured_lifetime > 0 ? (@captured_lifetime.to_f / @seen_lifetime) : 0.0 end end end end
Version data entries
39 entries across 39 versions & 1 rubygems