プロジェクト

全般

プロフィール

最適化 #564 » memory_tracker.rb

Takuma Nakajima, 2013-02-14 17:04

 
1
Plugin.create :memory_tracker do
2

    
3
  def memory_profile
4
    GC.start
5
    str = Time.now.strftime("%Y%m%d%H%M%S").to_s
6
    str += "\t" + ObjectSpace.each_object(Mutex).count.to_s
7
    str += "\t" + ObjectSpace.each_object(User).count.to_s
8
    str += "\t" + ObjectSpace.each_object(Time).count.to_s
9
    str += "\t" + ObjectSpace.each_object(Data).count.to_s
10
    str += "\t" + ObjectSpace.each_object(RubyVM::InstructionSequence).count.to_s
11
    str += "\t" + ObjectSpace.each_object(RubyVM::Env).count.to_s
12
    str += "\t" + ObjectSpace.each_object(Proc).count.to_s
13
    str += "\t" + ObjectSpace.each_object(Hash).count.to_s
14
    str += "\t" + ObjectSpace.each_object(Array).count.to_s
15
    str += "\t" + ObjectSpace.each_object(String).count.to_s
16
    str
17
  end
18

    
19
  def update_profile
20
    f = open("/dev/shm/mikutter_objs.log", "a")
21
    f.write(memory_profile + "\n")
22
    f.close
23
  end
24

    
25
  Thread.new {
26
    loop do
27
      update_profile
28
      sleep 30
29
    end
30
  }
31

    
32
end
33

    
(2-2/3)