Class: TingYun::Agent::TracedMethodStack
- Inherits:
-
Object
- Object
- TingYun::Agent::TracedMethodStack
- Defined in:
- lib/ting_yun/agent/transaction/traced_method_stack.rb
Instance Method Summary collapse
- #clear ⇒ Object
- #empty? ⇒ Boolean
- #fetch_matching_frame(expected_frame) ⇒ Object
-
#initialize ⇒ TracedMethodStack
constructor
A new instance of TracedMethodStack.
- #note_children_time(frame, time, deduct_call_time_from_parent) ⇒ Object
- #pop_frame(state, expected_frame, name, time, deduct_call_time_from_parent = true, klass_name = nil) ⇒ Object
- #push_frame(state, tag, time = Time.now.to_f) ⇒ Object
- #sampler_enabled? ⇒ Boolean
- #transaction_sampler ⇒ Object
Constructor Details
#initialize ⇒ TracedMethodStack
Returns a new instance of TracedMethodStack.
17 18 19 |
# File 'lib/ting_yun/agent/transaction/traced_method_stack.rb', line 17 def initialize @stack = [] end |
Instance Method Details
#clear ⇒ Object
70 71 72 |
# File 'lib/ting_yun/agent/transaction/traced_method_stack.rb', line 70 def clear @stack.clear end |
#empty? ⇒ Boolean
74 75 76 |
# File 'lib/ting_yun/agent/transaction/traced_method_stack.rb', line 74 def empty? @stack.empty? end |
#fetch_matching_frame(expected_frame) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ting_yun/agent/transaction/traced_method_stack.rb', line 36 def fetch_matching_frame(expected_frame) while frame = @stack.pop if frame == expected_frame return frame else TingYun::Agent.logger.info("Unexpected frame in traced method stack: #{frame.inspect} expected to be #{expected_frame.inspect}") TingYun::Agent.logger.debug do ["Backtrace for unexpected frame: ", caller.join("\n")] end end end raise "Frame not found in blame stack: #{expected_frame.inspect}" end |
#note_children_time(frame, time, deduct_call_time_from_parent) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/ting_yun/agent/transaction/traced_method_stack.rb', line 51 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)*1000 else @stack.last.children_time += frame.children_time end end end |
#pop_frame(state, expected_frame, name, time, deduct_call_time_from_parent = true, klass_name = nil) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/ting_yun/agent/transaction/traced_method_stack.rb', line 28 def pop_frame(state, expected_frame, name, time, deduct_call_time_from_parent=true, klass_name=nil) frame = fetch_matching_frame(expected_frame) note_children_time(frame, time, deduct_call_time_from_parent) transaction_sampler.notice_pop_frame(state, name, time, klass_name) if sampler_enabled? frame.name = name frame end |
#push_frame(state, tag, time = Time.now.to_f) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/ting_yun/agent/transaction/traced_method_stack.rb', line 21 def push_frame(state, tag, time = Time.now.to_f) transaction_sampler.notice_push_frame(state, time) if sampler_enabled? frame = TracedMethodFrame.new(tag, time) @stack.push frame frame end |
#sampler_enabled? ⇒ Boolean
62 63 64 |
# File 'lib/ting_yun/agent/transaction/traced_method_stack.rb', line 62 def sampler_enabled? TingYun::Agent.config[:'nbs.action_tracer.enabled'] end |
#transaction_sampler ⇒ Object
66 67 68 |
# File 'lib/ting_yun/agent/transaction/traced_method_stack.rb', line 66 def transaction_sampler ::TingYun::Agent::Collector::TransactionSampler end |