require 'ruby-prof' module RubyProfiler FLAT = 1 GRAPH = 2 GRAPH_HTML = 3 def start_profile RubyProf.start end def write_profile(result, min=5, type=FLAT) path = request.request_uri.gsub(/http:\/\/host_with_port/, '') path.gsub!(/\//, '.') path[0] = '/' path = "#{RAILS_ROOT}/tmp/ruby-prof#{path}.#{Time.new.strftime('%Y%m%d%H%M%S')}" case type when GRAPH printer = RubyProf::GraphPrinter.new(result) path << '.graph' when GRAPH_HTML printer = RubyProf::GraphHtmlPrinter.new(result) path << '.graph.html' else printer = RubyProf::FlatPrinter.new(result) path << '.flat' end printer.print(File.new(path, 'w'), min) end end