Class: HeimdallApm::Segment
- Inherits:
-
Object
- Object
- HeimdallApm::Segment
- Defined in:
- lib/heimdall_apm/segment.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Additional data linked to the segment (for example SQL or Elastic queries).
-
#name ⇒ Object
readonly
More specific name of the item Examples: “User#find”, “find_by_sql”, “users#index”.
-
#start_time ⇒ Object
readonly
Start and stop of this segment.
-
#stop_time ⇒ Object
readonly
Start and stop of this segment.
-
#type ⇒ Object
readonly
Generic type of the thing being tracked Examples: “ActiveRecord”, “SQL”, “Controller”.
Instance Method Summary collapse
-
#accept(visitor) ⇒ Object
Entry point for visitors depth-first style: start by visiting ‘self` then visit all of its children.
- #add_child(segment) ⇒ Object
-
#children ⇒ Object
Lazy initialization of children to avoid bloating leaf segments.
-
#initialize(type, name, start_time = nil) ⇒ Segment
constructor
A new instance of Segment.
- #record_stop_time ⇒ Object
- #start ⇒ Object
- #total_call_time ⇒ Object
- #total_exclusive_time ⇒ Object
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
#data ⇒ Object
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 |
#name ⇒ Object (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_time ⇒ Object (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_time ⇒ Object (readonly)
Start and stop of this segment
12 13 14 |
# File 'lib/heimdall_apm/segment.rb', line 12 def stop_time @stop_time end |
#type ⇒ Object (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 |
#children ⇒ Object
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_time ⇒ Object
49 50 51 |
# File 'lib/heimdall_apm/segment.rb', line 49 def record_stop_time @stop_time = Process.clock_gettime(Process::CLOCK_REALTIME) end |
#start ⇒ Object
25 26 27 |
# File 'lib/heimdall_apm/segment.rb', line 25 def start @start_time = Process.clock_gettime(Process::CLOCK_REALTIME) end |
#total_call_time ⇒ Object
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_time ⇒ Object
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 |