Commit 8346da65 authored by Stan Hu's avatar Stan Hu

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.
parent 72611cbc
---
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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment