Class: Flows::Plugin::Profiler::Report::Tree::CalculatedNode Private

Inherits:
Object
  • Object
show all
Defined in:
lib/flows/plugin/profiler/report/tree/calculated_node.rb

Overview

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.

Since:

  • 0.4.0

Constant Summary collapse

MICROSECONDS_IN_MILLISECOND =

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

Since:

  • 0.4.0

1000.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ CalculatedNode

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 CalculatedNode.

Since:

  • 0.4.0



12
13
14
15
16
17
18
# File 'lib/flows/plugin/profiler/report/tree/calculated_node.rb', line 12

def initialize(node)
  @node = node
  @children = node.children
                  .map { |child| self.class.new(child) }
                  .sort_by(&:total_ms)
                  .reverse
end

Instance Attribute Details

#childrenObject (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.

Since:

  • 0.4.0



10
11
12
# File 'lib/flows/plugin/profiler/report/tree/calculated_node.rb', line 10

def children
  @children
end

Instance Method Details

#avg_msObject

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.

Since:

  • 0.4.0



32
33
34
# File 'lib/flows/plugin/profiler/report/tree/calculated_node.rb', line 32

def avg_ms
  @avg_ms ||= total_ms / count
end

#avg_self_msObject

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.

Since:

  • 0.4.0



52
53
54
# File 'lib/flows/plugin/profiler/report/tree/calculated_node.rb', line 52

def avg_self_ms
  @avg_self_ms ||= total_self_ms / count
end

#children_msObject

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.

Since:

  • 0.4.0



36
37
38
# File 'lib/flows/plugin/profiler/report/tree/calculated_node.rb', line 36

def children_ms
  @children_ms ||= children.map(&:total_ms).sort.sum
end

#countObject

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.

Since:

  • 0.4.0



24
25
26
# File 'lib/flows/plugin/profiler/report/tree/calculated_node.rb', line 24

def count
  @count ||= @node.executions.count
end

#group_by_subjectObject

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.

:reek:DuplicateMethodCall :reek:NestedIterators

Since:

  • 0.4.0



76
77
78
79
80
81
82
83
84
85
# File 'lib/flows/plugin/profiler/report/tree/calculated_node.rb', line 76

def group_by_subject
  @group_by_subject ||= (
    [children.group_by(&:subject)] + children.map(&:group_by_subject)
  ).each_with_object({}) do |group, result|
    group.each do |subject, nodes|
      result[subject] ||= []
      result[subject] += nodes
    end
  end
end

#subjectObject

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.

Since:

  • 0.4.0



20
21
22
# File 'lib/flows/plugin/profiler/report/tree/calculated_node.rb', line 20

def subject
  @node.subject
end

#to_h(root_node = self) ⇒ 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.

rubocop:disable Metrics/MethodLength

Since:

  • 0.4.0



56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/flows/plugin/profiler/report/tree/calculated_node.rb', line 56

def to_h(root_node = self) # rubocop:disable Metrics/MethodLength
  @to_h ||= {
    subject: subject,
    count: count,
    total_ms: total_ms,
    total_percentage: total_percentage(root_node),
    total_self_ms: total_self_ms,
    total_self_percentage: total_self_percentage(root_node),
    avg_ms: avg_ms,
    avg_self_ms: avg_self_ms,
    nested: children.map { |node| node.to_h(root_node) }
  }
end

#to_s(root_node = self) ⇒ 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.

Since:

  • 0.4.0



70
71
72
# File 'lib/flows/plugin/profiler/report/tree/calculated_node.rb', line 70

def to_s(root_node = self)
  @to_s ||= (base_text_list(root_node) + childeren_text_list(root_node)).join("\n")
end

#total_msObject

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.

Since:

  • 0.4.0



28
29
30
# File 'lib/flows/plugin/profiler/report/tree/calculated_node.rb', line 28

def total_ms
  @total_ms ||= @node.executions.sort.sum / MICROSECONDS_IN_MILLISECOND
end

#total_percentage(root_node = self) ⇒ 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.

Since:

  • 0.4.0



48
49
50
# File 'lib/flows/plugin/profiler/report/tree/calculated_node.rb', line 48

def total_percentage(root_node = self)
  @total_percentage ||= total_ms / root_node.children_ms * 100.0
end

#total_self_msObject

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.

Since:

  • 0.4.0



40
41
42
# File 'lib/flows/plugin/profiler/report/tree/calculated_node.rb', line 40

def total_self_ms
  @total_self_ms ||= total_ms - children_ms
end

#total_self_percentage(root_node = self) ⇒ 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.

Since:

  • 0.4.0



44
45
46
# File 'lib/flows/plugin/profiler/report/tree/calculated_node.rb', line 44

def total_self_percentage(root_node = self)
  @total_self_percentage ||= total_self_ms / root_node.children_ms * 100.0
end