Created
April 9, 2009 13:12
-
-
Save wilson/92453 to your computer and use it in GitHub Desktop.
mongrel_object_track.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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