Class: MemoryTracker::Stores::InMemoryStore::Stats

Inherits:
Object
  • Object
show all
Defined in:
lib/memory_tracker/stores/in_memory_store.rb

Instance Method Summary collapse

Constructor Details

#initializeStats

Returns a new instance of Stats.



61
62
63
# File 'lib/memory_tracker/stores/in_memory_store.rb', line 61

def initialize
  @data = {}
end

Instance Method Details

#count(controller, action) ⇒ Object



70
71
72
73
# File 'lib/memory_tracker/stores/in_memory_store.rb', line 70

def count(controller, action)
  ca = controller_action_data(controller, action)
  ca[:num]
end

#each(&block) ⇒ Object



75
76
77
78
79
80
81
# File 'lib/memory_tracker/stores/in_memory_store.rb', line 75

def each(&block)
  @data.each do |controller, h|
    h.each do |action, stats|
      yield [controller, action, stats]
    end
  end
end

#fetch(controller, action, attr) ⇒ Object



65
66
67
68
# File 'lib/memory_tracker/stores/in_memory_store.rb', line 65

def fetch(controller, action, attr)
  ca = controller_action_data(controller, action)
  ca[:gcstat][attr]
end

#increment_action_attribute(controller, action, attr, value) ⇒ Object



88
89
90
91
92
93
94
95
# File 'lib/memory_tracker/stores/in_memory_store.rb', line 88

def increment_action_attribute(controller, action, attr, value)
  ca = controller_action_data(controller, action)
  if ca[:gcstat][attr]
    ca[:gcstat][attr] += value
  else
    ca[:gcstat][attr] = value
  end
end

#increment_action_count(controller, action) ⇒ Object



83
84
85
86
# File 'lib/memory_tracker/stores/in_memory_store.rb', line 83

def increment_action_count(controller, action)
  ca = controller_action_data(controller, action)
  ca[:num] += 1
end

#to_aObject



98
99
100
101
102
103
104
105
106
107
108
# File 'lib/memory_tracker/stores/in_memory_store.rb', line 98

def to_a
  a = []
  @data.each do |controller, actions|
    actions.each do |action, counters|
      row = { :controller => controller, :action => action, :num => counters[:num] }
      row.merge!(counters[:gcstat])
      a << row
    end
  end
  a
end