class DerailedBenchmarks::RequireTree
Constants
- REQUIRED_BY
Attributes
cost[W]
name[R]
parent[RW]
Public Class Methods
new(name)
click to toggle source
# File lib/derailed_benchmarks/require_tree.rb, line 13 def initialize(name) @name = name @children = {} @cost = 0 end
reset!()
click to toggle source
# File lib/derailed_benchmarks/require_tree.rb, line 19 def self.reset! REQUIRED_BY.clear if defined?(Kernel::REQUIRE_STACK) Kernel::REQUIRE_STACK.clear Kernel::REQUIRE_STACK.push(TOP_REQUIRE) end end
Public Instance Methods
<<(tree)
click to toggle source
# File lib/derailed_benchmarks/require_tree.rb, line 28 def <<(tree) @children[tree.name.to_s] = tree tree.parent = self (REQUIRED_BY[tree.name.to_s] ||= []) << self.name end
[](name)
click to toggle source
# File lib/derailed_benchmarks/require_tree.rb, line 34 def [](name) @children[name.to_s] end
children()
click to toggle source
Returns array of child nodes
# File lib/derailed_benchmarks/require_tree.rb, line 39 def children @children.values end
cost()
click to toggle source
# File lib/derailed_benchmarks/require_tree.rb, line 43 def cost @cost || 0 end
print_sorted_children(level = 0, out = STDOUT)
click to toggle source
Recursively prints all child nodes
# File lib/derailed_benchmarks/require_tree.rb, line 66 def print_sorted_children(level = 0, out = STDOUT) return if cost < ENV['CUT_OFF'].to_f out.puts " " * level + self.to_string level += 1 sorted_children.each do |child| child.print_sorted_children(level, out) end end
sorted_children()
click to toggle source
Returns sorted array of child nodes from Largest to Smallest
# File lib/derailed_benchmarks/require_tree.rb, line 48 def sorted_children children.sort { |c1, c2| c2.cost <=> c1.cost } end
to_string()
click to toggle source
# File lib/derailed_benchmarks/require_tree.rb, line 52 def to_string str = String.new("#{name}: #{cost.round(4)} MiB") if parent && REQUIRED_BY[self.name.to_s] names = REQUIRED_BY[self.name.to_s].uniq - [parent.name.to_s] if names.any? str << " (Also required by: #{ names.first(2).join(", ") }" str << ", and #{names.count - 2} others" if names.count > 3 str << ")" end end str end