Module: DeepTest::Metrics::QueueLockWaitTimeMeasurement

Defined in:
lib/deep_test/metrics/queue_lock_wait_time_measurement.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#total_pop_timeObject (readonly)

Returns the value of attribute total_pop_time.



4
5
6
# File 'lib/deep_test/metrics/queue_lock_wait_time_measurement.rb', line 4

def total_pop_time
  @total_pop_time
end

#total_push_timeObject (readonly)

Returns the value of attribute total_push_time.



4
5
6
# File 'lib/deep_test/metrics/queue_lock_wait_time_measurement.rb', line 4

def total_push_time
  @total_push_time
end

Class Method Details

.extended(o) ⇒ Object



6
7
8
9
10
11
12
13
14
# 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

Instance Method Details

#add_pop_time(time) ⇒ Object



62
63
64
65
66
67
# 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) ⇒ Object



55
56
57
58
59
60
# 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) ⇒ Object



48
49
50
51
52
53
# 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) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# 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) ⇒ Object



42
43
44
45
46
# 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