-
-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Instrument Reflex processing in development and log summary
- Loading branch information
1 parent
078db30
commit 0120ae6
Showing
3 changed files
with
30 additions
and
2 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
module StimulusReflex | ||
class Instrumentation | ||
def self.track(reflex) | ||
return yield unless reflex.logger && StimulusReflex.config.instrument_reflexes | ||
|
||
events = [] | ||
|
||
time = Benchmark.realtime do | ||
ActiveSupport::Notifications.subscribed(lambda { |event| events << event }, /^sql.active_record|^render/) do | ||
yield | ||
end | ||
end | ||
|
||
sql, views = events.partition { |e| e.name.match?(/^sql/) } | ||
|
||
reflex.logger.info "Processed #{reflex.class.name}##{reflex.method_name} in #{(time * 1000).round(1)}ms " + | ||
"(Views: #{views.sum(&:duration).round(1)}ms | " + | ||
"ActiveRecord: #{sql.sum(&:duration).round(1)}ms | " + | ||
"Allocations: #{events.sum(&:allocations)}) \n" | ||
end | ||
end | ||
end |
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