Class: Camayoc::Handlers::Memory

Inherits:
Object
  • Object
show all
Includes:
ThreadSafety
Defined in:
lib/camayoc/handlers/memory.rb

Constant Summary collapse

DEFAULT_MAX_EVENTS =
1024

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ThreadSafety

#synchronize, #thread_safe=, #thread_safe?

Constructor Details

#initialize(options = {}) ⇒ Memory

Returns a new instance of Memory.



11
12
13
14
15
16
# File 'lib/camayoc/handlers/memory.rb', line 11

def initialize(options={})
  @data = {}
  @max_events = options[:max_events].to_i rescue 0
  @max_events = DEFAULT_MAX_EVENTS if @max_events <= 0
  self.thread_safe = Camayoc.thread_safe?
end

Instance Attribute Details

#max_eventsObject (readonly)

Returns the value of attribute max_events.



9
10
11
# File 'lib/camayoc/handlers/memory.rb', line 9

def max_events
  @max_events
end

Instance Method Details

#event(ev) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/camayoc/handlers/memory.rb', line 18

def event(ev)
  case ev.type
    when :count then count(ev)
    when :timing then timing(ev)
    when :generic then generic(ev)
  end
end

#get(stat) ⇒ Object Also known as: []



26
27
28
29
30
# File 'lib/camayoc/handlers/memory.rb', line 26

def get(stat)
  synchronize do
    @data[stat]
  end
end