Code Profiling

Snippet to make a useful encapsulation in Rails apps.

config/initializers/rubyprof.rb:

class Prof def self.callstack(filename='callstack.html') result = nil profile = RubyProf.profile do result = yield end report = RubyProf::CallStackPrinter.new(profile) File.open(filename, 'w') do |file| report.print(file) end result end end