ruby-prof-rails
ruby-prof-rails copied to clipboard
Ruby-Prof Rails: Easily run ruby-prof on your Rails applications.
Ruby-Prof Rails
Summary
Rack middleware that allows you to easily run ruby-prof profiler on your rails application for your session only and not impact other users of a Rails application.
Requirements
- Ruby 1.9.3 or higher
- Rails 3 or later (with asset pipeline enabled)
- ruby-prof gem
- ruby-prof-flamegraph gem
Install
To install, include ruby-prof-rails in your Gemfile and run bundle install:
gem "ruby-prof-rails", :git => "[email protected]:tleish/ruby-prof-rails.git", :group => :production
Note: ruby-prof-rails requires production type settings (cache classes, cache view lookups, etc.), therefore it is recommended to only include the gem in production environments.
Configure
ruby-prof-rails won't do ANYTHING until you configure it. Update your config/environments/production.rb initializer with the following code:
RubyProf::Rails::Config.username = "your_shared_username"
RubyProf::Rails::Config.password = "your_shared_password"
RubyProf::Rails::Config.session_auth_lambda = lambda do |session|
session[:user_type] == :admin
end
RubyProf::Rails::Config.path = File.join(Rails.root, 'files', 'ruby-prof-rails')
The code above will ready ruby-prof for your rails application:
RubyProf::Rails::Config.username: (required) username for HTTP Basic authentication to access control panel and profilesRubyProf::Rails::Config.password: (required) password for HTTP Basic authentication to access control panel and profilesRubyProf::Rails::Config.session_auth_lambda: (optional) lambda to check user session for specific parameters. True allows access control panel and profiles, false will not.RubyProf::Rails::Config.path: (optional) File location where profiles are saved (defaults toRails.root/tmp/ruby-prof-rails/).
Routes
(Optional) Mount the gem by adding the following to config/routes.rb:
mount RubyProf::Rails::Engine, :at => '/' if Rails.env.production?
Usage
Once installed and configured, run your application and navigate to http://your_app/ruby_prof_rails, enter profiling options and press the Start Profiling button

Option: Printers
Select one or more printers to save the output of your profile results.
See:
Option: Measurement
Option: Eliminate Method Patterns
see ruby-prof Method Elimination
eliminate_methods is a list of regular expressions (line separated text).
Integer#times
String#.*
Option: Exclude Request Route Formats:
ruby-prof-rails supports excluding specific request file formats from the routes.
For example, you likely want to skip images (png, jpg, gif), unless you are producing these images via rails code.
exclude_formats is a list of file formats (line separated text).
css, js, json, map, jpg, jpeg, png, gif
Any routes with the file formats specified will be ignored and skipped over.
Stop Profiling:
When profiling is complete, press the stop button to see profiling results

Profiles
- My Profiles: Profiles captured from your current session.
- All Profiles: Profiles captured from all sessions.

License
See MIT-LICENSE for further details.