Class: SourceRoute::Wrapper

Inherits:
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



69
70
71
# File 'lib/source_route/wrapper.rb', line 69

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

#tp_self_cachesObject (readonly)

Returns the value of attribute tp_self_caches.



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

def tp_self_caches
  @tp_self_caches
end

Instance Method Details

#jsonify_eventsObject



101
102
103
# File 'lib/source_route/wrapper.rb', line 101

def jsonify_events
  Oj.dump(@condition.events.map(&:to_s))
end

#jsonify_tp_result_chainObject



105
106
107
108
109
# File 'lib/source_route/wrapper.rb', line 105

def jsonify_tp_result_chain
  # puts tp_result_chain.stringify
  json_array = tp_result_chain.map { |result| Jsonify.dump(result) }
  '[ ' + json_array.join(',') + ' ]'
end

#jsonify_tp_self_cachesObject



111
112
113
# File 'lib/source_route/wrapper.rb', line 111

def jsonify_tp_self_caches
  Oj.dump(tp_self_caches.clone.map(&:to_s))
end

#resetObject



73
74
75
76
77
78
79
# File 'lib/source_route/wrapper.rb', line 73

def reset
  @tp.disable if defined? @tp
  @condition = Condition.new
  @tp_result_chain = TpResultChain.new
  @tp_self_caches = []
  self
end

#traceObject



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/source_route/wrapper.rb', line 81

def trace
  # dont wanna init it in tp block, cause tp block could run thousands of times in one cycle trace
  build_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 = build_result.build(tp)
      @tp_result_chain.push(ret_data)
    end

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