class Fable::Profiler::ProfileNode
Node used in the hierarchical tree of timings used by the Profiler
. Each node corresponds to a single line viewable in a UI-based representation.
Attributes
key[RW]
nodes[RW]
self_milliseconds[RW]
self_sample_count[RW]
total_milliseconds[RW]
total_sample_count[RW]
Public Class Methods
new(key="")
click to toggle source
# File lib/fable/profiler.rb, line 175 def initialize(key="") self.key = key self.total_sample_count = 0 self.total_milliseconds = 0 self.self_sample_count = 0 self.self_milliseconds = 0 end
pad(io, indent)
click to toggle source
# File lib/fable/profiler.rb, line 242 def self.pad(io, indent) io << " " * indent end
Public Instance Methods
add_sample(stack, duration)
click to toggle source
# File lib/fable/profiler.rb, line 183 def add_sample(stack, duration) add_sample_with_index(stack, -1, duration) end
add_sample_to_node(stack, stack_index, duration)
click to toggle source
# File lib/fable/profiler.rb, line 201 def add_sample_to_node(stack, stack_index, duration) node_key = stack[stack_index] nodes ||= {node_key => ProfileNode.new(node_key)} nodes[node_key].add_sample_with_index(stack, stack_index, duration) end
add_sample_with_index(stack, stack_index, duration)
click to toggle source
# File lib/fable/profiler.rb, line 187 def add_sample_with_index(stack, stack_index, duration) self.total_milliseconds += 1 self.total_milliseconds += duration if stack_index == (stack.size - 1) self.self_sample_count += 1 self.self_milliseconds += duration end if stack_index < stack.size add_sample_to_node(stack, stack_index + 1, duration) end end
has_children?()
click to toggle source
# File lib/fable/profiler.rb, line 171 def has_children? !nodes.nil? && nodes.size > 0 end
own_report()
click to toggle source
Generates a string giving timing information for this single node, including total milliseconds spent on the piece of ink, the time spent within itself (v.s. spent in children), as well as the number of samples (instruction steps) recorded for both too.
# File lib/fable/profiler.rb, line 224 def own_report report = StringIO.new report << "total #{Profiler.format_milliseconds(total_milliseconds)}" report << ", self #{Profiler.format_milliseconds(self_milliseconds)}" report << " (#{self_sample_count} self samples, #{total_sample_count} total)" report.rewind report.read end
print_hierarchy(io, indent)
click to toggle source
# File lib/fable/profiler.rb, line 208 def print_hierarchy(io, indent) self.class.pad(io, indent) io << "#{key}: #{own_report}\n" return if nodes.nil? nodes.sort_by{|k,v| v.total_milliseconds }.reverse.each do |key, node| node.print_hierarchy(io, indent + 1) end end
to_s()
click to toggle source
# File lib/fable/profiler.rb, line 235 def to_s report = StringIO.new print_hierarchy(report, 0) report.rewind report.read end