summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2015-11-19 12:33:58 +0100
committerYorick Peterse <yorickpeterse@gmail.com>2015-11-24 10:57:21 +0100
commit97f8c6279fc39c4bad87bb880eba04802f6d351d (patch)
treeef1eac455f8529ae4e35f3b286e225e556f148ee
parent31a34b591731eb8997da4844287d7c31e3686454 (diff)
downloadgitlab-ce-sherlock-total-query-time.tar.gz
Added total query time to Sherlocksherlock-total-query-time
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).
-rw-r--r--app/views/sherlock/transactions/_general.html.haml6
-rw-r--r--config/locales/sherlock.en.yml1
-rw-r--r--lib/gitlab/sherlock/transaction.rb5
-rw-r--r--spec/lib/gitlab/sherlock/transaction_spec.rb13
4 files changed, 25 insertions, 0 deletions
diff --git a/app/views/sherlock/transactions/_general.html.haml b/app/views/sherlock/transactions/_general.html.haml
index 4287a0c3203..8533b130da6 100644
--- a/app/views/sherlock/transactions/_general.html.haml
+++ b/app/views/sherlock/transactions/_general.html.haml
@@ -27,6 +27,12 @@
= t('sherlock.seconds')
%li
%span.light
+ #{t('sherlock.query_time')}
+ %strong
+ = @transaction.query_duration.round(2)
+ = t('sherlock.seconds')
+ %li
+ %span.light
#{t('sherlock.finished_at')}:
%strong
= time_ago_in_words(@transaction.finished_at)
diff --git a/config/locales/sherlock.en.yml b/config/locales/sherlock.en.yml
index 683b09dc329..f24b825f585 100644
--- a/config/locales/sherlock.en.yml
+++ b/config/locales/sherlock.en.yml
@@ -35,3 +35,4 @@ en:
events: Events
percent: '%'
count: Count
+ query_time: Query Time
diff --git a/lib/gitlab/sherlock/transaction.rb b/lib/gitlab/sherlock/transaction.rb
index d87a4c9bb4a..3489fb251b6 100644
--- a/lib/gitlab/sherlock/transaction.rb
+++ b/lib/gitlab/sherlock/transaction.rb
@@ -36,6 +36,11 @@ module Gitlab
@duration ||= started_at && finished_at ? finished_at - started_at : 0
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
@id
end
diff --git a/spec/lib/gitlab/sherlock/transaction_spec.rb b/spec/lib/gitlab/sherlock/transaction_spec.rb
index bb49fb65cf8..fb80c62c794 100644
--- a/spec/lib/gitlab/sherlock/transaction_spec.rb
+++ b/spec/lib/gitlab/sherlock/transaction_spec.rb
@@ -84,6 +84,19 @@ describe Gitlab::Sherlock::Transaction do
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
it 'returns the transaction ID' do
expect(transaction.to_param).to eq(transaction.id)