class HeimdallApm::Segment
Attributes
data[RW]
Additional data linked to the segment (for example SQL or Elastic queries). Can be left nil.
name[R]
More specific name of the item
Examples: "User#find", "find_by_sql", "users#index"
start_time[R]
Start and stop of this segment
stop_time[R]
Start and stop of this segment
type[R]
Generic type of the thing being tracked
Examples: "ActiveRecord", "SQL", "Controller"
Public Class Methods
new(type, name, start_time = nil)
click to toggle source
# File lib/heimdall_apm/segment.rb, line 18 def initialize(type, name, start_time = nil) @type = type @name = name @start_time = start_time @children = nil end
Public Instance Methods
accept(visitor)
click to toggle source
Entry point for visitors depth-first style: start by visiting `self` then visit all of its children
# File lib/heimdall_apm/segment.rb, line 40 def accept(visitor) visitor.visit(self) if @children visitor.before_children if visitor.respond_to?(:before_children) @children.each { |c| c.accept(visitor) } visitor.after_children if visitor.respond_to?(:after_children) end end
add_child(segment)
click to toggle source
# File lib/heimdall_apm/segment.rb, line 34 def add_child(segment) children << segment end
children()
click to toggle source
Lazy initialization of children to avoid bloating leaf segments
# File lib/heimdall_apm/segment.rb, line 30 def children @children ||= [] end
record_stop_time()
click to toggle source
# File lib/heimdall_apm/segment.rb, line 49 def record_stop_time @stop_time = Process.clock_gettime(Process::CLOCK_REALTIME) end
start()
click to toggle source
# File lib/heimdall_apm/segment.rb, line 25 def start @start_time = Process.clock_gettime(Process::CLOCK_REALTIME) end
total_call_time()
click to toggle source
# File lib/heimdall_apm/segment.rb, line 53 def total_call_time @total_call_time ||= stop_time - start_time end
total_exclusive_time()
click to toggle source
# File lib/heimdall_apm/segment.rb, line 57 def total_exclusive_time return total_call_time unless @children total_call_time - children_call_time end
Private Instance Methods
children_call_time()
click to toggle source
# File lib/heimdall_apm/segment.rb, line 64 def children_call_time children.map(&:total_call_time).sum end