Class: ActiveSupport::Notifications::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/active_support/notifications/instrumenter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, start, ending, transaction_id, payload) ⇒ Event

Returns a new instance of Event.



56
57
58
59
60
61
62
63
64
# File 'lib/active_support/notifications/instrumenter.rb', line 56

def initialize(name, start, ending, transaction_id, payload)
  @name           = name
  @payload        = payload.dup
  @time           = start
  @transaction_id = transaction_id
  @end            = ending
  @children       = []
  @duration       = nil
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



53
54
55
# File 'lib/active_support/notifications/instrumenter.rb', line 53

def children
  @children
end

#endObject

Returns the value of attribute end.



54
55
56
# File 'lib/active_support/notifications/instrumenter.rb', line 54

def end
  @end
end

#nameObject (readonly)

Returns the value of attribute name.



53
54
55
# File 'lib/active_support/notifications/instrumenter.rb', line 53

def name
  @name
end

#payloadObject (readonly)

Returns the value of attribute payload.



53
54
55
# File 'lib/active_support/notifications/instrumenter.rb', line 53

def payload
  @payload
end

#timeObject (readonly)

Returns the value of attribute time.



53
54
55
# File 'lib/active_support/notifications/instrumenter.rb', line 53

def time
  @time
end

#transaction_idObject (readonly)

Returns the value of attribute transaction_id.



53
54
55
# File 'lib/active_support/notifications/instrumenter.rb', line 53

def transaction_id
  @transaction_id
end

Instance Method Details

#<<(event) ⇒ Object



82
83
84
# File 'lib/active_support/notifications/instrumenter.rb', line 82

def <<(event)
  @children << event
end

#durationObject

Returns the difference in milliseconds between when the execution of the event started and when it ended.

ActiveSupport::Notifications.subscribe('wait') do |*args|
  @event = ActiveSupport::Notifications::Event.new(*args)
end

ActiveSupport::Notifications.instrument('wait') do
  sleep 1
end

@event.duration # => 1000.138


78
79
80
# File 'lib/active_support/notifications/instrumenter.rb', line 78

def duration
  @duration ||= 1000.0 * (self.end - time)
end

#parent_of?(event) ⇒ Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/active_support/notifications/instrumenter.rb', line 86

def parent_of?(event)
  @children.include? event
end