Skip to content

Instantly share code, notes, and snippets.

@pcantrell
Created November 29, 2011 17:42
Show Gist options
  • Save pcantrell/1405671 to your computer and use it in GitHub Desktop.
Save pcantrell/1405671 to your computer and use it in GitHub Desktop.
Get app profiling straight from the browser. Usage: (1) http://localhost:3000/rubyprof/start (2) Exercise slow requests (3) http://localhost:3000/rubyprof/stop (be patient) to get a report.
gem 'ruby-prof'
# ------ Debug ------
if Rails.env.development?
match 'rubyprof/:action', controller: 'ruby_prof'
end
class RubyProfController < ApplicationController
# before_filter :text_response
#
# def text_response
# response.content_type = 'text/plain'
# end
def start
if RubyProf.running?
render text: 'RubyProf is already running.'
else
RubyProf.start
render text: 'RubyProf started.'
end
end
def stop
if RubyProf.running?
prof = RubyProf.stop
report = StringIO.new
RubyProf::GraphHtmlPrinter.new(prof).print(report, min_percent: 1)
report.close
render text: report.string
else
render text: 'Profiler not running.'
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment