Class: SCNR::Introspector::ExecutionFlow
- Inherits:
-
Object
- Object
- SCNR::Introspector::ExecutionFlow
- Defined in:
- lib/scnr/introspector/execution_flow.rb,
lib/scnr/introspector/execution_flow/point.rb,
lib/scnr/introspector/execution_flow/scope.rb
Defined Under Namespace
Constant Summary collapse
- ALLOWED_EVENTS =
Set.new([:line, :call, :c_call])
Instance Attribute Summary collapse
- #points ⇒ Array<Point> readonly
- #scope ⇒ Scope
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}, &block) ⇒ ExecutionFlow
constructor
A new instance of ExecutionFlow.
- #to_rpc_data ⇒ Object
- #trace(&block) ⇒ ExecutionFlow
Constructor Details
#initialize(options = {}, &block) ⇒ ExecutionFlow
Returns a new instance of ExecutionFlow.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/scnr/introspector/execution_flow.rb', line 27 def initialize( = {}, &block ) = .dup if (scope = .delete(:scope)).is_a? ExecutionFlow::Scope @scope = scope elsif scope.is_a? Hash @scope = ExecutionFlow::Scope.new( scope ) elsif scope.nil? @scope = ExecutionFlow::Scope.new else fail ExecutionFlow::Scope::Error::Invalid end @points = [] trace( &block ) if block_given? end |
Instance Attribute Details
#points ⇒ Array<Point> (readonly)
15 16 17 |
# File 'lib/scnr/introspector/execution_flow.rb', line 15 def points @points end |
#scope ⇒ Scope
12 13 14 |
# File 'lib/scnr/introspector/execution_flow.rb', line 12 def scope @scope end |
Class Method Details
.from_rpc_data(h) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/scnr/introspector/execution_flow.rb', line 83 def self.from_rpc_data( h ) n = self.new h.each do |k, v| case k when 'points' n.instance_variable_set( "@#{k}", v.map { |pd| Point.from_rpc_data( pd ) } ) else n.instance_variable_set( "@#{k}", v ) end end n end |
Instance Method Details
#to_rpc_data ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/scnr/introspector/execution_flow.rb', line 63 def to_rpc_data data = {} instance_variables.each do |iv| case iv when :@points data['points'] = @points.map(&:to_rpc_data) when :@scope next else v = instance_variable_get( iv ) next if !v data[iv.to_s.gsub('@','')] = v.to_rpc_data end end data end |
#trace(&block) ⇒ ExecutionFlow
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/scnr/introspector/execution_flow.rb', line 52 def trace( &block ) TracePoint.new do |tp| next if !ALLOWED_EVENTS.include? tp.event next if @scope.out?( tp.path ) @points << create_point_from_trace_point( tp ) end.enable(&block) self end |