lib/zold/stress/stats.rb in zold-stress-0.5.1 vs lib/zold/stress/stats.rb in zold-stress-0.5.2
- old
+ new
@@ -31,13 +31,14 @@
# Copyright:: Copyright (c) 2018 Yegor Bugayenko
# License:: MIT
module Zold::Stress
# Stats
class Stats
- def initialize
+ def initialize(log: Zold::Log::NULL)
@history = {}
@mutex = Mutex.new
+ @log = log
end
def exists?(metric)
!@history[metric].nil?
end
@@ -76,9 +77,10 @@
start = Time.now
yield
put(metric + '_ok', Time.now - start)
rescue StandardError => ex
put(metric + '_error', Time.now - start)
+ @log.error(Backtrace.new(ex))
raise ex unless swallow
ensure
put(metric, Time.now - start)
end