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.



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

#framesObject (readonly)

Returns the value of attribute frames.



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

def frames
  @frames
end

#samplesObject (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_typeObject



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_frameObject



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_treeObject



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

#calltreeObject



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