Class: LogStash::Instrument::Metric::TimedExecution
- Inherits:
-
Object
- Object
- LogStash::Instrument::Metric::TimedExecution
- Defined in:
- lib/logstash/instrument/metric.rb
Overview
Allow to calculate the execution of a block of code. This class support 2 differents syntax a block or the return of the object itself, but in the later case the metric won’t be recorded Until we call ‘#stop`.
Constant Summary collapse
- MILLISECONDS =
1_000.0.freeze
Instance Method Summary collapse
-
#initialize(metric, namespace, key) ⇒ TimedExecution
constructor
A new instance of TimedExecution.
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(metric, namespace, key) ⇒ TimedExecution
Returns a new instance of TimedExecution.
87 88 89 90 91 92 |
# File 'lib/logstash/instrument/metric.rb', line 87 def initialize(metric, namespace, key) @metric = metric @namespace = namespace @key = key start end |
Instance Method Details
#start ⇒ Object
94 95 96 |
# File 'lib/logstash/instrument/metric.rb', line 94 def start @start_time = Time.now end |
#stop ⇒ Object
98 99 100 101 102 |
# File 'lib/logstash/instrument/metric.rb', line 98 def stop execution_time = (MILLISECONDS * (Time.now - @start_time)).to_i @metric.report_time(@namespace, @key, execution_time) execution_time end |