class SystemMetrics::NestedEvent

Attributes

action[R]
category[R]

Public Class Methods

arrange(events, options={}) click to toggle source
# 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
new(*args) click to toggle source
Calls superclass method
# File lib/system_metrics/nested_event.rb, line 21
def initialize(*args)
  super
  @action, @category = name.split('.')
end

Public Instance Methods

child_of?(event) click to toggle source
# File lib/system_metrics/nested_event.rb, line 47
def child_of?(event)
  event.parent_of?(self)
end
children() click to toggle source
# File lib/system_metrics/nested_event.rb, line 38
def children
  @children ||= []
end
ended_at() click to toggle source
# File lib/system_metrics/nested_event.rb, line 34
def ended_at
  self.end
end
exclusive_duration() click to toggle source
# 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) click to toggle source
# 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_at() click to toggle source
# File lib/system_metrics/nested_event.rb, line 30
def started_at
  self.time
end
to_hash() click to toggle source
# 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