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
Defined Under Namespace
Classes: Config
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_result_chain ⇒ Object
readonly
Returns the value of attribute tp_result_chain.
-
#tp_self_caches ⇒ Object
readonly
Returns the value of attribute tp_self_caches.
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(wrapper) ⇒ GenerateResult
constructor
A new instance of GenerateResult.
- #jsonify_events ⇒ Object
- #jsonify_tp_result_chain ⇒ Object
- #jsonify_tp_self_caches ⇒ Object
- #output(tp_ins) ⇒ Object
Constructor Details
#initialize(wrapper) ⇒ GenerateResult
Returns a new instance of GenerateResult.
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/source_route/generate_result.rb', line 42 def initialize(wrapper) @wrapper = wrapper @config = @wrapper.condition.result_config @tp_result_chain = TpResultChain.new @tp_self_caches = [] @wanted_attributes = {} 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_result_chain ⇒ Object (readonly)
Returns the value of attribute tp_result_chain.
11 12 13 |
# File 'lib/source_route/generate_result.rb', line 11 def tp_result_chain @tp_result_chain 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 |
Class Method Details
.clear_wanted_attributes ⇒ Object
64 65 66 |
# File 'lib/source_route/generate_result.rb', line 64 def self.clear_wanted_attributes @wanted_attributes = {} end |
.wanted_attributes(eve) ⇒ Object
it cached and only calculate once for one trace point block round
54 55 56 57 58 59 60 61 62 |
# File 'lib/source_route/generate_result.rb', line 54 def self.wanted_attributes(eve) event = eve.to_sym @wanted_attributes.fetch event do attrs = DEFAULT_ATTRS[event] + Array(SourceRoute.wrapper.condition.result_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
117 118 119 120 121 |
# File 'lib/source_route/generate_result.rb', line 117 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
123 124 125 |
# File 'lib/source_route/generate_result.rb', line 123 def jsonify_events Oj.dump(@wrapper.condition.events.map(&:to_s)) end |
#jsonify_tp_result_chain ⇒ Object
127 128 129 130 131 132 |
# File 'lib/source_route/generate_result.rb', line 127 def jsonify_tp_result_chain Oj.dump(tp_result_chain.chain.map(&:to_hash)) # tp_result_chain.to_json # json_array = tp_result_chain.map { |result| Jsonify.dump(result) } # '[ ' + json_array.join(',') + ' ]' end |
#jsonify_tp_self_caches ⇒ Object
134 135 136 137 |
# File 'lib/source_route/generate_result.rb', line 134 def jsonify_tp_self_caches Oj.dump(tp_self_caches.clone .map(&:to_s)) end |
#output(tp_ins) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/source_route/generate_result.rb', line 68 def output(tp_ins) format = @config.format format = format.to_sym if format.respond_to? :to_sym 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 collection is still in process # so we collect tp here @tp_result_chain.push(TpResult.new(tp_ins)) when :silence, :none # do nothing at now when :test @tp_result_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) end end |