Class: Drone::Metrics::Timer
- Inherits:
-
Drone::Metric
- Object
- Drone::Metric
- Drone::Metrics::Timer
- 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
Instance Method Summary collapse
- #clear ⇒ Object
- #count ⇒ Object
-
#initialize(name) ⇒ Timer
constructor
A new instance of Timer.
-
#time {|Proc| ... } ⇒ Object
time and record the duration of the block.
-
#update(duration) ⇒ Object
Method used to record a new duration.
Constructor Details
Instance Method Details
#clear ⇒ Object
29 30 31 |
# File 'lib/drone/metrics/timer.rb', line 29 def clear @histogram.clear() end |
#count ⇒ Object
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
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
38 39 40 41 42 |
# File 'lib/drone/metrics/timer.rb', line 38 def update(duration) if duration >= 0 @histogram.update(duration) end end |