From 8346da6527ab4b9233605565a022ef9f05d3f4c9 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Sun, 9 Jun 2019 18:18:14 -0700 Subject: Add backtraces to Peek performance bar for SQL calls Just as we have backtraces for Gitaly, we should also have backtraces for SQL calls. This makes it much easier to find the source of the SQL call and optimize N+1 queries and other performance issues with an endpoint. --- lib/gitlab/performance_bar/peek_query_tracker.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/gitlab/performance_bar/peek_query_tracker.rb b/lib/gitlab/performance_bar/peek_query_tracker.rb index 16c16aa0265..3a27e26eaba 100644 --- a/lib/gitlab/performance_bar/peek_query_tracker.rb +++ b/lib/gitlab/performance_bar/peek_query_tracker.rb @@ -27,15 +27,16 @@ module Gitlab subscribe('sql.active_record') do |_, start, finish, _, data| if Gitlab::SafeRequestStore.store[:peek_enabled] unless data[:cached] - track_query(data[:sql].strip, data[:binds], start, finish) + backtrace = Gitlab::Profiler.clean_backtrace(caller) + track_query(data[:sql].strip, data[:binds], backtrace, start, finish) end end end end - def track_query(raw_query, bindings, start, finish) + def track_query(raw_query, bindings, backtrace, start, finish) duration = (finish - start) * 1000.0 - query_info = { duration: duration.round(3), sql: raw_query } + query_info = { duration: duration.round(3), sql: raw_query, backtrace: backtrace } PEEK_DB_CLIENT.query_details << query_info end -- cgit v1.2.1