Created
August 2, 2010 08:37
-
-
Save tmm1/504342 to your computer and use it in GitHub Desktop.
rails3 patch for perftools.rb cpu/object profiling
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
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×=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