Module: ObjectTracker

Defined in:
lib/mongrel/debug.rb

Class Method Summary collapse

Class Method Details

.configureObject



65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/mongrel/debug.rb', line 65

def ObjectTracker.configure
  @active_objects = Set.new

  ObjectSpace.each_object do |obj|
    begin
      # believe it or not, some idiots actually alter the object_id method
      @active_objects << obj.object_id
    rescue Object
      # skip this one, he's an idiot
    end
  end
end

.sampleObject



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
# File 'lib/mongrel/debug.rb', line 78

def ObjectTracker.sample
  ospace = Set.new
  counts = {}
  
  ObjectSpace.each_object do |obj|
    begin
      ospace << obj.object_id
      counts[obj.class] ||= 0
      counts[obj.class] += 1
    rescue Object
      # skip since object_id can magically get parameters
    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