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 {
metric: 'active-record',
title: 'pg',
header: s__('PerformanceBar|SQL queries'),
keys: ['sql'],
keys: ['sql', 'cached'],
},
{
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:
- **Current Host**: the current host serving the page.
- **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:
![SQL profiling using the Performance Bar](img/performance_bar_sql_queries.png)
- **Gitaly calls**: the time taken (in milliseconds) and the total number of
......
......@@ -17,27 +17,38 @@ module Peek
}
}.freeze
def results
super.merge(calls: detailed_calls)
end
def self.thresholds
@thresholds ||= THRESHOLDS.fetch(Rails.env.to_sym, DEFAULT_THRESHOLDS)
end
private
def detailed_calls
"#{calls} (#{cached_calls} cached)"
end
def cached_calls
detail_store.count { |item| item[:cached] == 'cached' }
end
def setup_subscribers
super
subscribe('sql.active_record') do |_, start, finish, _, data|
if Gitlab::PerformanceBar.enabled_for_request?
unless data[:cached]
detail_store << {
duration: finish - start,
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
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