-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Track initializer's loaded event per file #12859
Track initializer's loaded event per file #12859
Conversation
@@ -645,6 +645,12 @@ def routes? #:nodoc: | |||
|
|||
protected | |||
|
|||
def load_initializer(initializer) | |||
ActiveSupport::Notifications.instrument('load_initializer.railties', initializer: initializer) do |_| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need to accept the _
variable?
Thanks @egilburg |
@pftg don't forget the CHANGELOG entry. Also, who users would use this in their applications? |
@rafaelfranca, this feature good for profiling tools, to find bottlenecks in booting app. This specific commit is help for @xaviershay, for his PR #12745, that's why I have not added changelog. |
Yes, I think for what it is good, I want to know how to use 😄 Right now there is no information. Should I add an initializer to listen the notification? Should I add a ruby script? Should I put this code somewhere else? Of course this need to be documented. |
I see, I'll add this |
Thank you! Going to try and look at this this week. |
This is great! I would love to have this. It's pretty easy to subscribe to the event in order to get profiling info: # development.rb
ActiveSupport::Notifications.subscribe("load_initializer.railties") do |*args|
event = ActiveSupport::Notifications::Event.new(*args)
puts "Loaded initializer #{event.payload[:initializer]} (#{event.duration}ms)"
end |
Needs the doc update still |
@rafaelfranca will do it today/tomorrow |
👍 |
@rafaelfranca I added changelog with examples of exploiting this instrument. |
end | ||
|
||
# config/initializers/benchmark_initializers.rb | ||
ActiveSupport::Notifications.subscribe('load_initializer.railties') do |*args| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is weird to me to put this code in an initializer. It is subscribing the load event of initializer and it will generate data for this event. I think we should recommend to put in the initializers folder
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, I'd just take out this example. There are load ordering issues as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:) just show possibility, that you can subscribe even in initializers. About order, I forget mention about naming of initializer. Elsewhere I'll remove!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two examples is plenty :)
In order to simplify profiling loading of initializers, added instument for tracking load config initializer event from `config/initializers`
Thanks @rafaelfranca and @xaviershay I updated changelog |
Track initializer's loaded event per file
Thanks! ❤️ |
awesome |
Proposed implementation of tracking load initializers for #12745
@xaviershay, you may cherry-pick this commit if you needed it for your implementation.