class OneApm::TransactionSample::Segment
Constants
- OA_UNKNOWN_SEGMENT_NAME
Attributes
entry_timestamp[R]
exit_timestamp[R]
The exit timestamp will be relative except for the outermost sample which will have a timestamp.
metric_name[RW]
parent_segment[R]
segment_id[R]
This is only used from developer mode and rpm_site. No new clients should be added.
Public Class Methods
new(timestamp, metric_name, segment_id=nil)
click to toggle source
# File lib/one_apm/transaction/segment.rb, line 20 def initialize(timestamp, metric_name, segment_id=nil) @entry_timestamp = timestamp @metric_name = metric_name || OA_UNKNOWN_SEGMENT_NAME @segment_id = segment_id || object_id end
Public Instance Methods
[](key)
click to toggle source
# File lib/one_apm/transaction/segment.rb, line 119 def [](key) params[key] end
[]=(key, value)
click to toggle source
# File lib/one_apm/transaction/segment.rb, line 113 def []=(key, value) # only create a parameters field if a parameter is set; this will save # bandwidth etc as most segments have no parameters params[key] = value end
add_called_segment(s)
click to toggle source
# File lib/one_apm/transaction/segment.rb, line 32 def add_called_segment(s) @called_segments ||= [] @called_segments << s s.parent_segment = self end
called_segments()
click to toggle source
# File lib/one_apm/transaction/segment.rb, line 87 def called_segments @called_segments || [] end
called_segments=(segments)
click to toggle source
# File lib/one_apm/transaction/segment.rb, line 184 def called_segments=(segments) @called_segments = segments end
count_segments()
click to toggle source
# File lib/one_apm/transaction/segment.rb, line 107 def count_segments count = 1 called_segments.each { | seg | count += seg.count_segments } count end
duration()
click to toggle source
return the total duration of this segment
# File lib/one_apm/transaction/segment.rb, line 92 def duration (@exit_timestamp - @entry_timestamp).to_f end
each_segment(&block)
click to toggle source
call the provided block for this segment and each of the called segments
# File lib/one_apm/transaction/segment.rb, line 133 def each_segment(&block) block.call self if @called_segments @called_segments.each do |segment| segment.each_segment(&block) end end end
each_segment_with_nest_tracking(&block)
click to toggle source
call the provided block for this segment and each of the called segments while keeping track of nested segments
# File lib/one_apm/transaction/segment.rb, line 145 def each_segment_with_nest_tracking(&block) summary = block.call self summary.current_nest_count += 1 if summary if @called_segments @called_segments.each do |segment| segment.each_segment_with_nest_tracking(&block) end end summary.current_nest_count -= 1 if summary end
end_trace(timestamp)
click to toggle source
sets the final timestamp on a segment to indicate the exit point of the segment
# File lib/one_apm/transaction/segment.rb, line 28 def end_trace(timestamp) @exit_timestamp = timestamp end
exclusive_duration()
click to toggle source
return the duration of this segment without including the time in the called segments
# File lib/one_apm/transaction/segment.rb, line 98 def exclusive_duration d = duration called_segments.each do |segment| d -= segment.duration end d end
explain_sql()
click to toggle source
# File lib/one_apm/transaction/segment.rb, line 168 def explain_sql return params[:explain_plan] if params.key?(:explain_plan) statement = params[:sql] return nil unless statement.respond_to?(:config) && statement.respond_to?(:explainer) OneApm::Agent::Database.explain_sql(statement, statement.config, &statement.explainer) end
find_segment(id)
click to toggle source
This is only for use by developer mode
# File lib/one_apm/transaction/segment.rb, line 159 def find_segment(id) return self if segment_id == id called_segments.each do |segment| found = segment.find_segment(id) return found if found end nil end
obfuscated_sql()
click to toggle source
# File lib/one_apm/transaction/segment.rb, line 180 def obfuscated_sql OneApm::Agent::Database.obfuscate_sql(params[:sql]) end
params()
click to toggle source
# File lib/one_apm/transaction/segment.rb, line 123 def params @params ||= {} end
params=(p)
click to toggle source
# File lib/one_apm/transaction/segment.rb, line 127 def params=(p) @params = p end
path_string()
click to toggle source
# File lib/one_apm/transaction/segment.rb, line 53 def path_string "#{metric_name}[#{called_segments.collect {|segment| segment.path_string }.join('')}]" end
to_array()
click to toggle source
# File lib/one_apm/transaction/segment.rb, line 44 def to_array [ OneApm::Helper.time_to_millis(@entry_timestamp), OneApm::Helper.time_to_millis(@exit_timestamp), string(@metric_name), (@params || {}) ] + [ (@called_segments ? @called_segments.map{|s| s.to_array} : []) ] #+ # [ '', '' ] end
to_debug_str(depth)
click to toggle source
# File lib/one_apm/transaction/segment.rb, line 66 def to_debug_str(depth) tab = " " * depth s = tab.clone s << ">> #{'%3i ms' % (@entry_timestamp*1000)} [#{self.class.name.split("::").last}] #{metric_name} \n" unless params.empty? params.each do |k,v| s << "#{tab} -#{'%-16s' % k}: #{v.to_s[0..80]}\n" end end called_segments.each do |cs| s << cs.to_debug_str(depth + 1) end s << tab + "<< " s << case @exit_timestamp when nil then ' n/a' when Numeric then '%3i ms' % (@exit_timestamp*1000) else @exit_timestamp.to_s end s << " #{metric_name}\n" end
to_s()
click to toggle source
# File lib/one_apm/transaction/segment.rb, line 38 def to_s to_debug_str(0) end
to_s_compact()
click to toggle source
# File lib/one_apm/transaction/segment.rb, line 57 def to_s_compact str = "" str << metric_name if called_segments.any? str << "{#{called_segments.map { | cs | cs.to_s_compact }.join(",")}}" end str end
Protected Instance Methods
parent_segment=(s)
click to toggle source
# File lib/one_apm/transaction/segment.rb, line 189 def parent_segment=(s) @parent_segment = s end