Class: OneApm::Agent::EventBuffer

Inherits:
Object
  • Object
show all
Defined in:
lib/one_apm/support/event_buffer.rb

Direct Known Subclasses

SampledBuffer, SizedBuffer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(capacity) ⇒ EventBuffer

Returns a new instance of EventBuffer.



21
22
23
24
25
# File 'lib/one_apm/support/event_buffer.rb', line 21

def initialize(capacity)
  @capacity = capacity
  @items    = []
  @seen     = 0
end

Instance Attribute Details

#capacityObject

Returns the value of attribute capacity.



19
20
21
# File 'lib/one_apm/support/event_buffer.rb', line 19

def capacity
  @capacity
end

Instance Method Details

#<<(x) ⇒ Object



46
47
48
49
# File 'lib/one_apm/support/event_buffer.rb', line 46

def <<(x)
  append(x)
  self # return self for method chaining
end

#append(x) ⇒ Object



41
42
43
44
# File 'lib/one_apm/support/event_buffer.rb', line 41

def append(x)
  @seen += 1
  append_event(x)
end

#full?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/one_apm/support/event_buffer.rb', line 51

def full?
  @items.size >= @capacity
end

#note_droppedObject



59
60
61
# File 'lib/one_apm/support/event_buffer.rb', line 59

def note_dropped
  @seen += 1
end

#num_droppedObject



67
68
69
# File 'lib/one_apm/support/event_buffer.rb', line 67

def num_dropped
  @seen - @items.size
end

#num_seenObject



63
64
65
# File 'lib/one_apm/support/event_buffer.rb', line 63

def num_seen
  @seen
end

#reset!Object



27
28
29
30
# File 'lib/one_apm/support/event_buffer.rb', line 27

def reset!
  @items = []
  @seen  = 0
end

#sample_rateObject



71
72
73
# File 'lib/one_apm/support/event_buffer.rb', line 71

def sample_rate
  @seen > 0 ? (size.to_f / @seen) : 0.0
end

#sizeObject



55
56
57
# File 'lib/one_apm/support/event_buffer.rb', line 55

def size
  @items.size
end

#to_aObject



75
76
77
# File 'lib/one_apm/support/event_buffer.rb', line 75

def to_a
  @items.dup
end