class OverallRequestTimes::Registry

Public Class Methods

new() click to toggle source
# File lib/overall_request_times/registry.rb, line 4
def initialize
  @registry = {}
  @mutex = Mutex.new
end

Public Instance Methods

add_duration(remote_app_name, duration_in_seconds) click to toggle source
# File lib/overall_request_times/registry.rb, line 79
def add_duration(remote_app_name, duration_in_seconds)
  @mutex.synchronize do
    @registry[remote_app_name] ||= GenericTimer.new(remote_app_name, true)
    @registry[remote_app_name].add(duration_in_seconds)
  end
end
bm(remote_app_name, &block) click to toggle source
# File lib/overall_request_times/registry.rb, line 57
def bm(remote_app_name, &block)
  start(remote_app_name)
  begin
    block.call
  ensure
    stop(remote_app_name)
  end
end
call_count_for(remote_app_name) click to toggle source
# File lib/overall_request_times/registry.rb, line 34
def call_count_for(remote_app_name)
  @mutex.synchronize do
    timer = @registry[remote_app_name]
    timer ? timer.call_count : 0
  end
end
register(timer) click to toggle source
# File lib/overall_request_times/registry.rb, line 21
def register(timer)
  @mutex.synchronize do
    @registry[timer.remote_app_name] ||= timer
  end
end
reset!() click to toggle source
# File lib/overall_request_times/registry.rb, line 15
def reset!
  @mutex.synchronize do
    @registry.each { |_, timer| timer.reset! }
  end
end
size() click to toggle source
# File lib/overall_request_times/registry.rb, line 9
def size
  @mutex.synchronize do
    @registry.size
  end
end
start(remote_app_name) click to toggle source
# File lib/overall_request_times/registry.rb, line 66
def start(remote_app_name)
  @mutex.synchronize do
    @registry[remote_app_name] ||= GenericTimer.new(remote_app_name, true)
    @registry[remote_app_name].start
  end
end
stop(remote_app_name) click to toggle source
# File lib/overall_request_times/registry.rb, line 73
def stop(remote_app_name)
  @mutex.synchronize do
    @registry[remote_app_name] && @registry[remote_app_name].stop
  end
end
total_for(remote_app_name) click to toggle source
# File lib/overall_request_times/registry.rb, line 27
def total_for(remote_app_name)
  @mutex.synchronize do
    timer = @registry[remote_app_name]
    timer ? timer.total : 0
  end
end
totals() click to toggle source
# File lib/overall_request_times/registry.rb, line 41
def totals
  @mutex.synchronize do
    @registry.each_with_object({}) do |(remote_app_name, timer), acc|
      acc[remote_app_name] = timer.total
    end
  end
end
totals_and_counts() click to toggle source
# File lib/overall_request_times/registry.rb, line 49
def totals_and_counts
  @mutex.synchronize do
    @registry.each_with_object({}) do |(remote_app_name, timer), acc|
      acc[remote_app_name] = {total: timer.total, call_count: timer.call_count}
    end
  end
end