Class: TPTree::CallStack
- Inherits:
-
Object
- Object
- TPTree::CallStack
- Defined in:
- lib/tp_tree/call_stack.rb
Overview
CallStack manages the state of method calls during tracing
Instance Method Summary collapse
- #add_event(event) ⇒ Object
- #current_depth ⇒ Object
- #empty? ⇒ Boolean
- #events ⇒ Object
- #events_array ⇒ Object
- #finish_call(method_name, return_value, end_time) ⇒ Object
-
#initialize ⇒ CallStack
constructor
A new instance of CallStack.
- #set_event_at_index(index, event) ⇒ Object
- #start_call(method_name, parameters, defined_class, path, lineno, start_time) ⇒ Object
Constructor Details
#initialize ⇒ CallStack
Returns a new instance of CallStack.
6 7 8 9 10 |
# File 'lib/tp_tree/call_stack.rb', line 6 def initialize @call_stack = [] @call_depth = 0 @events = [] end |
Instance Method Details
#add_event(event) ⇒ Object
48 49 50 |
# File 'lib/tp_tree/call_stack.rb', line 48 def add_event(event) @events << event end |
#current_depth ⇒ Object
64 65 66 |
# File 'lib/tp_tree/call_stack.rb', line 64 def current_depth @call_depth end |
#empty? ⇒ Boolean
68 69 70 |
# File 'lib/tp_tree/call_stack.rb', line 68 def empty? @call_stack.empty? end |
#events ⇒ Object
56 57 58 |
# File 'lib/tp_tree/call_stack.rb', line 56 def events @events.compact end |
#events_array ⇒ Object
60 61 62 |
# File 'lib/tp_tree/call_stack.rb', line 60 def events_array @events end |
#finish_call(method_name, return_value, end_time) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/tp_tree/call_stack.rb', line 31 def finish_call(method_name, return_value, end_time) return nil if @call_stack.empty? # Find matching call on stack (handles filtered nested calls) call_info = @call_stack.last return nil unless call_info && call_info[:method_name] == method_name @call_depth -= 1 @call_stack.pop call_info.merge( return_value: return_value, end_time: end_time, has_children: @events.length > call_info[:event_index] + 1 ) end |
#set_event_at_index(index, event) ⇒ Object
52 53 54 |
# File 'lib/tp_tree/call_stack.rb', line 52 def set_event_at_index(index, event) @events[index] = event end |
#start_call(method_name, parameters, defined_class, path, lineno, start_time) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/tp_tree/call_stack.rb', line 12 def start_call(method_name, parameters, defined_class, path, lineno, start_time) call_info = { method_name: method_name, parameters: parameters, depth: @call_depth, event_index: @events.length, defined_class: defined_class, path: path, lineno: lineno, start_time: start_time } @call_stack.push(call_info) @events << nil # Placeholder for the actual TreeNode @call_depth += 1 call_info end |