Module: ObjectTracker

Defined in:
lib/mongrel/debug.rb

Class Method Summary collapse

Class Method Details

.configureObject



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

def ObjectTracker.configure
  @active_objects = Set.new

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

.sampleObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/mongrel/debug.rb', line 55

def ObjectTracker.sample
  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|
    ospace << obj.object_id
    counts[obj.class] ||= 0
    counts[obj.class] += 1
  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