module Peek module Rblineprof module CustomControllerHelpers extend ActiveSupport::Concern # This will become useless once https://github.com/peek/peek-rblineprof/pull/5 # is merged def pygmentize(file_name, code, lexer = nil) if lexer.present? Gitlab::Highlight.highlight(file_name, code) else "
#{Rack::Utils.escape_html(code)}" end end # rubocop:disable all def inject_rblineprof ret = nil profile = lineprof(rblineprof_profiler_regex) do ret = yield end if response.content_type =~ %r|text/html| sort = params[:lineprofiler_sort] mode = params[:lineprofiler_mode] || 'cpu' min = (params[:lineprofiler_min] || 5).to_i * 1000 summary = params[:lineprofiler_summary] # 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] wall = summary == 'exclusive' ? excl : total cpu = summary == 'exclusive' ? excl_cpu : total_cpu idle = summary == 'exclusive' ? (excl - excl_cpu) : (total - total_cpu) [ file, lines, wall, cpu, idle, sort == 'idle' ? idle : sort == 'cpu' ? cpu : wall ] end.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 << "
#{times.join("\n")}" # The following line was changed from # https://github.com/peek/peek-rblineprof/blob/8d3b7a283a27de2f40abda45974516693d882258/lib/peek/rblineprof/controller_helpers.rb#L125 # This will become useless once https://github.com/peek/peek-rblineprof/pull/16 # is merged and is implemented. output << "
#{pygmentize(file_name, code.join, 'ruby')}" output << "