Class: NewRelic::Agent::SampledBuffer
- Inherits:
-
Object
- Object
- NewRelic::Agent::SampledBuffer
- Defined in:
- lib/new_relic/agent/sampled_buffer.rb
Instance Attribute Summary collapse
-
#capacity ⇒ Object
Returns the value of attribute capacity.
-
#captured_lifetime ⇒ Object
readonly
Returns the value of attribute captured_lifetime.
-
#seen ⇒ Object
readonly
Returns the value of attribute seen.
-
#seen_lifetime ⇒ Object
readonly
Returns the value of attribute seen_lifetime.
Instance Method Summary collapse
- #<<(x) ⇒ Object
-
#append(x) ⇒ Object
Like ‘<<’, but returns the value of full?.
- #full? ⇒ Boolean
-
#initialize(capacity) ⇒ SampledBuffer
constructor
A new instance of SampledBuffer.
- #reset ⇒ Object
- #sample_rate ⇒ Object
- #sample_rate_lifetime ⇒ Object
- #size ⇒ Object
- #to_a ⇒ Object
Constructor Details
#initialize(capacity) ⇒ SampledBuffer
Returns a new instance of SampledBuffer.
15 16 17 18 19 20 21 |
# File 'lib/new_relic/agent/sampled_buffer.rb', line 15 def initialize(capacity) @items = [] @capacity = capacity @captured_lifetime = 0 @seen = 0 @seen_lifetime = 0 end |
Instance Attribute Details
#capacity ⇒ Object
Returns the value of attribute capacity.
13 14 15 |
# File 'lib/new_relic/agent/sampled_buffer.rb', line 13 def capacity @capacity end |
#captured_lifetime ⇒ Object (readonly)
Returns the value of attribute captured_lifetime.
13 14 15 |
# File 'lib/new_relic/agent/sampled_buffer.rb', line 13 def captured_lifetime @captured_lifetime end |
#seen ⇒ Object (readonly)
Returns the value of attribute seen.
13 14 15 |
# File 'lib/new_relic/agent/sampled_buffer.rb', line 13 def seen @seen end |
#seen_lifetime ⇒ Object (readonly)
Returns the value of attribute seen_lifetime.
13 14 15 |
# File 'lib/new_relic/agent/sampled_buffer.rb', line 13 def seen_lifetime @seen_lifetime end |
Instance Method Details
#<<(x) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/new_relic/agent/sampled_buffer.rb', line 39 def <<(x) @seen += 1 if @items.size < @capacity @items << x else m = rand(@seen) # [0, @seen) if m < @capacity @items[m] = x else # discard current sample end end return self end |
#append(x) ⇒ Object
Like ‘<<’, but returns the value of full?
35 36 37 |
# File 'lib/new_relic/agent/sampled_buffer.rb', line 35 def append(x) (self << x).full? end |
#full? ⇒ Boolean
30 31 32 |
# File 'lib/new_relic/agent/sampled_buffer.rb', line 30 def full? @items.size >= @capacity end |
#reset ⇒ Object
23 24 25 26 27 28 |
# File 'lib/new_relic/agent/sampled_buffer.rb', line 23 def reset @captured_lifetime += @items.size @seen_lifetime += @seen @items = [] @seen = 0 end |
#sample_rate ⇒ Object
69 70 71 |
# File 'lib/new_relic/agent/sampled_buffer.rb', line 69 def sample_rate @seen > 0 ? (size.to_f / @seen) : 0.0 end |
#sample_rate_lifetime ⇒ Object
73 74 75 |
# File 'lib/new_relic/agent/sampled_buffer.rb', line 73 def sample_rate_lifetime @captured_lifetime > 0 ? (@captured_lifetime.to_f / @seen_lifetime) : 0.0 end |
#size ⇒ Object
54 55 56 |
# File 'lib/new_relic/agent/sampled_buffer.rb', line 54 def size @items.size end |
#to_a ⇒ Object
58 59 60 |
# File 'lib/new_relic/agent/sampled_buffer.rb', line 58 def to_a @items.dup end |