From e85914532970d61d53f025f3ff0d85891bab2637 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Wed, 7 Jun 2017 19:55:07 +0200 Subject: Fix Rubocop offenses, improve SQL duration format and changelog entry MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rémy Coutable --- lib/peek/rblineprof/custom_controller_helpers.rb | 30 +++++++++++++++++------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'lib/peek') 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 << "
" show_src = file_sort > min tmpl = show_src ? "%s" : "%s" - if mode == 'cpu' - output << sprintf("% 8.1fms + % 8.1fms #{tmpl}", file_cpu / 1000.0, file_idle / 1000.0, file_name.sub(Rails.root.to_s + '/', '')) - else - output << sprintf("% 8.1fms #{tmpl}", file_wall/1000.0, file_name.sub(Rails.root.to_s + '/', '')) - end + output << + if mode == 'cpu' + sprintf("% 8.1fms + % 8.1fms #{tmpl}", file_cpu / 1000.0, file_idle / 1000.0, file_name.sub(Rails.root.to_s + '/', '')) + else + sprintf("% 8.1fms #{tmpl}", file_wall / 1000.0, file_name.sub(Rails.root.to_s + '/', '')) + end output << "
" # .heading -- cgit v1.2.3