1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Instrument each load config initializer

In order to simplify profiling loading of initializers,
added instument for tracking load config initializer event from
`config/initializers`
This commit is contained in:
Paul Nikitochkin 2013-11-11 19:56:02 +02:00
parent 93e752cfae
commit 251923c7a8
4 changed files with 59 additions and 1 deletions

View file

@ -396,6 +396,15 @@ INFO. Cache stores my add their own keys
}
```
Railties
--------
### load_config_initializer.railties
| Key | Value |
| -------------- | ----------------------------------------------------- |
| `:initializer` | Path to loaded initializer from `config/initializers` |
Rails
-----

View file

@ -1,3 +1,33 @@
* Instrument an `load_config_initializer.railties` event on each load of configuration initializer
from `config/initializers`. Subscribers should be attached before `load_config_initializers`
initializer completed.
Registering subscriber examples:
# config/application.rb
module RailsApp
class Application < Rails::Application
ActiveSupport::Notifications.subscribe('load_config_initializer.railties') do |*args|
event = ActiveSupport::Notifications::Event.new(*args)
puts "Loaded initializer #{event.payload[:initializer]} (#{event.duration}ms)"
end
end
end
# my_engine/lib/my_engine/engine.rb
module MyEngine
class Engine < ::Rails::Engine
config.before_initialize do
ActiveSupport::Notifications.subscribe('load_config_initializer.railties') do |*args|
event = ActiveSupport::Notifications::Event.new(*args)
puts "Loaded initializer #{event.payload[:initializer]} (#{event.duration}ms)"
end
end
end
end
*Paul Nikitochkin*
* Support for Pathnames in eager load paths.
*Mike Pack*

View file

@ -611,7 +611,7 @@ module Rails
initializer :load_config_initializers do
config.paths["config/initializers"].existent.sort.each do |initializer|
load(initializer)
load_config_initializer(initializer)
end
end
@ -645,6 +645,12 @@ module Rails
protected
def load_config_initializer(initializer)
ActiveSupport::Notifications.instrument('load_config_initializer.railties', initializer: initializer) do
load(initializer)
end
end
def run_tasks_blocks(*) #:nodoc:
super
paths["lib/tasks"].existent.sort.each { |ext| load(ext) }

View file

@ -39,5 +39,18 @@ module ApplicationTests
assert_equal 1, logger.logged(:debug).size
assert_match(/SHOW tables/, logger.logged(:debug).last)
end
test 'rails load_config_initializer event is instrumented' do
app_file 'config/initializers/foo.rb', ''
events = []
callback = -> (*_) { events << _ }
ActiveSupport::Notifications.subscribed(callback, 'load_config_initializer.railties') do
app
end
assert_equal %w[load_config_initializer.railties], events.map(&:first)
assert_includes events.first.last[:initializer], 'config/initializers/foo.rb'
end
end
end