Module: MemoryProfile
- Defined in:
- lib/pmsrb/memory_profile.rb
Constant Summary collapse
- LOG_FILE =
"/tmp/memory_profile.log"
Class Method Summary collapse
Class Method Details
.report ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/pmsrb/memory_profile.rb', line 70 def MemoryProfile::report Dir.chdir "/tmp" ObjectSpace::garbage_collect sleep 10 # Give the GC thread a chance all = [] ObjectSpace.each_object do |obj| next if obj.object_id == all.object_id all << obj end tally = Hash.new(0) max_obj = nil max_count = 0 all.each do |obj| count = obj.memory_profile_size_of_object if max_count < count max_obj = obj max_count = count end tally[obj.class]+=count end open( LOG_FILE, 'a') do |outf| outf.puts '+'*70 tally.keys.sort{|a,b| if tally[a] == tally[b] a.to_s <=> b.to_s else -1*(tally[a]<=>tally[b]) end }.each do |klass| outf.puts "#{klass}\t#{tally[klass]}" end outf.puts '-'*70 outf.puts "Max obj was #{max_obj.class} at #{max_count}" outf.puts "Maximum object is..." outf.puts max_obj.memory_profile_inspect end end |
.simple_count ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/pmsrb/memory_profile.rb', line 113 def MemoryProfile::simple_count Dir.chdir "/tmp" ObjectSpace::garbage_collect sleep 10 # Give the GC thread a chance tally = Hash.new(0) ObjectSpace.each_object do |obj| next if obj.object_id == tally.object_id tally[obj.class]+=1 end open( LOG_FILE, 'a') do |outf| outf.puts '='*70 outf.puts "MemoryProfile report for #{$0}" outf.puts `cat /proc/#{Process.pid}/status` tally.keys.sort{|a,b| if tally[a] == tally[b] a.to_s <=> b.to_s else -1*(tally[a]<=>tally[b]) end }.each do |klass| outf.puts "#{klass}\t#{tally[klass]}" end end end |