Class: Flows::Plugin::Profiler::Report::Flat::MethodReport Private

Inherits:
Object
  • Object
show all
Defined in:
lib/flows/plugin/profiler/report/flat/method_report.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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root_node, *calculated_nodes) ⇒ MethodReport

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

Since:

  • 0.4.0



10
11
12
13
14
15
16
# File 'lib/flows/plugin/profiler/report/flat/method_report.rb', line 10

def initialize(root_node, *calculated_nodes)
  @root_node = root_node
  @calculated_nodes = calculated_nodes

  raise 'no single node provided' if calculated_nodes.empty?
  raise 'calculated_nodes must be about the same subject' unless nodes_have_same_subject
end

Instance Attribute Details

#calculated_nodesObject (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



8
9
10
# File 'lib/flows/plugin/profiler/report/flat/method_report.rb', line 8

def calculated_nodes
  @calculated_nodes
end

#root_nodeObject (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



8
9
10
# File 'lib/flows/plugin/profiler/report/flat/method_report.rb', line 8

def root_node
  @root_node
end

Instance Method Details

#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



37
38
39
# File 'lib/flows/plugin/profiler/report/flat/method_report.rb', line 37

def avg_self_ms
  @avg_self_ms ||= total_self_ms / count
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



22
23
24
# File 'lib/flows/plugin/profiler/report/flat/method_report.rb', line 22

def count
  @count ||= calculated_nodes.map(&:count).sum
end

#direct_subcallsObject

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



41
42
43
44
45
# File 'lib/flows/plugin/profiler/report/flat/method_report.rb', line 41

def direct_subcalls
  @direct_subcalls ||= calculated_nodes
                       .flat_map { |node| node.children.map(&:subject) }
                       .uniq
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



18
19
20
# File 'lib/flows/plugin/profiler/report/flat/method_report.rb', line 18

def subject
  @subject ||= calculated_nodes.first.subject
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.

Since:

  • 0.4.0



47
48
49
50
51
52
53
54
55
56
# File 'lib/flows/plugin/profiler/report/flat/method_report.rb', line 47

def to_h
  @to_h ||= {
    subject: subject,
    count: count,
    total_self_ms: total_self_ms,
    total_self_percentage: total_self_percentage,
    avg_self_ms: avg_self_ms,
    direct_subcalls: direct_subcalls
  }
end

#to_sObject

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



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

def to_s
  [
    '',
    "- #{subject} -",
    "called:                      #{count} time(s)",
    "total self execution time:   #{total_self_ms.truncate(2)}ms",
    "total self percentage:       #{total_self_percentage.truncate(2)}%",
    "average self execution time: #{avg_self_ms.truncate(2)}ms",
    "direct subcalls:             #{direct_subcalls.join(', ')}"
  ]
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



26
27
28
# File 'lib/flows/plugin/profiler/report/flat/method_report.rb', line 26

def total_self_ms
  @total_self_ms ||= calculated_nodes.map(&:total_self_ms).sort.sum
end

#total_self_percentageObject

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



30
31
32
33
34
35
# File 'lib/flows/plugin/profiler/report/flat/method_report.rb', line 30

def total_self_percentage
  @total_self_percentage ||= calculated_nodes
                             .map { |node| node.total_self_percentage(root_node) }
                             .sort
                             .sum
end