Class: Orbacle::Indexer::StatsRecorder

Inherits:
Object
  • Object
show all
Defined in:
lib/orbacle/indexer.rb

Instance Method Summary collapse

Constructor Details

#initializeStatsRecorder

Returns a new instance of StatsRecorder.



11
12
13
14
15
# File 'lib/orbacle/indexer.rb', line 11

def initialize
  @timers = Hash.new(0.0)
  @counters = Hash.new(0)
  @values = Hash.new
end

Instance Method Details

#all_statsObject



29
30
31
# File 'lib/orbacle/indexer.rb', line 29

def all_stats
  @timers.merge(@counters).merge(@values)
end

#counter(counter_key) ⇒ Object



37
38
39
# File 'lib/orbacle/indexer.rb', line 37

def counter(counter_key)
  @counters[counter_key]
end

#inc(counter_key, by = 1) ⇒ Object



33
34
35
# File 'lib/orbacle/indexer.rb', line 33

def inc(counter_key, by = 1)
  @counters[counter_key] += by
end

#measure(timer) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/orbacle/indexer.rb', line 17

def measure(timer)
  started_at = Time.now.to_f
  process_result = yield
  finished_at = Time.now.to_f
  process_result
rescue Exception => e
  finished_at ||= Time.now.to_f
  raise
ensure
  @timers[timer] += finished_at - started_at
end

#set_value(key, value) ⇒ Object



41
42
43
# File 'lib/orbacle/indexer.rb', line 41

def set_value(key, value)
  @values[key] = value
end