Skip to content

Instantly share code, notes, and snippets.

@wilson
Created April 9, 2009 13:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wilson/92453 to your computer and use it in GitHub Desktop.
Save wilson/92453 to your computer and use it in GitHub Desktop.
mongrel_object_track.conf
# Original code by Robert Klemme
OUT=open("objects.log","w")
OUT.sync = true
$last_stat = nil
$run_count = 0
OUT.puts "run,classname,last,count,delta"
class ObjectTrackFilter < Mongrel::HttpHandler
def process(request,response)
GC.start # force a collection
stats = Hash.new(0)
ObjectSpace.each_object {|o| stats[o.class] += 1}
stats.sort {|(k1,v1),(k2,v2)| v2 <=> v1}.each do |k,v|
if $last_stat
delta = v - $last_stat[k]
if v > 10 and delta != 0
OUT.printf "%d,%s,%d,%d,%d\n", $run_count, k, $last_stat[k], v, delta
end
end
end
$run_count += 1
$last_stat = stats
end
end
# add :in_front => true to track all requests
uri "/", :handler => ObjectTrackFilter.new, :in_front => true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment