Commit 7629fadf authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch '259005-add-cached-queries-to-performance-bar' into 'master'

Include cached sql calls in performance bar

Closes #259005

See merge request gitlab-org/gitlab!44022
parents c2c5bd72 beb5a5ca
...@@ -36,7 +36,7 @@ export default { ...@@ -36,7 +36,7 @@ export default {
metric: 'active-record', metric: 'active-record',
title: 'pg', title: 'pg',
header: s__('PerformanceBar|SQL queries'), header: s__('PerformanceBar|SQL queries'),
keys: ['sql'], keys: ['sql', 'cached'],
}, },
{ {
metric: 'bullet', metric: 'bullet',
......
---
title: Include cached sql calls in performance bar
merge_request: 44022
author:
type: changed
...@@ -15,7 +15,7 @@ From left to right, it displays: ...@@ -15,7 +15,7 @@ From left to right, it displays:
- **Current Host**: the current host serving the page. - **Current Host**: the current host serving the page.
- **Database queries**: the time taken (in milliseconds) and the total number - **Database queries**: the time taken (in milliseconds) and the total number
of database queries, displayed in the format `00ms / 00pg`. Click to display of database queries, displayed in the format `00ms / 00 (00 cached) pg`. Click to display
a modal window with more details: a modal window with more details:
![SQL profiling using the Performance Bar](img/performance_bar_sql_queries.png) ![SQL profiling using the Performance Bar](img/performance_bar_sql_queries.png)
- **Gitaly calls**: the time taken (in milliseconds) and the total number of - **Gitaly calls**: the time taken (in milliseconds) and the total number of
......
...@@ -17,27 +17,38 @@ module Peek ...@@ -17,27 +17,38 @@ module Peek
} }
}.freeze }.freeze
def results
super.merge(calls: detailed_calls)
end
def self.thresholds def self.thresholds
@thresholds ||= THRESHOLDS.fetch(Rails.env.to_sym, DEFAULT_THRESHOLDS) @thresholds ||= THRESHOLDS.fetch(Rails.env.to_sym, DEFAULT_THRESHOLDS)
end end
private private
def detailed_calls
"#{calls} (#{cached_calls} cached)"
end
def cached_calls
detail_store.count { |item| item[:cached] == 'cached' }
end
def setup_subscribers def setup_subscribers
super super
subscribe('sql.active_record') do |_, start, finish, _, data| subscribe('sql.active_record') do |_, start, finish, _, data|
if Gitlab::PerformanceBar.enabled_for_request? if Gitlab::PerformanceBar.enabled_for_request?
unless data[:cached]
detail_store << { detail_store << {
duration: finish - start, duration: finish - start,
sql: data[:sql].strip, sql: data[:sql].strip,
backtrace: Gitlab::BacktraceCleaner.clean_backtrace(caller) backtrace: Gitlab::BacktraceCleaner.clean_backtrace(caller),
cached: data[:cached] ? 'cached' : ''
} }
end end
end end
end end
end end
end end
end
end 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