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.
214 215 216 |
# File 'lib/fog/softlayer/storage.rb', line 214 def result @result end |
#roots ⇒ Object
Returns the value of attribute roots.
213 214 215 |
# File 'lib/fog/softlayer/storage.rb', line 213 def roots @roots end |
Instance Method Details
#analyze ⇒ Object
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 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 |
# File 'lib/fog/softlayer/storage.rb', line 216 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 |