Class: D13n::Metric::Stream::TracedSpanStack
- Inherits:
-
Object
- Object
- D13n::Metric::Stream::TracedSpanStack
- Defined in:
- lib/d13n/metric/stream/traced_span_stack.rb
Instance Method Summary collapse
- #clear ⇒ Object
- #empty? ⇒ Boolean
- #fetch_matching_frame(expected_frame) ⇒ Object
-
#initialize ⇒ TracedSpanStack
constructor
A new instance of TracedSpanStack.
- #last ⇒ Object
- #note_children_time(frame, time, deduct_call_time_from_parent) ⇒ Object
- #pop_frame(state, expected_frame, name, time, deduct_call_time_from_parent = true) ⇒ Object
- #push_frame(state, tag, time = Time.now.to_f) ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize ⇒ TracedSpanStack
Returns a new instance of TracedSpanStack.
15 16 17 |
# File 'lib/d13n/metric/stream/traced_span_stack.rb', line 15 def initialize @stack = [] end |
Instance Method Details
#clear ⇒ Object
60 61 62 |
# File 'lib/d13n/metric/stream/traced_span_stack.rb', line 60 def clear @stack.clear end |
#empty? ⇒ Boolean
56 57 58 |
# File 'lib/d13n/metric/stream/traced_span_stack.rb', line 56 def empty? @stack.empty? end |
#fetch_matching_frame(expected_frame) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/d13n/metric/stream/traced_span_stack.rb', line 35 def fetch_matching_frame(expected_frame) while frame = @stack.pop if frame == expected_frame return frame else D13n.logger.info("Unexpected frame in traced method stack: #{frame.inspect} expected to be #{expected_frame.inspect}") end end raise UnexpectedStackError.new "Frame not found in stack: #{expected_frame.inspect}" end |
#last ⇒ Object
64 65 66 |
# File 'lib/d13n/metric/stream/traced_span_stack.rb', line 64 def last @stack.last end |
#note_children_time(frame, time, deduct_call_time_from_parent) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/d13n/metric/stream/traced_span_stack.rb', line 46 def note_children_time(frame, time, deduct_call_time_from_parent) if !@stack.empty? if deduct_call_time_from_parent @stack.last.children_time += (time - frame.start_time) else @stack.last.children_time += frame.children_time end end end |
#pop_frame(state, expected_frame, name, time, deduct_call_time_from_parent = true) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/d13n/metric/stream/traced_span_stack.rb', line 25 def pop_frame(state, expected_frame, name, time, deduct_call_time_from_parent=true) frame = fetch_matching_frame(expected_frame) frame.end_time = time frame.name = name note_children_time(frame, time, deduct_call_time_from_parent) frame end |
#push_frame(state, tag, time = Time.now.to_f) ⇒ Object
19 20 21 22 23 |
# File 'lib/d13n/metric/stream/traced_span_stack.rb', line 19 def push_frame(state, tag, time = Time.now.to_f) frame = StackFrame.new(tag, time) @stack.push frame frame end |
#size ⇒ Object
68 69 70 |
# File 'lib/d13n/metric/stream/traced_span_stack.rb', line 68 def size @stack.size end |