Class: Appstats::Benchmarker

Inherits:
Object
  • Object
show all
Defined in:
lib/appstats/benchmarker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = {}) ⇒ Benchmarker

Returns a new instance of Benchmarker.



9
10
11
# File 'lib/appstats/benchmarker.rb', line 9

def initialize(data = {})
  @redis = data[:redis] || Redis.new
end

Instance Attribute Details

#redisObject

Returns the value of attribute redis.



7
8
9
# File 'lib/appstats/benchmarker.rb', line 7

def redis
  @redis
end

Instance Method Details

#measure(title, legend) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/appstats/benchmarker.rb', line 13

def measure(title,legend)
  time = Benchmark.measure do
    yield
  end
  record(title,legend,time.real)
  time
end

#record(title, legend, point) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/appstats/benchmarker.rb', line 21

def record(title,legend,point)
  redis.multi do
    redis.sadd "benchmarks", title
    redis.sadd "benchmarks:#{title}", legend
    redis.rpush "benchmarks:#{title}:#{legend}", point
  end
end