diff options
author | Rémy Coutable <remy@rymai.me> | 2017-06-07 19:55:07 +0200 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2017-06-09 17:21:39 +0200 |
commit | e85914532970d61d53f025f3ff0d85891bab2637 (patch) | |
tree | a54bac63e63570a31ff31d4cafffc31e1636a1a0 /lib | |
parent | 55631e3d52dd2e16b69b02ffc99207b60a22989e (diff) | |
download | gitlab-ce-e85914532970d61d53f025f3ff0d85891bab2637.tar.gz |
Fix Rubocop offenses, improve SQL duration format and changelog entry
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/performance_bar/peek_query_tracker.rb | 3 | ||||
-rw-r--r-- | lib/peek/rblineprof/custom_controller_helpers.rb | 30 |
2 files changed, 23 insertions, 10 deletions
diff --git a/lib/gitlab/performance_bar/peek_query_tracker.rb b/lib/gitlab/performance_bar/peek_query_tracker.rb index 479396f6664..7ab80f5ee0f 100644 --- a/lib/gitlab/performance_bar/peek_query_tracker.rb +++ b/lib/gitlab/performance_bar/peek_query_tracker.rb @@ -30,7 +30,8 @@ module Gitlab def track_query(raw_query, bindings, 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 end end diff --git a/lib/peek/rblineprof/custom_controller_helpers.rb b/lib/peek/rblineprof/custom_controller_helpers.rb index 796420971b5..2ecda58c669 100644 --- a/lib/peek/rblineprof/custom_controller_helpers.rb +++ b/lib/peek/rblineprof/custom_controller_helpers.rb @@ -11,6 +11,7 @@ module Peek end end + # rubocop:disable Metrics/AbcSize def inject_rblineprof ret = nil profile = lineprof(rblineprof_profiler_regex) do @@ -25,32 +26,43 @@ module Peek # Sort each file by the longest calculated time 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 cpu = summary == 'exclusive' ? excl_cpu : 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, 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 = '' per_file.each do |file_name, lines, file_wall, file_cpu, file_idle, file_sort| - output << "<div class='peek-rblineprof-file'><div class='heading'>" show_src = file_sort > min tmpl = show_src ? "<a href='#' class='js-lineprof-file'>%s</a>" : "%s" - 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 + '/', '')) - else - output << sprintf("<span class='duration'>% 8.1fms</span> #{tmpl}", file_wall/1000.0, file_name.sub(Rails.root.to_s + '/', '')) - end + output << + if mode == 'cpu' + 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 + sprintf("<span class='duration'>% 8.1fms</span> #{tmpl}", file_wall / 1000.0, file_name.sub(Rails.root.to_s + '/', '')) + end output << "</div>" # .heading |