Add the following to application.rb
:
$icallbacks = []
$icallbacks.define_singleton_method(:print) do
puts sort_by { |(a, b)| -b }.map { |(a, b)| "#{b}\t\t#{a}" }.join("\n")
end
ActiveSupport::Notifications.subscribe("load_config_initializer.railties") do |event|
$icallbacks << [event.payload[:initializer], event.duration]
end
$pcallbacks = []
$pcallbacks.define_singleton_method(:print) do
puts sort_by { |(a, b)| -b }.map { |(a, b)| "#{b}\t\t#{a.first}:#{a.last}" }.join("\n")
end
require 'active_support/reloader'
require 'benchmark'
ActiveSupport::Reloader.singleton_class.prepend(Module.new do
def to_prepare(*args, &block)
wrapper = proc do |*bargs|
result = nil
time = Benchmark.realtime do
result = block.call(*bargs)
end
$pcallbacks << [block.source_location, time]
result
end
super(*args, &wrapper)
end
end)
Then, run rails r 'puts $icallbacks.print'
, etc.
See also Bumbler.