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.
This commit is contained in:
parent
72611cbc3a
commit
8346da6527
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: Add backtraces to Peek performance bar for SQL calls
|
||||
merge_request:
|
||||
author:
|
||||
type: added
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue