Class: SystemMetrics::NestedEvent

Inherits:
ActiveSupport::Notifications::Event
  • Object
show all
Defined in:
lib/system_metrics/nested_event.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ NestedEvent

Returns a new instance of NestedEvent.



21
22
23
24
# File 'lib/system_metrics/nested_event.rb', line 21

def initialize(*args)
  super
  @action, @category = name.split('.')
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



5
6
7
# File 'lib/system_metrics/nested_event.rb', line 5

def action
  @action
end

#categoryObject (readonly)

Returns the value of attribute category.



5
6
7
# File 'lib/system_metrics/nested_event.rb', line 5

def category
  @category
end

Class Method Details

.arrange(events, options = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/system_metrics/nested_event.rb', line 7

def self.arrange(events, options={})
  events.sort! { |a, b| a.end <=> b.end } unless options[:presort] == false

  while event = events.shift
    if parent = events.find { |n| n.parent_of?(event) }
      parent.children << event
    elsif events.empty?
      root = event
    end
  end

  root
end

Instance Method Details

#child_of?(event) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/system_metrics/nested_event.rb', line 47

def child_of?(event)
  event.parent_of?(self)
end

#childrenObject



38
39
40
# File 'lib/system_metrics/nested_event.rb', line 38

def children
  @children ||= []
end

#ended_atObject



34
35
36
# File 'lib/system_metrics/nested_event.rb', line 34

def ended_at
  self.end
end

#exclusive_durationObject



26
27
28
# File 'lib/system_metrics/nested_event.rb', line 26

def exclusive_duration
  @exclusive_duration ||= duration - children.inject(0.0) { |sum, child| sum + child.duration }
end

#parent_of?(event) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
45
# File 'lib/system_metrics/nested_event.rb', line 42

def parent_of?(event)
  start = (started_at - event.started_at) * 1000.0
  start <= 0 && (start + duration >= event.duration)
end

#started_atObject



30
31
32
# File 'lib/system_metrics/nested_event.rb', line 30

def started_at
  self.time
end

#to_hashObject



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/system_metrics/nested_event.rb', line 51

def to_hash
  {
    :name => name,
    :action => action,
    :category => category,
    :started_at => started_at,
    :transaction_id => transaction_id,
    :payload => payload,
    :duration => duration,
    :exclusive_duration => exclusive_duration
  }
end