diff options
author | Rémy Coutable <remy@rymai.me> | 2017-06-07 17:53:13 +0300 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2017-06-09 18:21:39 +0300 |
commit | 651eb51ececf9c256416eabe87c062ef33f45502 (patch) | |
tree | 6c77ca71fd5af17db2cba2c51113c97cda03f4c3 /lib/gitlab | |
parent | 5f218eb5c3ceabb42c42109bb7fe7427bd72e12f (diff) |
Display queries duration in performance bar queries modal
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'lib/gitlab')
-rw-r--r-- | lib/gitlab/performance_bar/peek_mysql_with_queries.rb | 36 | ||||
-rw-r--r-- | lib/gitlab/performance_bar/peek_query_tracker.rb (renamed from lib/gitlab/performance_bar/peek_pg_with_queries.rb) | 14 |
2 files changed, 8 insertions, 42 deletions
diff --git a/lib/gitlab/performance_bar/peek_mysql_with_queries.rb b/lib/gitlab/performance_bar/peek_mysql_with_queries.rb deleted file mode 100644 index ea577de5a69..00000000000 --- a/lib/gitlab/performance_bar/peek_mysql_with_queries.rb +++ /dev/null @@ -1,36 +0,0 @@ -# Inspired by https://github.com/peek/peek-mysql2/blob/master/lib/peek/views/mysql2.rb -module Gitlab - module PerformanceBar - module PeekMysqlWithQueries - def queries - ::Mysql2::Client.query_details - end - - def results - super.merge(queries: queries) - end - - private - - def setup_subscribers - super - - # Reset each counter when a new request starts - before_request do - ::Mysql2::Client.query_details = [] - end - - subscribe('sql.active_record') do |_, start, finish, _, data| - if RequestStore.active? && RequestStore.store[:peek_enabled] - track_query(data[:sql].strip, data[:binds], start, finish) - end - end - end - - def track_query(raw_query, bindings, start, finish) - query = Gitlab::Sherlock::Query.new(raw_query, start, finish) - ::Mysql2::Client.query_details << query.formatted_query - end - end - end -end diff --git a/lib/gitlab/performance_bar/peek_pg_with_queries.rb b/lib/gitlab/performance_bar/peek_query_tracker.rb index 6e9cb593d36..479396f6664 100644 --- a/lib/gitlab/performance_bar/peek_pg_with_queries.rb +++ b/lib/gitlab/performance_bar/peek_query_tracker.rb @@ -1,13 +1,14 @@ # Inspired by https://github.com/peek/peek-pg/blob/master/lib/peek/views/pg.rb module Gitlab module PerformanceBar - module PeekPgWithQueries - def queries - ::PG::Connection.query_details + module PeekQueryTracker + def sorted_queries + PEEK_DB_CLIENT.query_details. + sort { |a, b| b[:duration] <=> a[:duration] } end def results - super.merge(queries: queries) + super.merge(queries: sorted_queries) end private @@ -17,7 +18,7 @@ module Gitlab # Reset each counter when a new request starts before_request do - ::PG::Connection.query_details = [] + PEEK_DB_CLIENT.query_details = [] end subscribe('sql.active_record') do |_, start, finish, _, data| @@ -29,7 +30,8 @@ module Gitlab def track_query(raw_query, bindings, start, finish) query = Gitlab::Sherlock::Query.new(raw_query, start, finish) - ::PG::Connection.query_details << query.formatted_query + query_info = { duration: query.duration.round(4), sql: query.formatted_query } + PEEK_DB_CLIENT.query_details << query_info end end end |