Class: Fog::Storage::Softlayer::Memory::Analyzer
- Inherits:
-
Object
- Object
- Fog::Storage::Softlayer::Memory::Analyzer
- Defined in:
- lib/fog/softlayer/storage.rb
Instance Attribute Summary collapse
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#roots ⇒ Object
Returns the value of attribute roots.
Instance Method Summary collapse
Instance Attribute Details
#result ⇒ Object (readonly)
Returns the value of attribute result.
243 244 245 |
# File 'lib/fog/softlayer/storage.rb', line 243 def result @result end |
#roots ⇒ Object
Returns the value of attribute roots.
242 243 244 |
# File 'lib/fog/softlayer/storage.rb', line 242 def roots @roots end |
Instance Method Details
#analyze ⇒ Object
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 277 278 279 280 281 282 283 284 285 286 287 288 289 |
# 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 |