Class: SourceRoute::GenerateResult
- Extended by:
- Forwardable
- Defined in:
- lib/source_route/generate_result.rb
Overview
How it work
-
Config collect route options
-
Proxy generate TracePoint Filter
-
Proxy generate TracePoint Monitor Block
-
Generator collect Wanted TracePoint
-
Parse and Generate Useful data from wanted TracePoint
-
Output data with correct format
Constant Summary collapse
- DEFAULT_ATTRS =
see event description in TracePoint API Doc
{ call: [:defined_class, :method_id], return: [:defined_class, :method_id, :return_value], c_call: [:defined_class, :method_id], line: [:path, :lineno], # following are not tested yet class: [:defined_class], end: [:defined_class], c_return: [:defined_class, :method_id, :return_value], raise: [:raised_exception], b_call: [:binding, :defined_class, :method_id], b_return: [:binding, :defined_class, :method_id, :return_value], thread_begin: [:defined_class, :method_id], thread_end: [:defined_class, :method_id] }
Instance Attribute Summary collapse
-
#collected_data ⇒ Object
readonly
Returns the value of attribute collected_data.
-
#tp_self_caches ⇒ Object
readonly
Returns the value of attribute tp_self_caches.
-
#trace_chain ⇒ Object
readonly
Returns the value of attribute trace_chain.
Class Method Summary collapse
- .clear_wanted_attributes ⇒ Object
-
.wanted_attributes(eve) ⇒ Object
it cached and only calculate once for one trace point block round.
Instance Method Summary collapse
-
#assign_tp_self_caches(tp_ins) ⇒ Object
include? will evaluate @tp.self, if @tp.self is AR::Relation, it could cause problems So that’s why I use object_id as replace.
-
#initialize(proxy) ⇒ GenerateResult
constructor
A new instance of GenerateResult.
- #jsonify_events ⇒ Object
- #jsonify_tp_self_caches ⇒ Object
- #jsonify_trace_chain ⇒ Object
- #output(tp_ins) ⇒ Object
Constructor Details
#initialize(proxy) ⇒ GenerateResult
Returns a new instance of GenerateResult.
33 34 35 36 37 |
# File 'lib/source_route/generate_result.rb', line 33 def initialize(proxy) @proxy = proxy @trace_chain = TraceChain.new @tp_self_caches = [] end |
Instance Attribute Details
#collected_data ⇒ Object (readonly)
Returns the value of attribute collected_data.
11 12 13 |
# File 'lib/source_route/generate_result.rb', line 11 def collected_data @collected_data end |
#tp_self_caches ⇒ Object (readonly)
Returns the value of attribute tp_self_caches.
11 12 13 |
# File 'lib/source_route/generate_result.rb', line 11 def tp_self_caches @tp_self_caches end |
#trace_chain ⇒ Object (readonly)
Returns the value of attribute trace_chain.
11 12 13 |
# File 'lib/source_route/generate_result.rb', line 11 def trace_chain @trace_chain end |
Class Method Details
.clear_wanted_attributes ⇒ Object
50 51 52 |
# File 'lib/source_route/generate_result.rb', line 50 def self.clear_wanted_attributes @wanted_attributes = {} end |
.wanted_attributes(eve) ⇒ Object
it cached and only calculate once for one trace point block round
40 41 42 43 44 45 46 47 48 |
# File 'lib/source_route/generate_result.rb', line 40 def self.wanted_attributes(eve) event = eve.to_sym @wanted_attributes.fetch event do attrs = DEFAULT_ATTRS[event] + Array(SourceRoute.proxy.config.show_additional_attrs) attrs.push(:event) @wanted_attributes[event] = attrs.uniq @wanted_attributes[event] end end |
Instance Method Details
#assign_tp_self_caches(tp_ins) ⇒ Object
include? will evaluate @tp.self, if @tp.self is AR::Relation, it could cause problems So that’s why I use object_id as replace
84 85 86 87 88 |
# File 'lib/source_route/generate_result.rb', line 84 def assign_tp_self_caches(tp_ins) unless tp_self_caches.find { |tp_cache| tp_cache.object_id.equal? tp_ins.self.object_id } tp_self_caches.push tp_ins.self end end |
#jsonify_events ⇒ Object
90 91 92 |
# File 'lib/source_route/generate_result.rb', line 90 def jsonify_events JSON.dump(@proxy.config.event.map(&:to_s)) end |
#jsonify_tp_self_caches ⇒ Object
104 105 106 107 |
# File 'lib/source_route/generate_result.rb', line 104 def jsonify_tp_self_caches JSON.dump(tp_self_caches.clone .map(&:to_s)) end |
#jsonify_trace_chain ⇒ Object
94 95 96 97 98 99 100 101 102 |
# File 'lib/source_route/generate_result.rb', line 94 def jsonify_trace_chain value = trace_chain.chain.map(&:to_hash) JSON.dump(value) # not worked # trace_chain.to_json # json_array = trace_chain.map { |result| JSON.dump(result) } # '[ ' + json_array.join(',') + ' ]' end |
#output(tp_ins) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/source_route/generate_result.rb', line 54 def output(tp_ins) format = @proxy.config.output_format assign_tp_self_caches(tp_ins) # we cant call method on tp_ins outside of track block, # so we have to run it immediately @collected_data = TpResult.new(tp_ins) case format when :console console_put(tp_ins) when :html # we cant generate html right now becase the tp callback is still in process # so we gather data into array @trace_chain.push(TpResult.new(tp_ins)) when :silence, :none # do nothing at now when :test @trace_chain.push(TpResult.new(tp_ins)) when :stack_overflow console_stack_overflow when Proc format.call(tp_ins) else klass = "SourceRoute::Formats::#{format.to_s.capitalize}" ::SourceRoute.const_get(klass).render(self, tp_ins, @collected_data) end end |