Commit e8591453 authored by Rémy Coutable's avatar Rémy Coutable

Fix Rubocop offenses, improve SQL duration format and changelog entry

Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent 55631e3d
import 'vendor/peek'; import 'vendor/peek';
import 'vendor/peek.performance_bar'; import 'vendor/peek.performance_bar';
(function() { $(document).on('click', '#peek-show-queries', function(e) {
$(document).on('click', '#peek-show-queries', function(e) { e.preventDefault();
var $modal;
$('.peek-rblineprof-modal').hide(); $('.peek-rblineprof-modal').hide();
$modal = $('#modal-peek-pg-queries'); let $modal = $('#modal-peek-pg-queries');
if ($modal.length) { if ($modal.length) {
$modal.modal('toggle'); $modal.modal('toggle');
} }
return e.preventDefault(); });
});
$(document).on('click', '.js-lineprof-file', function(e) { $(document).on('click', '.js-lineprof-file', function(e) {
e.preventDefault();
$(this).parents('.heading').next('div').toggle(); $(this).parents('.heading').next('div').toggle();
return e.preventDefault(); });
});
}).call(window);
...@@ -60,11 +60,10 @@ import findAndFollowLink from './shortcuts_dashboard_navigation'; ...@@ -60,11 +60,10 @@ import findAndFollowLink from './shortcuts_dashboard_navigation';
e.preventDefault(); e.preventDefault();
if (Cookies.get('perf_bar_enabled') === 'true') { if (Cookies.get('perf_bar_enabled') === 'true') {
Cookies.remove('perf_bar_enabled', { path: '/' }); Cookies.remove('perf_bar_enabled', { path: '/' });
} } else {
else {
Cookies.set('perf_bar_enabled', true, { path: '/' }); Cookies.set('perf_bar_enabled', true, { path: '/' });
} }
return gl.utils.refreshCurrentPage(); gl.utils.refreshCurrentPage();
}; };
Shortcuts.prototype.toggleMarkdownPreview = function(e) { Shortcuts.prototype.toggleMarkdownPreview = function(e) {
......
--- ---
title: Allow to enable a performance bar with the keyboard shortcut title: Add an optional performance bar to view performance metrics for the current page
merge_request: 11439 merge_request: 11439
author: author:
...@@ -3,16 +3,15 @@ Rails.application.config.peek.adapter = :redis, { client: ::Redis.new(Gitlab::Re ...@@ -3,16 +3,15 @@ Rails.application.config.peek.adapter = :redis, { client: ::Redis.new(Gitlab::Re
Peek.into Peek::Views::Host Peek.into Peek::Views::Host
Peek.into Peek::Views::PerformanceBar Peek.into Peek::Views::PerformanceBar
if Gitlab::Database.mysql? if Gitlab::Database.mysql?
require 'peek-mysql' require 'peek-mysql2'
PEEK_DB_CLIENT = ::Mysql2::Client PEEK_DB_CLIENT = ::Mysql2::Client
PEEK_DB_VIEW = Peek::Views::Mysql2 PEEK_DB_VIEW = Peek::Views::Mysql2
Peek.into PEEK_DB_VIEW
else else
require 'peek-pg' require 'peek-pg'
PEEK_DB_CLIENT = ::PG::Connection PEEK_DB_CLIENT = ::PG::Connection
PEEK_DB_VIEW = Peek::Views::PG PEEK_DB_VIEW = Peek::Views::PG
Peek.into PEEK_DB_VIEW
end end
Peek.into PEEK_DB_VIEW
Peek.into Peek::Views::Redis Peek.into Peek::Views::Redis
Peek.into Peek::Views::Sidekiq Peek.into Peek::Views::Sidekiq
Peek.into Peek::Views::Rblineprof Peek.into Peek::Views::Rblineprof
...@@ -25,4 +24,5 @@ class PEEK_DB_CLIENT ...@@ -25,4 +24,5 @@ class PEEK_DB_CLIENT
self.query_details = Concurrent::Array.new self.query_details = Concurrent::Array.new
end end
# rubocop:disable Style/ClassAndModuleCamelCase
PEEK_DB_VIEW.prepend ::Gitlab::PerformanceBar::PeekQueryTracker PEEK_DB_VIEW.prepend ::Gitlab::PerformanceBar::PeekQueryTracker
...@@ -30,7 +30,8 @@ module Gitlab ...@@ -30,7 +30,8 @@ module Gitlab
def track_query(raw_query, bindings, start, finish) def track_query(raw_query, bindings, start, finish)
query = Gitlab::Sherlock::Query.new(raw_query, start, finish) query = Gitlab::Sherlock::Query.new(raw_query, start, finish)
query_info = { duration: query.duration.round(4), sql: query.formatted_query } query_info = { duration: '%.3f' % query.duration, sql: query.formatted_query }
PEEK_DB_CLIENT.query_details << query_info PEEK_DB_CLIENT.query_details << query_info
end end
end end
......
...@@ -11,6 +11,7 @@ module Peek ...@@ -11,6 +11,7 @@ module Peek
end end
end end
# rubocop:disable Metrics/AbcSize
def inject_rblineprof def inject_rblineprof
ret = nil ret = nil
profile = lineprof(rblineprof_profiler_regex) do profile = lineprof(rblineprof_profiler_regex) do
...@@ -25,31 +26,42 @@ module Peek ...@@ -25,31 +26,42 @@ module Peek
# Sort each file by the longest calculated time # Sort each file by the longest calculated time
per_file = profile.map do |file, lines| per_file = profile.map do |file, lines|
total, child, excl, total_cpu, child_cpu, excl_cpu = lines[0] total, _child, excl, total_cpu, _child_cpu, excl_cpu = lines[0]
wall = summary == 'exclusive' ? excl : total wall = summary == 'exclusive' ? excl : total
cpu = summary == 'exclusive' ? excl_cpu : total_cpu cpu = summary == 'exclusive' ? excl_cpu : total_cpu
idle = summary == 'exclusive' ? (excl - excl_cpu) : (total - total_cpu) idle = summary == 'exclusive' ? (excl - excl_cpu) : (total - total_cpu)
sort_method =
case sort
when 'idle'
idle
when 'cpu'
cpu
else
wall
end
[ [
file, lines, file, lines,
wall, cpu, idle, wall, cpu, idle,
sort == 'idle' ? idle : sort == 'cpu' ? cpu : wall sort_method
] ]
end.sort_by{ |a,b,c,d,e,f| -f } end
per_file = per_file.sort_by { |_a, _b, _c, _d, _e, f| -f }
output = '' output = ''
per_file.each do |file_name, lines, file_wall, file_cpu, file_idle, file_sort| per_file.each do |file_name, lines, file_wall, file_cpu, file_idle, file_sort|
output << "<div class='peek-rblineprof-file'><div class='heading'>" output << "<div class='peek-rblineprof-file'><div class='heading'>"
show_src = file_sort > min show_src = file_sort > min
tmpl = show_src ? "<a href='#' class='js-lineprof-file'>%s</a>" : "%s" tmpl = show_src ? "<a href='#' class='js-lineprof-file'>%s</a>" : "%s"
output <<
if mode == 'cpu' if mode == 'cpu'
output << sprintf("<span class='duration'>% 8.1fms + % 8.1fms</span> #{tmpl}", file_cpu / 1000.0, file_idle / 1000.0, file_name.sub(Rails.root.to_s + '/', '')) sprintf("<span class='duration'>% 8.1fms + % 8.1fms</span> #{tmpl}", file_cpu / 1000.0, file_idle / 1000.0, file_name.sub(Rails.root.to_s + '/', ''))
else else
output << sprintf("<span class='duration'>% 8.1fms</span> #{tmpl}", file_wall/1000.0, file_name.sub(Rails.root.to_s + '/', '')) sprintf("<span class='duration'>% 8.1fms</span> #{tmpl}", file_wall / 1000.0, file_name.sub(Rails.root.to_s + '/', ''))
end end
output << "</div>" # .heading output << "</div>" # .heading
......
var requestId; let requestId = null;
requestId = null;
(function($) { (function($) {
var fetchRequestResults, getRequestId, peekEnabled, toggleBar, updatePerformanceBar; var fetchRequestResults, getRequestId, peekEnabled, toggleBar, updatePerformanceBar;
...@@ -16,9 +14,11 @@ requestId = null; ...@@ -16,9 +14,11 @@ requestId = null;
}; };
updatePerformanceBar = function(results) { updatePerformanceBar = function(results) {
var key, label, data, table, html, tr, duration_td, sql_td, strong; var key, label, data, table, html, tr, duration_td, sql_td, strong;
for (key in results.data) {
for (label in results.data[key]) { Object.keys(results.data).forEach((key) => {
Object.keys(results.data[key]).forEach((label) => {
data = results.data[key][label]; data = results.data[key][label];
if (label == 'queries') { if (label == 'queries') {
table = document.createElement('table'); table = document.createElement('table');
...@@ -40,12 +40,11 @@ requestId = null; ...@@ -40,12 +40,11 @@ requestId = null;
table.className = 'table'; table.className = 'table';
$("[data-defer-to=" + key + "-" + label + "]").html(table); $("[data-defer-to=" + key + "-" + label + "]").html(table);
} } else {
else {
$("[data-defer-to=" + key + "-" + label + "]").text(results.data[key][label]); $("[data-defer-to=" + key + "-" + label + "]").text(results.data[key][label]);
} }
} });
} });
return $(document).trigger('peek:render', [getRequestId(), results]); return $(document).trigger('peek:render', [getRequestId(), results]);
}; };
toggleBar = function(event) { toggleBar = function(event) {
...@@ -77,19 +76,6 @@ requestId = null; ...@@ -77,19 +76,6 @@ requestId = null;
}; };
$(document).on('keypress', toggleBar); $(document).on('keypress', toggleBar);
$(document).on('peek:update', fetchRequestResults); $(document).on('peek:update', fetchRequestResults);
$(document).on('pjax:end', function(event, xhr, options) {
if (xhr != null) {
requestId = xhr.getResponseHeader('X-Request-Id');
}
if (peekEnabled()) {
return $(this).trigger('peek:update');
}
});
$(document).on('page:change turbolinks:load', function() {
if (peekEnabled()) {
return $(this).trigger('peek:update');
}
});
return $(function() { return $(function() {
if (peekEnabled()) { if (peekEnabled()) {
return $(this).trigger('peek:update'); return $(this).trigger('peek:update');
......
...@@ -6,16 +6,11 @@ header.navbar-gitlab.with-peek { ...@@ -6,16 +6,11 @@ header.navbar-gitlab.with-peek {
} }
#peek { #peek {
background: #000; background: $black;
height: 35px; height: 35px;
line-height: 35px; line-height: 35px;
color: #999; color: #999;
.hidden {
display: none;
visibility: visible;
}
&.disabled { &.disabled {
display: none; display: none;
} }
...@@ -58,12 +53,12 @@ header.navbar-gitlab.with-peek { ...@@ -58,12 +53,12 @@ header.navbar-gitlab.with-peek {
} }
strong { strong {
color: #fff; color: $white-light;
} }
table { table {
strong { strong {
color: #000; color: $black;
} }
} }
...@@ -95,5 +90,5 @@ header.navbar-gitlab.with-peek { ...@@ -95,5 +90,5 @@ header.navbar-gitlab.with-peek {
} }
#modal-peek-pg-queries-content { #modal-peek-pg-queries-content {
color: #000; color: $black;
} }
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