Class: DiverDown::Trace::CallStack
- Inherits:
-
Object
- Object
- DiverDown::Trace::CallStack
- Defined in:
- lib/diver_down/trace/call_stack.rb
Overview
To handle call stacks obtained by TracePoint more efficiently. TracePoint also acquires calls that are not trace targets, but for dependency extraction, we want to acquire only a list of targets. In this class, push/pop is performed on all call/return, but it should always be possible to trace back to the caller of the target dependency at high speed.
Defined Under Namespace
Classes: StackEmptyError
Instance Attribute Summary collapse
- #stack_size ⇒ Object readonly
Instance Method Summary collapse
- #context_stack ⇒ Array<Object>
- #context_stack_size ⇒ Array<Integer>
- #empty_context_stack? ⇒ Boolean
-
#ignored? ⇒ Boolean
If a stack is not already a tracing target, some conditions are unnecessary so that it can be easily ignored.
-
#initialize ⇒ CallStack
constructor
A new instance of CallStack.
- #pop ⇒ void
- #push(context = nil, ignored: false) ⇒ void
Constructor Details
#initialize ⇒ CallStack
Returns a new instance of CallStack.
14 15 16 17 18 |
# File 'lib/diver_down/trace/call_stack.rb', line 14 def initialize @ignored_stack_size = nil @stack_size = 0 @context_stack = {} end |
Instance Attribute Details
#stack_size ⇒ Object (readonly)
12 13 14 |
# File 'lib/diver_down/trace/call_stack.rb', line 12 def stack_size @stack_size end |
Instance Method Details
#context_stack ⇒ Array<Object>
31 32 33 |
# File 'lib/diver_down/trace/call_stack.rb', line 31 def context_stack @context_stack.values end |
#context_stack_size ⇒ Array<Integer>
26 27 28 |
# File 'lib/diver_down/trace/call_stack.rb', line 26 def context_stack_size @context_stack.keys end |
#empty_context_stack? ⇒ Boolean
21 22 23 |
# File 'lib/diver_down/trace/call_stack.rb', line 21 def empty_context_stack? @context_stack.empty? end |
#ignored? ⇒ Boolean
If a stack is not already a tracing target, some conditions are unnecessary so that it can be easily ignored.
46 47 48 |
# File 'lib/diver_down/trace/call_stack.rb', line 46 def ignored? !@ignored_stack_size.nil? end |
#pop ⇒ void
This method returns an undefined value.
51 52 53 54 55 56 57 |
# File 'lib/diver_down/trace/call_stack.rb', line 51 def pop raise StackEmptyError if @stack_size.zero? @context_stack.delete(@stack_size) if @context_stack.key?(@stack_size) @ignored_stack_size = nil if @ignored_stack_size && @ignored_stack_size == @stack_size @stack_size -= 1 end |
#push(context = nil, ignored: false) ⇒ void
This method returns an undefined value.
37 38 39 40 41 |
# File 'lib/diver_down/trace/call_stack.rb', line 37 def push(context = nil, ignored: false) @stack_size += 1 @context_stack[@stack_size] = context unless context.nil? @ignored_stack_size ||= @stack_size if ignored end |