Class: SourceRoute::Wrapper

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Singleton
Defined in:
lib/source_route/wrapper.rb

Defined Under Namespace

Classes: Condition

Constant Summary collapse

TRACE_POINT_METHODS =
[:defined_class, :method_id, :path, :lineno]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeWrapper



55
56
57
# File 'lib/source_route/wrapper.rb', line 55

def initialize
  reset
end

Instance Attribute Details

#conditionObject

Returns the value of attribute condition.



8
9
10
# File 'lib/source_route/wrapper.rb', line 8

def condition
  @condition
end

#tpObject

Returns the value of attribute tp.



8
9
10
# File 'lib/source_route/wrapper.rb', line 8

def tp
  @tp
end

#tp_result_chainObject (readonly)

Returns the value of attribute tp_result_chain.



9
10
11
# File 'lib/source_route/wrapper.rb', line 9

def tp_result_chain
  @tp_result_chain
end

Instance Method Details

#resetObject



59
60
61
62
63
64
# File 'lib/source_route/wrapper.rb', line 59

def reset
  @tp.disable if @tp
  @condition = Condition.new
  @tp_result_chain = TpResultChain.new
  self
end

#traceObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/source_route/wrapper.rb', line 66

def trace
  # dont wanna init it in tp block, cause tp block could run thousands of times in one cycle trace
  tp_result = GenerateResult.new(self)
  tp_filter = TpFilter.new(condition)

  track = TracePoint.new *condition.events do |tp|

    next if tp_filter.block_it?(tp)

    unless condition.result_config.format.is_a? Proc
      ret_data = tp_result.build(tp)
      @tp_result_chain.push(ret_data)
    end

    tp_result.output(tp)
  end
  track.enable
  self.tp = track
  track
end