Module: ObjectTracker

Defined in:
lib/mongrel/debug.rb

Class Method Summary collapse

Class Method Details

.configureObject



48
49
50
51
52
53
54
# File 'lib/mongrel/debug.rb', line 48

def ObjectTracker.configure
  @active_objects = Set.new

  ObjectSpace.each_object do |obj|
    @active_objects << obj.object_id
  end
end

.sampleObject



65
66
67
68
69
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
# File 'lib/mongrel/debug.rb', line 65

def ObjectTracker.sample
  Class.stopit do
    ospace = Set.new
    counts = {}
    
    # Strings can't be tracked easily and are so numerous that they drown out all else
    # so we just ignore them in the counts.
    ObjectSpace.each_object do |obj|
      if not obj.kind_of? String
        ospace << obj.object_id
        counts[obj.class] ||= 0
        counts[obj.class] += 1
      end
    end
    
    dead_objects = @active_objects - ospace
    new_objects = ospace - @active_objects
    live_objects = ospace & @active_objects
    
    MongrelDbg::trace(:objects, "COUNTS: #{dead_objects.length},#{new_objects.length},#{live_objects.length}")
    
    if MongrelDbg::tracing? :objects
      top_20 = counts.sort{|a,b| b[1] <=> a[1]}[0..20]
      MongrelDbg::trace(:objects,"TOP 20: #{top_20.inspect}")
    end
    
    @active_objects = live_objects + new_objects

    [@active_objects, top_20]
  end
end

.startObject



57
58
59
# File 'lib/mongrel/debug.rb', line 57

def ObjectTracker.start
  @live_object_tracking = true
end

.stopObject



61
62
63
# File 'lib/mongrel/debug.rb', line 61

def ObjectTracker.stop
  @live_object_tracking = false
end