Class: Fog::Storage::Softlayer::Memory::Analyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/softlayer/storage.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#resultObject (readonly)

Returns the value of attribute result.



230
231
232
# File 'lib/fog/softlayer/storage.rb', line 230

def result
  @result
end

#rootsObject

Returns the value of attribute roots.



229
230
231
# File 'lib/fog/softlayer/storage.rb', line 229

def roots
  @roots
end

Instance Method Details

#analyzeObject



232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# File 'lib/fog/softlayer/storage.rb', line 232

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