Skip to content

Instantly share code, notes, and snippets.

@tmm1
Created March 22, 2011 02:26
Show Gist options
  • Save tmm1/880651 to your computer and use it in GitHub Desktop.
Save tmm1/880651 to your computer and use it in GitHub Desktop.
class Numeric
def commify
to_s.reverse.gsub(/(\d\d\d)(?=\d)(?!\d*\.)/,'\1,').reverse
end
end
require 'rubygems'
require 'yajl'
tests = []
ARGF.each_line do |line|
tests << Yajl.load(line, :symbolize_keys=>true)
end
tests.sort_by{ |t| -t[:time] }.each do |o|
puts o[:rails][:controller]
o[:time] /= 1000.0
puts " #{o[:time]} seconds"
print " #{o[:tracers][:gc][:calls]} GC calls, #{o[:tracers][:gc][:time]/1000.0}s in GC"
if o[:tracers][:gc][:stime] > 0
puts " (#{o[:tracers][:gc][:utime]/1000.0}s user, #{o[:tracers][:gc][:stime]/1000.0}s system)"
else
puts
end
puts " #{o[:tracers][:objects][:created].commify} objects created"
puts " #{o[:tracers][:mysql][:queries].commify} database queries, #{o[:tracers][:mysql][:time]/1000.0}s in database" if o[:tracers][:mysql][:queries]
stime = o[:tracers][:resources][:stime]
utime = o[:tracers][:resources][:utime]
cpu_time = utime+stime
puts " #{cpu_time/1000.0}s on CPU (#{utime/1000.0}s user, #{stime/1000.0}s system)"
io_time = o[:tracers][:fd].inject(0){ |s, (k,v)| s += v[:time] if v[:time]; s }
puts " #{io_time/1000.0}s in IO"
if io_time > 0
o[:tracers][:fd].select{ |k,v| v[:time] }.sort_by{ |k,v| -v[:time] }.map do |k,v|
puts " #{v[:time]/1000.0}s in #{k}()"
end
end
puts
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment