Created
November 29, 2011 17:42
-
-
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.
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
gem 'ruby-prof' |
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
# ------ Debug ------ | |
if Rails.env.development? | |
match 'rubyprof/:action', controller: 'ruby_prof' | |
end |
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
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