class ObjectSpace::AllocationSampler::Display::Stack
Attributes
max_depth[R]
Public Class Methods
new(output: $stdout)
click to toggle source
Calls superclass method
# File lib/allocation_sampler.rb, line 141 def initialize output: $stdout super(output) end
Public Instance Methods
show(frames)
click to toggle source
# File lib/allocation_sampler.rb, line 145 def show frames max_width = max_width(frames, 0, {}) display(frames, 0, frames.total_samples, [], {}, max_width) end
Private Instance Methods
display(frame, depth, total_samples, last_stack, seen, max_width)
click to toggle source
# File lib/allocation_sampler.rb, line 169 def display frame, depth, total_samples, last_stack, seen, max_width seen[frame] = true buffer = max_width - ((depth * 4) + frame.name.length) self_samples = frame.samples last_stack.each_with_index do |last, i| if i == last_stack.length - 1 if last printf "`-- " else printf "|-- " end else if last printf " " else printf "| " end end end printf frame.name printf " " * buffer printf "% d % 8s", self_samples, "(%2.1f%%)" % (self_samples*100.0/total_samples) puts children = (frame.children || []).sort_by { |ie| -ie.total_samples }.reject { |f| seen[f] } children.each_with_index do |child, i| s = last_stack + [i == children.length - 1] display child, depth + 1, total_samples, s, seen, max_width end end
max_width(frame, depth, seen)
click to toggle source
# File lib/allocation_sampler.rb, line 152 def max_width frame, depth, seen if seen.key? frame return 0 end seen[frame] = true my_length = (depth * 4) + frame.name.length frame.children.each do |caller| child_len = max_width caller, depth + 1, seen my_length = child_len if my_length < child_len end my_length end