Created
January 24, 2022 13:29
-
-
Save palkan/a40e028865dc7bc4ccfb6db2ade9c94f to your computer and use it in GitHub Desktop.
Revisions
-
palkan created this gist
Jan 24, 2022 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,41 @@ Add the following to `application.rb`: ```ruby $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](https://github.com/nevir/Bumbler).