Skip to content

Instantly share code, notes, and snippets.

@tmm1
Created August 2, 2010 08:37
Show Gist options
  • Save tmm1/504342 to your computer and use it in GitHub Desktop.
Save tmm1/504342 to your computer and use it in GitHub Desktop.
rails3 patch for perftools.rb cpu/object profiling
diff --git a/Gemfile b/Gemfile
index fd90d42..9dd0146 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1,4 +1,6 @@
source 'http://rubygems.org'
+gem 'perftools.rb', '>= 0.4.4'
+gem 'rack-perftools_profiler'
gem 'rails', '3.0.0.rc'
diff --git a/config/application.rb b/config/application.rb
index 1900eaf..484a7b9 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -38,5 +38,26 @@ module Foobar
# Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters += [:password]
+
+ # Enable object allocation profiling
+ #
+ # $ RAILS_ENV=production ./script/rails server
+ #
+ # $ curl http://localhost:3000/__start__
+ # $ curl http://localhost:3000/home
+ # $ curl http://localhost:3000/about
+ # $ curl http://localhost:3000/__stop__
+ # $ curl http://localhost:3000/__data__ -o profile.gif
+ # $ curl http://localhost:3000/__data__?printer=text -o profile.txt
+ #
+ # $ curl "http://localhost:3000/home?profile=true&times=10&printer=gif" -o 10_requests_to_homepage.gif
+ #
+ STDERR.puts '*** perftools.rb object allocation profiling is enabled (this will impact performance)'
+
+ ENV['CPUPROFILE_OBJECTS'] = '1' # remove this to do CPU profiling instead (much lower overhead)
+ config.cache_classes = true # avoid unnecessary objects
+
+ require 'rack/perftools_profiler'
+ config.middleware.insert 0, Rack::PerftoolsProfiler, :default_printer => 'gif'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment