Class: Airbrake::TimedTrace
- Inherits:
-
Object
- Object
- Airbrake::TimedTrace
- Defined in:
- lib/airbrake-ruby/timed_trace.rb
Overview
TimedTrace represents a chunk of code performance of which was measured and stored under a label. The chunk is called a “span”.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ TimedTrace
constructor
A new instance of TimedTrace.
- #span(label) ⇒ Boolean
- #spans ⇒ Hash<String=>Float>
- #start_span(label) ⇒ Boolean
- #stop_span(label) ⇒ Boolean
Constructor Details
#initialize ⇒ TimedTrace
Returns a new instance of TimedTrace.
21 22 23 |
# File 'lib/airbrake-ruby/timed_trace.rb', line 21 def initialize @spans = {} end |
Class Method Details
.span(label, &block) ⇒ Airbrake::TimedTrace
17 18 19 |
# File 'lib/airbrake-ruby/timed_trace.rb', line 17 def self.span(label, &block) new.tap { |timed_trace| timed_trace.span(label, &block) } end |
Instance Method Details
#span(label) ⇒ Boolean
27 28 29 30 31 |
# File 'lib/airbrake-ruby/timed_trace.rb', line 27 def span(label) start_span(label) yield stop_span(label) end |
#spans ⇒ Hash<String=>Float>
52 53 54 |
# File 'lib/airbrake-ruby/timed_trace.rb', line 52 def spans @spans.transform_values(&:duration) end |
#start_span(label) ⇒ Boolean
35 36 37 38 39 40 |
# File 'lib/airbrake-ruby/timed_trace.rb', line 35 def start_span(label) return false if @spans.key?(label) @spans[label] = Airbrake::Benchmark.new true end |
#stop_span(label) ⇒ Boolean
44 45 46 47 48 49 |
# File 'lib/airbrake-ruby/timed_trace.rb', line 44 def stop_span(label) return false unless @spans.key?(label) @spans[label].stop true end |