8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'app/models/effective/profiler.rb', line 8
def self.allocations(sourcefiles: ['effective_'], &block)
raise('please install the allocation_stats gem') unless defined?(AllocationStats)
retval = nil
stats = AllocationStats.trace { retval = yield(block) }
allocations = stats.allocations.to_a
if sourcefiles.present?
sourcefiles = Array(sourcefiles)
allocations = allocations.select! { |allocation| sourcefiles.any? { |str| allocation.sourcefile.include?(str) } }
end
allocations = allocations.sort_by { |allocation| allocation.memsize }
puts AllocationStats::AllocationsProxy.new(allocations).to_text
puts "Total allocations: #{allocations.length}. Total size: #{allocations.sum(&:memsize)}"
retval
end
|