Class: Benchin::Wrap::Report::Node Private

Inherits:
Object
  • Object
show all
Defined in:
lib/benchin/wrap/report/node.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Direct Known Subclasses

Virtual

Defined Under Namespace

Classes: Virtual

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Node

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Node.


11
12
13
14
15
16
17
# File 'lib/benchin/wrap/report/node.rb', line 11

def initialize(name)
  @name = name

  @calls = 0
  @total_seconds = 0.0
  @nested = {}
end

Instance Attribute Details

#callsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


7
8
9
# File 'lib/benchin/wrap/report/node.rb', line 7

def calls
  @calls
end

#nameObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


6
7
8
# File 'lib/benchin/wrap/report/node.rb', line 6

def name
  @name
end

#nestedObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


9
10
11
# File 'lib/benchin/wrap/report/node.rb', line 9

def nested
  @nested
end

#total_secondsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


8
9
10
# File 'lib/benchin/wrap/report/node.rb', line 8

def total_seconds
  @total_seconds
end

Instance Method Details

#add_call(seconds) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


19
20
21
22
23
# File 'lib/benchin/wrap/report/node.rb', line 19

def add_call(seconds)
  @child_seconds = nil
  @calls += 1
  @total_seconds += seconds
end

#child_secondsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


40
41
42
43
44
# File 'lib/benchin/wrap/report/node.rb', line 40

def child_seconds
  child_nodes = nested.values

  @child_seconds ||= child_nodes.map(&:total_seconds).sum.to_f
end

#self_secondsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


36
37
38
# File 'lib/benchin/wrap/report/node.rb', line 36

def self_seconds
  total_seconds - child_seconds
end

#to_hObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


25
26
27
28
29
30
31
32
33
34
# File 'lib/benchin/wrap/report/node.rb', line 25

def to_h
  {
    name: name,
    calls: calls,
    total_seconds: total_seconds,
    self_seconds: self_seconds,
    child_seconds: child_seconds,
    nested: nested.values.map(&:to_h)
  }
end