module DeepTest::Metrics::QueueLockWaitTimeMeasurement

Attributes

total_pop_time[R]
total_push_time[R]

Public Class Methods

extended(o) click to toggle source
# 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

Public Instance Methods

add_pop_time(time) click to toggle source
# 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
add_push_time(time) click to toggle source
# 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
measure(accumulator) { || ... } click to toggle source
# 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
pop_with_lock_wait_measurement(no_wait = false) click to toggle source
# 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
push_with_lock_wait_measurement(value) click to toggle source
# File lib/deep_test/metrics/queue_lock_wait_time_measurement.rb, line 42
def push_with_lock_wait_measurement(value)
  measure(:add_push_time) do
    push_without_lock_wait_measurement(value)
  end
end