Class: Drone::Metrics::Timer

Inherits:
Drone::Metric show all
Extended by:
Forwardable
Defined in:
lib/drone/metrics/timer.rb

Overview

The timer metric will record the time spent in a given method or any block of code.

All the times are in milliseconds.

Instance Attribute Summary

Attributes inherited from Drone::Metric

#name

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Timer

Returns a new instance of Timer.



19
20
21
22
23
# File 'lib/drone/metrics/timer.rb', line 19

def initialize(name)
  super(name)
  
  @histogram = Histogram.new("#{name}:histogram", :biased)
end

Instance Method Details

#clearObject



29
30
31
# File 'lib/drone/metrics/timer.rb', line 29

def clear
  @histogram.clear()
end

#countObject



25
26
27
# File 'lib/drone/metrics/timer.rb', line 25

def count
  @histogram.count
end

#time {|Proc| ... } ⇒ Object

time and record the duration of the block

Yields:

  • (Proc)

    The block to time



48
49
50
51
52
53
# File 'lib/drone/metrics/timer.rb', line 48

def time
  started_at = Time.now.to_f
  yield()
ensure
  update((Time.now.to_f - started_at.to_f) * 1000)
end

#update(duration) ⇒ Object

Method used to record a new duration

Parameters:

  • duration (Float)

    A duration in milliseconds



38
39
40
41
42
# File 'lib/drone/metrics/timer.rb', line 38

def update(duration)
  if duration >= 0
    @histogram.update(duration)
  end
end