module MemoryProfiler::ObjectSpaceAnalyser

Public Class Methods

analyse(opt = {}) click to toggle source

Returns a hash mapping each Class to its usage.

If opt is true, the usage is estimated using Marshal.dump() for each instance; otherwise it is a simple instance count.

If opt is true, the analyser writes a text file containing every string in the Ruby ObjectSpace, at: /tmp/memory_profiler-<pid>-strings-<time>.log

Uses opt and opt , as per MemoryProfiler#start

    # File lib/memory-profiler.rb
278 def self.analyse(opt = {})
279   opt = MemoryProfiler::DEFAULTS.merge(opt)
280   marshal_size = !!(opt[:marshal_size] || opt[:marshall_size])
281   string_debug = !!opt[:string_debug]
282   ign  = opt[:ignore]
283   only = opt[:only]
284 
285   res = Hash.new(0)
286   str = [] if string_debug
287   ObjectSpace.each_object do |o|
288     if res[o.class] or ((only.empty? or only.any?{|y| o.is_a? y }) and ign.none?{|x| o.is_a? x })
289       res[o.class] += (marshal_size ? self.__sizeof(o) : 1)
290     end
291     str.push o.inspect if string_debug and o.class == String
292   end
293   if string_debug
294     self.__save str
295     str = nil
296   end
297   res
298 end