Commit ef2bc0f0 authored by Yorick Peterse's avatar Yorick Peterse

Merge branch 'sherlock-total-query-time' into 'master'

Added total query time to Sherlock

This makes it easier to see if a problem is caused by slow queries or
slow Ruby code (unrelated to any SQL queries that might be used).

See merge request !1887
parents 4cfc3df5 97f8c627
...@@ -25,6 +25,12 @@ ...@@ -25,6 +25,12 @@
%strong %strong
= @transaction.duration.round(2) = @transaction.duration.round(2)
= t('sherlock.seconds') = t('sherlock.seconds')
%li
%span.light
#{t('sherlock.query_time')}
%strong
= @transaction.query_duration.round(2)
= t('sherlock.seconds')
%li %li
%span.light %span.light
#{t('sherlock.finished_at')}: #{t('sherlock.finished_at')}:
......
...@@ -35,3 +35,4 @@ en: ...@@ -35,3 +35,4 @@ en:
events: Events events: Events
percent: '%' percent: '%'
count: Count count: Count
query_time: Query Time
...@@ -36,6 +36,11 @@ module Gitlab ...@@ -36,6 +36,11 @@ module Gitlab
@duration ||= started_at && finished_at ? finished_at - started_at : 0 @duration ||= started_at && finished_at ? finished_at - started_at : 0
end end
# Returns the total query duration in seconds.
def query_duration
@query_duration ||= @queries.map { |q| q.duration }.inject(:+) / 1000.0
end
def to_param def to_param
@id @id
end end
......
...@@ -84,6 +84,19 @@ describe Gitlab::Sherlock::Transaction do ...@@ -84,6 +84,19 @@ describe Gitlab::Sherlock::Transaction do
end end
end end
describe '#query_duration' do
it 'returns the total query duration in seconds' do
time = Time.now
query1 = Gitlab::Sherlock::Query.new('SELECT 1', time, time + 5)
query2 = Gitlab::Sherlock::Query.new('SELECT 2', time, time + 2)
transaction.queries << query1
transaction.queries << query2
expect(transaction.query_duration).to be_within(0.1).of(7.0)
end
end
describe '#to_param' do describe '#to_param' do
it 'returns the transaction ID' do it 'returns the transaction ID' do
expect(transaction.to_param).to eq(transaction.id) expect(transaction.to_param).to eq(transaction.id)
......
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