Class: Object

Inherits:
BasicObject
Defined in:
lib/pmsrb/memory_profile.rb

Instance Method Summary collapse

Instance Method Details

#memory_profile_inspect(seen = {}, level = 0) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/pmsrb/memory_profile.rb', line 30

def memory_profile_inspect(seen={},level=0)
  return object_id.to_s if seen.has_key? object_id
  seen[object_id] = true
  result = ' '*level
  if kind_of? Hash
    result += "{\n" + ' '*level
    each_pair do |key,value|
      result += key.memory_profile_inspect(seen,level+1) + "=>\n"
      result += value.memory_profile_inspect(seen,level+2) + ",\n" + ' '*level
    end
    result += "}\n" + ' '*level
  elsif kind_of? Array
    result += "[\n" + ' '*level
    each do |element|
      result += element.memory_profile_inspect(seen,level+1) + ",\n" + ' '*level
    end
    result += "]\n" + ' '*level
  elsif kind_of? String
    result += self
  elsif kind_of? Numeric
    result += self.to_s
  elsif kind_of? Class
    result += to_s
  else
    result += "---"+self.class.to_s + "---\n" + ' '*level
  end


  instance_variables.each do |var|
    result += var + "=" + instance_variable_get(var.to_sym).memory_profile_inspect(seen,level+1) + "\n" + ' '*level
  end

  result
end

#memory_profile_size_of_object(seen = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/pmsrb/memory_profile.rb', line 6

def memory_profile_size_of_object(seen={})
  return 0 if seen.has_key? object_id
  seen[object_id] = true
  count = 1
  if kind_of? Hash
    each_pair do |key,value|
      count += key.memory_profile_size_of_object(seen)
      count += value.memory_profile_size_of_object(seen)
    end
  elsif kind_of? Array
    count += size
    each do |element|
      count += element.memory_profile_size_of_object(seen)
    end
  end

  count += instance_variables.size
  instance_variables.each do |var|
    count += instance_variable_get(var.to_sym).memory_profile_size_of_object(seen)
  end

  count
end