class Flows::Plugin::Profiler::Report::Tree
Tree
report. Merges similar calls, saves execution structure (who called whom).
@example
Flows::Plugin::Profiler.profile(:tree) do # some code here end puts Flows::Plugin::Profiler.last_report
Public Instance Methods
add(*)
click to toggle source
Calls superclass method
Flows::Plugin::Profiler::Report#add
# File lib/flows/plugin/profiler/report/tree.rb, line 49 def add(*) forget_memoized_values super end
to_a()
click to toggle source
Returns tree report as Ruby data structs.
@return [Array<Hash>] tree report.
@example
[ { subject: 'MyClass#call', count: 2, total_ms: 100.0, total_self_ms: 80.0, total_self_percentage: 80.0, avg_ms: 50.0, avg_self_ms: 40.0, nested: [ { subject: 'MyClass#another_method', count: 1, total_ms: 20.0, total_self_ms: 20.0, total_self_percentage: 20.0, avg_ms: 20.0, avg_self_ms: 20.0, nested: [] } ] } ]
# File lib/flows/plugin/profiler/report/tree.rb, line 45 def to_a root_calculated_node.children.map { |node| node.to_h(root_calculated_node) } end
to_s()
click to toggle source
# File lib/flows/plugin/profiler/report/tree.rb, line 54 def to_s root_calculated_node.children.map { |node| node.to_s(root_calculated_node) }.join end
Private Instance Methods
forget_memoized_values()
click to toggle source
# File lib/flows/plugin/profiler/report/tree.rb, line 60 def forget_memoized_values @root_node = nil @root_calculated_node = nil end
process_finish_event(node_path, current_node, event)
click to toggle source
:reek: UtilityFunction :reek:FeatureEnvy
# File lib/flows/plugin/profiler/report/tree.rb, line 88 def process_finish_event(node_path, current_node, event) raise 'Invalid profiling events detected' if event.subject != current_node.subject current_node.register_execution(event.data) node_path.pop end
process_start_event(node_path, current_node, event)
click to toggle source
:reek: UtilityFunction
# File lib/flows/plugin/profiler/report/tree.rb, line 83 def process_start_event(node_path, current_node, event) node_path << current_node[event.subject] end
root_calculated_node()
click to toggle source
# File lib/flows/plugin/profiler/report/tree.rb, line 65 def root_calculated_node @root_calculated_node ||= CalculatedNode.new(root_node) end
root_node()
click to toggle source
# File lib/flows/plugin/profiler/report/tree.rb, line 69 def root_node @root_node ||= Node.new(subject: :ROOT).tap do |root_node| events.each_with_object([root_node]) do |event, node_path| current_node = node_path.last case event when StartEvent then process_start_event(node_path, current_node, event) when FinishEvent then process_finish_event(node_path, current_node, event) end end end end