From 52b6cbcb9df7e2c968da3e9a9779500cacfac465 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Mon, 20 Nov 2017 09:18:15 -0800 Subject: Add QUERY_RECORDER_DEBUG environment variable to improve performance debugging --- spec/support/query_recorder.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'spec') diff --git a/spec/support/query_recorder.rb b/spec/support/query_recorder.rb index ba0b805caad..cd67b517ea0 100644 --- a/spec/support/query_recorder.rb +++ b/spec/support/query_recorder.rb @@ -8,7 +8,14 @@ module ActiveRecord ActiveSupport::Notifications.subscribed(method(:callback), 'sql.active_record', &block) end + def show_backtrace(values) + Rails.logger.debug("QueryRecorder SQL: #{values[:sql]}") + caller.each { |line| Rails.logger.debug(" --> #{line}") } + end + def callback(name, start, finish, message_id, values) + show_backtrace(values) if ENV['QUERY_RECORDER_DEBUG'] + if values[:name]&.include?("CACHE") @cached << values[:sql] elsif !values[:name]&.include?("SCHEMA") -- cgit v1.2.1