# File lib/deep_test/metrics/queue_lock_wait_time_measurement.rb, line 6 def self.extended(o) o.instance_eval do alias pop_without_lock_wait_measurement pop alias pop pop_with_lock_wait_measurement alias push_without_lock_wait_measurement push alias push push_with_lock_wait_measurement end end
# File lib/deep_test/metrics/queue_lock_wait_time_measurement.rb, line 62 def add_pop_time(time) Thread.exclusive do @total_pop_time ||= 0 @total_pop_time += time end end
# File lib/deep_test/metrics/queue_lock_wait_time_measurement.rb, line 55 def add_push_time(time) Thread.exclusive do @total_push_time ||= 0 @total_push_time += time end end
# File lib/deep_test/metrics/queue_lock_wait_time_measurement.rb, line 48 def measure(accumulator) start_time = Time.now result = yield send(accumulator, Time.now - start_time) result end
# File lib/deep_test/metrics/queue_lock_wait_time_measurement.rb, line 16 def pop_with_lock_wait_measurement(no_wait = false) if no_wait return measure(:add_pop_time) do pop_without_lock_wait_measurement(no_wait) end else begin # Measure without waiting to minimize extra time added # above locking time # return measure(:add_pop_time) do pop_without_lock_wait_measurement(true) end rescue ThreadError => e if e.message == "queue empty" # Normally we would have waiting for a condvar signal, # so don't penalize time for locking here again - hence # no measure return pop_without_lock_wait_measurement(false) else raise end end end end
Generated with the Darkfish Rdoc Generator 2.