Class: ObjectSpace::AllocationSampler::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/allocation_sampler.rb

Defined Under Namespace

Classes: Frame

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(samples, frames) ⇒ Result

Returns a new instance of Result.



70
71
72
73
# File 'lib/allocation_sampler.rb', line 70

def initialize samples, frames
  @samples = samples.sort_by! { |s| s[1] }.reverse!
  @frames = frames
end

Instance Attribute Details

#framesObject (readonly)

Returns the value of attribute frames.



68
69
70
# File 'lib/allocation_sampler.rb', line 68

def frames
  @frames
end

#samplesObject (readonly)

Returns the value of attribute samples.



68
69
70
# File 'lib/allocation_sampler.rb', line 68

def samples
  @samples
end

Instance Method Details

#allocations_by_typeObject



75
76
77
78
79
# File 'lib/allocation_sampler.rb', line 75

def allocations_by_type
  @samples.each_with_object(Hash.new(0)) do |(type, count, _), h|
    h[type] += count
  end
end

#allocations_with_top_frameObject



81
82
83
84
85
86
87
# File 'lib/allocation_sampler.rb', line 81

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_treeObject



96
97
98
99
100
101
102
103
104
# File 'lib/allocation_sampler.rb', line 96

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

#calltreeObject



89
90
91
92
93
94
# File 'lib/allocation_sampler.rb', line 89

def calltree
  frame_delegates = {}
  @samples.map { |type, count, stack|
    build_tree(stack, count, frame_delegates)
  }.uniq.first
end