class Fog::Storage::Softlayer::Memory::Analyzer
Attributes
result[R]
roots[RW]
Public Instance Methods
analyze()
click to toggle source
# File lib/fog/softlayer/storage.rb, line 245 def analyze @result = MemoryInfo.new roots, 0, 0, 0 @objs = {} queue = roots.dup until queue.empty? obj = queue.shift case obj when IO visit(obj) when String visit(obj) { @result.bytes += obj.size } when Fixnum @result.bytes += FIXNUM_SIZE when Array visit(obj) do @result.bytes += obj.size * REF_SIZE queue.concat(obj) end when Hash visit(obj) do @result.bytes += obj.size * REF_SIZE * 2 obj.each {|k,v| queue.push(k).push(v)} end when Enumerable visit(obj) do obj.each do |o| @result.bytes += REF_SIZE queue.push(o) end end else visit(obj) do obj.instance_variables.each do |var| @result.bytes += REF_SIZE queue.push(obj.instance_variable_get(var)) end end end end @result end
Private Instance Methods
visit(obj) { |obj| ... }
click to toggle source
# File lib/fog/softlayer/storage.rb, line 292 def visit(obj) id = obj.object_id if @objs.has_key? id @result.loops += 1 false else @objs[id] = true @result.bytes += OBJ_OVERHEAD @result.objects += 1 yield obj if block_given? true end end