Class: ObjectSpace::AllocationSampler::Result
- Inherits:
-
Object
- Object
- ObjectSpace::AllocationSampler::Result
- Defined in:
- lib/allocation_sampler.rb
Defined Under Namespace
Classes: Frame
Instance Attribute Summary collapse
-
#frames ⇒ Object
readonly
Returns the value of attribute frames.
-
#samples ⇒ Object
readonly
Returns the value of attribute samples.
Instance Method Summary collapse
- #allocations_by_type ⇒ Object
- #allocations_with_top_frame ⇒ Object
- #by_type_with_call_tree ⇒ Object
- #calltree ⇒ Object
-
#initialize(samples, frames) ⇒ Result
constructor
A new instance of Result.
Constructor Details
#initialize(samples, frames) ⇒ Result
Returns a new instance of Result.
69 70 71 72 |
# File 'lib/allocation_sampler.rb', line 69 def initialize samples, frames @samples = samples.sort_by! { |s| s[1] }.reverse! @frames = frames end |
Instance Attribute Details
#frames ⇒ Object (readonly)
Returns the value of attribute frames.
67 68 69 |
# File 'lib/allocation_sampler.rb', line 67 def frames @frames end |
#samples ⇒ Object (readonly)
Returns the value of attribute samples.
67 68 69 |
# File 'lib/allocation_sampler.rb', line 67 def samples @samples end |
Instance Method Details
#allocations_by_type ⇒ Object
74 75 76 77 78 |
# File 'lib/allocation_sampler.rb', line 74 def allocations_by_type @samples.each_with_object(Hash.new(0)) do |(type, count, _), h| h[type] += count end end |
#allocations_with_top_frame ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/allocation_sampler.rb', line 80 def allocations_with_top_frame @samples.each_with_object({}) do |(type, count, stack), h| top_frame_id, line = stack.first frame = @frames[top_frame_id] ((h[type] ||= {})[frame.path] ||= {})[line] = count end end |
#by_type_with_call_tree ⇒ Object
95 96 97 98 99 100 101 102 103 |
# File 'lib/allocation_sampler.rb', line 95 def by_type_with_call_tree types_with_stacks = @samples.group_by(&:first) types_with_stacks.transform_values do |stacks| frame_delegates = {} stacks.map { |_, count, stack| build_tree(stack, count, frame_delegates) }.uniq.first end end |
#calltree ⇒ Object
88 89 90 91 92 93 |
# File 'lib/allocation_sampler.rb', line 88 def calltree frame_delegates = {} @samples.map { |type, count, stack| build_tree(stack, count, frame_delegates) }.uniq.first end |