Plugin.create :memory_tracker do

  def memory_profile
    GC.start
    str = Time.now.strftime("%Y%m%d%H%M%S").to_s
    str += "\t" + ObjectSpace.each_object(Mutex).count.to_s
    str += "\t" + ObjectSpace.each_object(User).count.to_s
    str += "\t" + ObjectSpace.each_object(Time).count.to_s
    str += "\t" + ObjectSpace.each_object(Data).count.to_s
    str += "\t" + ObjectSpace.each_object(RubyVM::InstructionSequence).count.to_s
    str += "\t" + ObjectSpace.each_object(RubyVM::Env).count.to_s
    str += "\t" + ObjectSpace.each_object(Proc).count.to_s
    str += "\t" + ObjectSpace.each_object(Hash).count.to_s
    str += "\t" + ObjectSpace.each_object(Array).count.to_s
    str += "\t" + ObjectSpace.each_object(String).count.to_s
    str
  end

  def update_profile
    f = open("/dev/shm/mikutter_objs.log", "a")
    f.write(memory_profile + "\n")
    f.close
  end

  Thread.new {
    loop do
      update_profile
      sleep 30
    end
  }

end

