Class: HeimdallApm::Segment

Inherits:
Object
  • Object
show all
Defined in:
lib/heimdall_apm/segment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, name, start_time = nil) ⇒ Segment

Returns a new instance of Segment.



18
19
20
21
22
23
# 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

Instance Attribute Details

#dataObject

Additional data linked to the segment (for example SQL or Elastic queries). Can be left nil.



16
17
18
# File 'lib/heimdall_apm/segment.rb', line 16

def data
  @data
end

#nameObject (readonly)

More specific name of the item

Examples: "User#find", "find_by_sql", "users#index"


9
10
11
# File 'lib/heimdall_apm/segment.rb', line 9

def name
  @name
end

#start_timeObject (readonly)

Start and stop of this segment



12
13
14
# File 'lib/heimdall_apm/segment.rb', line 12

def start_time
  @start_time
end

#stop_timeObject (readonly)

Start and stop of this segment



12
13
14
# File 'lib/heimdall_apm/segment.rb', line 12

def stop_time
  @stop_time
end

#typeObject (readonly)

Generic type of the thing being tracked

Examples: "ActiveRecord", "SQL", "Controller"


5
6
7
# File 'lib/heimdall_apm/segment.rb', line 5

def type
  @type
end

Instance Method Details

#accept(visitor) ⇒ Object

Entry point for visitors depth-first style: start by visiting ‘self` then visit all of its children



40
41
42
43
44
45
46
47
# 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) ⇒ Object



34
35
36
# File 'lib/heimdall_apm/segment.rb', line 34

def add_child(segment)
  children << segment
end

#childrenObject

Lazy initialization of children to avoid bloating leaf segments



30
31
32
# File 'lib/heimdall_apm/segment.rb', line 30

def children
  @children ||= []
end

#record_stop_timeObject



49
50
51
# File 'lib/heimdall_apm/segment.rb', line 49

def record_stop_time
  @stop_time = Process.clock_gettime(Process::CLOCK_REALTIME)
end

#startObject



25
26
27
# File 'lib/heimdall_apm/segment.rb', line 25

def start
  @start_time = Process.clock_gettime(Process::CLOCK_REALTIME)
end

#total_call_timeObject



53
54
55
# File 'lib/heimdall_apm/segment.rb', line 53

def total_call_time
  @total_call_time ||= stop_time - start_time
end

#total_exclusive_timeObject



57
58
59
60
# 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