Class: TingYun::Agent::Transaction::TraceNode
- Inherits:
-
Object
- Object
- TingYun::Agent::Transaction::TraceNode
- Defined in:
- lib/ting_yun/agent/transaction/trace_node.rb
Constant Summary collapse
- UNKNOWN_NODE_NAME =
'<unknown>'.freeze
Instance Attribute Summary collapse
-
#called_nodes ⇒ Object
readonly
Returns the value of attribute called_nodes.
-
#count ⇒ Object
Returns the value of attribute count.
-
#entry_timestamp ⇒ Object
readonly
Returns the value of attribute entry_timestamp.
-
#exit_timestamp ⇒ Object
Returns the value of attribute exit_timestamp.
-
#klass ⇒ Object
Returns the value of attribute klass.
-
#method ⇒ Object
Returns the value of attribute method.
-
#metric_name ⇒ Object
Returns the value of attribute metric_name.
-
#name ⇒ Object
Returns the value of attribute name.
-
#parent_node ⇒ Object
readonly
Returns the value of attribute parent_node.
-
#uri ⇒ Object
Returns the value of attribute uri.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #add_called_node(s) ⇒ Object
- #custom_params ⇒ Object
-
#duration ⇒ Object
return the total duration of this node.
- #each_call(&blk) ⇒ Object
- #end_trace(timestamp) ⇒ Object
- #explain_sql ⇒ Object
-
#initialize(timestamp, metric_name) ⇒ TraceNode
constructor
A new instance of TraceNode.
- #params ⇒ Object
- #params=(p) ⇒ Object
- #pre_metric_name(metric_name) ⇒ Object
- #request_params ⇒ Object
- #to_array ⇒ Object
Constructor Details
#initialize(timestamp, metric_name) ⇒ TraceNode
Returns a new instance of TraceNode.
20 21 22 23 24 25 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 20 def initialize(, metric_name) = @metric_name = metric_name || UNKNOWN_NODE_NAME @called_nodes = nil @count = 1 end |
Instance Attribute Details
#called_nodes ⇒ Object (readonly)
Returns the value of attribute called_nodes.
12 13 14 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 12 def called_nodes @called_nodes end |
#count ⇒ Object
Returns the value of attribute count.
13 14 15 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 13 def count @count end |
#entry_timestamp ⇒ Object (readonly)
Returns the value of attribute entry_timestamp.
12 13 14 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 12 def end |
#exit_timestamp ⇒ Object
Returns the value of attribute exit_timestamp.
13 14 15 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 13 def end |
#klass ⇒ Object
Returns the value of attribute klass.
13 14 15 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 13 def klass @klass end |
#method ⇒ Object
Returns the value of attribute method.
13 14 15 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 13 def method @method end |
#metric_name ⇒ Object
Returns the value of attribute metric_name.
13 14 15 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 13 def metric_name @metric_name end |
#name ⇒ Object
Returns the value of attribute name.
13 14 15 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 13 def name @name end |
#parent_node ⇒ Object
Returns the value of attribute parent_node.
12 13 14 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 12 def parent_node @parent_node end |
#uri ⇒ Object
Returns the value of attribute uri.
13 14 15 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 13 def uri @uri end |
Instance Method Details
#[](key) ⇒ Object
77 78 79 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 77 def [](key) params[key] end |
#[]=(key, value) ⇒ Object
71 72 73 74 75 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 71 def []=(key, value) # only create a parameters field if a parameter is set; this will save # bandwidth etc as most nodes have no parameters params[key] = value end |
#add_called_node(s) ⇒ Object
27 28 29 30 31 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 27 def add_called_node(s) @called_nodes ||= [] @called_nodes << s s.parent_node = self end |
#custom_params ⇒ Object
63 64 65 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 63 def custom_params {} end |
#duration ⇒ Object
return the total duration of this node
38 39 40 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 38 def duration TingYun::Helper.time_to_millis( - ) end |
#each_call(&blk) ⇒ Object
89 90 91 92 93 94 95 96 97 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 89 def each_call(&blk) blk.call self if @called_nodes @called_nodes.each do |node| node.each_call(&blk) end end end |
#end_trace(timestamp) ⇒ Object
33 34 35 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 33 def end_trace() = end |
#explain_sql ⇒ Object
99 100 101 102 103 104 105 106 107 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 99 def explain_sql return params[:explainPlan] if params.key?(:explainPlan) statement = params[:sql] return nil unless statement.respond_to?(:config) && statement.respond_to?(:explainer) TingYun::Agent::Database.explain_sql(statement) end |
#params ⇒ Object
81 82 83 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 81 def params @params ||= {} end |
#params=(p) ⇒ Object
85 86 87 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 85 def params=(p) @params = p end |
#pre_metric_name(metric_name) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 43 def pre_metric_name(metric_name) @name ||= if metric_name.start_with?('Database ') "#{metric_name.split('/')[0]}%2F#{metric_name.split('%2F')[-1]}" else metric_name end end |
#request_params ⇒ Object
67 68 69 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 67 def request_params {} end |
#to_array ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/ting_yun/agent/transaction/trace_node.rb', line 51 def to_array [TingYun::Helper.time_to_millis(), TingYun::Helper.time_to_millis(), TingYun::Support::Coerce.string(metric_name), TingYun::Support::Coerce.string(uri)||'', TingYun::Support::Coerce.int(count), TingYun::Support::Coerce.string(klass)||TingYun::Support::Coerce.string(pre_metric_name(metric_name)), TingYun::Support::Coerce.string(method)||'', params] + [(@called_nodes ? @called_nodes.map{|s| s.to_array} : [])] end |