Class: Camayoc::Handlers::Memory

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

Instance Method Summary collapse

Methods included from ThreadSafety

#synchronize, #thread_safe=, #thread_safe?

Constructor Details

#initialize(options = {}) ⇒ Memory

Returns a new instance of Memory.



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

def initialize(options={})
  @data = {}
  self.thread_safe = Camayoc.thread_safe?
end

Instance Method Details

#count(event) ⇒ Object



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

def count(event)
  stat = event.ns_stat
  synchronize do
    @data[stat] ||= 0
    @data[stat] += event.value
  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

#timing(event) ⇒ Object



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

def timing(event)
  synchronize do
    (@data[event.ns_stat] ||= Timing.new) << event.value
  end
end