Class: SystemMetrics::NestedEvent
- Inherits:
-
ActiveSupport::Notifications::Event
- Object
- ActiveSupport::Notifications::Event
- SystemMetrics::NestedEvent
- Defined in:
- lib/system_metrics/nested_event.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#category ⇒ Object
readonly
Returns the value of attribute category.
Class Method Summary collapse
Instance Method Summary collapse
- #child_of?(event) ⇒ Boolean
- #children ⇒ Object
- #ended_at ⇒ Object
- #exclusive_duration ⇒ Object
-
#initialize(*args) ⇒ NestedEvent
constructor
A new instance of NestedEvent.
- #parent_of?(event) ⇒ Boolean
- #started_at ⇒ Object
- #to_hash ⇒ Object
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
#action ⇒ Object (readonly)
Returns the value of attribute action.
5 6 7 |
# File 'lib/system_metrics/nested_event.rb', line 5 def action @action end |
#category ⇒ Object (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, ={}) events.sort! { |a, b| a.end <=> b.end } unless [: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
47 48 49 |
# File 'lib/system_metrics/nested_event.rb', line 47 def child_of?(event) event.parent_of?(self) end |
#children ⇒ Object
38 39 40 |
# File 'lib/system_metrics/nested_event.rb', line 38 def children @children ||= [] end |
#ended_at ⇒ Object
34 35 36 |
# File 'lib/system_metrics/nested_event.rb', line 34 def ended_at self.end end |
#exclusive_duration ⇒ Object
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
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_at ⇒ Object
30 31 32 |
# File 'lib/system_metrics/nested_event.rb', line 30 def started_at self.time end |
#to_hash ⇒ Object
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 |