Module: Smith::ObjectCount

Included in:
Agent
Defined in:
lib/smith/object_count.rb

Instance Method Summary collapse

Instance Method Details

#object_count(threshold = 10) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/smith/object_count.rb', line 5

def object_count(threshold=10)
  objects = ObjectSpace.each_object.inject(Hash.new(0)) do |a,o|
    a.tap {|acc| acc[o.class.to_s] += 1}
  end.sort {|(_,a),(_,b)| b <=> a}

  max_table_width = objects.first[1].to_s.length + 3

  objects.inject([]) do |a,(clazz,count)|
    a.tap {|acc| acc << "%-#{max_table_width}s%s" % [count,clazz] if count > threshold}
  end
end