Module: Endeca::Benchmarking

Included in:
Endeca
Defined in:
lib/endeca/benchmarking.rb

Instance Method Summary collapse

Instance Method Details

#bm(metric_symbol, detail = nil) ⇒ Object

Log and benchmark the workings of a single block. Will only be called if Endeca.debug and Endeca.benchmark are true.



5
6
7
8
9
10
11
12
# File 'lib/endeca/benchmarking.rb', line 5

def bm(metric_symbol, detail = nil)
  result = nil
  ms = ::Benchmark.ms { result = yield }
  add_bm_detail(metric_symbol,ms,detail) if detail.to_s.strip.length > 0
  increase_metric(metric_symbol, ms)
  Endeca.logger.debug("#{metric_symbol.to_s}: #{'%.1f' % ms}ms")
  result
end

#increase_metric(metric_symbol, up_value) ⇒ Object



14
15
16
17
18
# File 'lib/endeca/benchmarking.rb', line 14

def increase_metric(metric_symbol, up_value)
  Thread.current[:endeca] ||= {}
  Thread.current[:endeca][metric_symbol] ||= 0
  Thread.current[:endeca][metric_symbol] += up_value
end