Module: TimeBandits

Defined in:
lib/time_bandits/time_consumers/beetle.rb,
lib/time_bandits.rb,
lib/time_bandits/railtie.rb,
lib/time_bandits/version.rb,
lib/time_bandits/rack/logger.rb,
lib/time_bandits/time_consumers/jmx.rb,
lib/time_bandits/monkey_patches/redis.rb,
lib/time_bandits/time_consumers/redis.rb,
lib/time_bandits/time_consumers/sequel.rb,
lib/time_bandits/time_consumers/database.rb,
lib/time_bandits/time_consumers/mem_cache.rb,
lib/time_bandits/time_consumers/memcached.rb,
lib/time_bandits/time_consumers/garbage_collection.rb

Overview

a time consumer implementation for garbage collection

Defined Under Namespace

Modules: Rack, RedisInstrumentation, TimeConsumers Classes: Railtie

Constant Summary collapse

VERSION =
"0.14.1"

Class Method Summary collapse

Class Method Details

.add(bandit) ⇒ Object



25
26
27
# File 'lib/time_bandits.rb', line 25

def self.add(bandit)
  self.time_bandits << bandit unless self.time_bandits.include?(bandit)
end

.benchmark(title = "Completed in", logger = Rails.logger) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/time_bandits.rb', line 60

def self.benchmark(title="Completed in", logger=Rails.logger)
  reset
  result = nil
  e = nil
  seconds = Benchmark.realtime do
    begin
      result = yield
    rescue Exception => e
      logger.error "Exception: #{e.class}(#{e.message}):\n#{e.backtrace[0..5].join("\n")}"
    end
  end
  consumed # needs to be called for DB time consumer
  rc = e ? "500 Internal Server Error" : "200 OK"
  logger.info "#{title} #{sprintf("%.3f", seconds * 1000)}ms (#{runtime}) | #{rc}"
  raise e if e
  result
end

.consumedObject



33
34
35
# File 'lib/time_bandits.rb', line 33

def self.consumed
  time_bandits.map{|b| b.consumed}.sum
end

.current_runtime(except = []) ⇒ Object



37
38
39
40
# File 'lib/time_bandits.rb', line 37

def self.current_runtime(except = [])
  except = Array(except)
  time_bandits.map{|b| except.include?(b) ? 0 : b.current_runtime}.sum
end

.metricsObject



50
51
52
53
54
55
56
57
58
# File 'lib/time_bandits.rb', line 50

def self.metrics
  metrics = Hash.new(0)
  time_bandits.each do |bandit|
    bandit.metrics.each do |k,v|
      metrics[k] += v
    end
  end
  metrics
end

.resetObject



29
30
31
# File 'lib/time_bandits.rb', line 29

def self.reset
  time_bandits.each{|b| b.reset}
end

.runtimeObject



46
47
48
# File 'lib/time_bandits.rb', line 46

def self.runtime
  runtimes.join(" | ")
end

.runtimesObject



42
43
44
# File 'lib/time_bandits.rb', line 42

def self.runtimes
  time_bandits.map{|b| b.runtime}.reject{|t| t.blank?}
end