Created
June 14, 2011 16:59
-
-
Save kpumuk/1025332 to your computer and use it in GitHub Desktop.
Profile Rails 2.2 startup
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/vendor/rails/railties/lib/initializer.rb b/vendor/rails/railties/lib/initializer.rb | |
index 16abe62..cb7a811 100644 | |
--- a/vendor/rails/railties/lib/initializer.rb | |
+++ b/vendor/rails/railties/lib/initializer.rb | |
@@ -10,11 +10,13 @@ require 'rails/plugin/loader' | |
require 'rails/gem_dependency' | |
require 'rails/rack' | |
+require 'rails_startup_timer' | |
RAILS_ENV = (ENV['RAILS_ENV'] || 'development').dup unless defined?(RAILS_ENV) | |
module Rails | |
class << self | |
+ | |
# The Configuration instance used to configure the Rails environment | |
def configuration | |
@@configuration | |
@@ -89,6 +91,9 @@ module Rails | |
# This will use the default configuration options from Rails::Configuration, | |
# but allow for overwriting on select areas. | |
class Initializer | |
+ | |
+ include ::RailsStartupTimer | |
+ | |
# The Configuration instance used by this Initializer instance. | |
attr_reader :configuration | |
@@ -125,67 +130,67 @@ module Rails | |
def process | |
Rails.configuration = configuration | |
- check_ruby_version | |
- install_gem_spec_stubs | |
- set_load_path | |
- add_gem_load_paths | |
+ time_it :check_ruby_version | |
+ time_it :install_gem_spec_stubs | |
+ time_it :set_load_path | |
+ time_it :add_gem_load_paths | |
- require_frameworks | |
- set_autoload_paths | |
- add_plugin_load_paths | |
- load_environment | |
+ time_it :require_frameworks | |
+ time_it :set_autoload_paths | |
+ time_it :add_plugin_load_paths | |
+ time_it :load_environment | |
- initialize_encoding | |
- initialize_database | |
+ time_it :initialize_encoding | |
+ time_it :initialize_database | |
- initialize_cache | |
- initialize_framework_caches | |
+ time_it :initialize_cache | |
+ time_it :initialize_framework_caches | |
- initialize_logger | |
- initialize_framework_logging | |
+ time_it :initialize_logger | |
+ time_it :initialize_framework_logging | |
- initialize_dependency_mechanism | |
- initialize_whiny_nils | |
- initialize_temporary_session_directory | |
+ time_it :initialize_dependency_mechanism | |
+ time_it :initialize_whiny_nils | |
+ time_it :initialize_temporary_session_directory | |
- initialize_time_zone | |
- initialize_i18n | |
+ time_it :initialize_time_zone | |
+ time_it :initialize_i18n | |
- initialize_framework_settings | |
- initialize_framework_views | |
+ time_it :initialize_framework_settings | |
+ time_it :initialize_framework_views | |
- add_support_load_paths | |
+ time_it :add_support_load_paths | |
- load_gems | |
- load_plugins | |
+ time_it :load_gems | |
+ time_it :load_plugins | |
# pick up any gems that plugins depend on | |
- add_gem_load_paths | |
- load_gems | |
- check_gem_dependencies | |
+ time_it :add_gem_load_paths | |
+ time_it :load_gems | |
+ time_it :check_gem_dependencies | |
- load_application_initializers | |
+ time_it :load_application_initializers | |
# the framework is now fully initialized | |
- after_initialize | |
+ time_it :after_initialize | |
# Prepare dispatcher callbacks and run 'prepare' callbacks | |
- prepare_dispatcher | |
+ time_it :prepare_dispatcher | |
# Routing must be initialized after plugins to allow the former to extend the routes | |
- initialize_routing | |
+ time_it :initialize_routing | |
# Observers are loaded after plugins in case Observers or observed models are modified by plugins. | |
- load_observers | |
+ time_it :load_observers | |
# Load view path cache | |
- load_view_paths | |
+ time_it :load_view_paths | |
# Load application classes | |
- load_application_classes | |
+ time_it :load_application_classes | |
# Disable dependency loading during request cycle | |
- disable_dependency_loading | |
+ time_it :disable_dependency_loading | |
# Flag initialized | |
Rails.initialized = true | |
@@ -278,7 +283,7 @@ module Rails | |
end | |
def load_gems | |
- @configuration.gems.each { |gem| gem.load } | |
+ @configuration.gems.each { |gem| time_it("gem:#{gem.name}", 2) { gem.load } } | |
end | |
def check_gem_dependencies | |
@@ -547,7 +552,7 @@ Run `rake gems:install` to install the missing gems. | |
def load_application_initializers | |
if gems_dependencies_loaded | |
Dir["#{configuration.root_path}/config/initializers/**/*.rb"].sort.each do |initializer| | |
- load(initializer) | |
+ time_it("initializer:#{File.basename(initializer)}", 2) { load(initializer) } | |
end | |
end | |
end | |
diff --git a/vendor/rails/railties/lib/rails/plugin/loader.rb b/vendor/rails/railties/lib/rails/plugin/loader.rb | |
index 948d497..a4e9eb8 100644 | |
--- a/vendor/rails/railties/lib/rails/plugin/loader.rb | |
+++ b/vendor/rails/railties/lib/rails/plugin/loader.rb | |
@@ -1,4 +1,5 @@ | |
require "rails/plugin" | |
+require "rails_startup_timer" | |
module Rails | |
class Plugin | |
@@ -27,10 +28,12 @@ module Rails | |
@all_plugins ||= locate_plugins | |
@all_plugins | |
end | |
+ | |
+ include ::RailsStartupTimer | |
def load_plugins | |
plugins.each do |plugin| | |
- plugin.load(initializer) | |
+ time_it("plugin:#{plugin.name}", 2) { plugin.load(initializer) } | |
register_plugin_as_loaded(plugin) | |
end | |
ensure_all_registered_plugins_are_loaded! | |
@@ -149,4 +152,4 @@ module Rails | |
end | |
end | |
-end | |
\ No newline at end of file | |
+end | |
diff --git a/vendor/rails/railties/lib/rails_startup_timer.rb b/vendor/rails/railties/lib/rails_startup_timer.rb | |
new file mode 100644 | |
index 0000000..39eb4e8 | |
--- /dev/null | |
+++ b/vendor/rails/railties/lib/rails_startup_timer.rb | |
@@ -0,0 +1,16 @@ | |
+module RailsStartupTimer | |
+ def time_it(name, indent=0) | |
+ @total ||= 0 | |
+ start = Time.now | |
+ if block_given? | |
+ yield | |
+ else | |
+ send(name) | |
+ end | |
+ finish = Time.now | |
+ total = (finish - start).to_f | |
+ @total += total | |
+ formatted_name = ((' ' * indent) + name.to_s.gsub(/ /, '')).ljust(45) | |
+ puts ("==== #{formatted_name} took %0.8fs =========================" % total)[0,72] | |
+ end | |
+end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment