lib/rorvswild/plugin/middleware.rb in rorvswild-1.7.1 vs lib/rorvswild/plugin/middleware.rb in rorvswild-1.8.0

- old
+ new

@@ -16,11 +16,11 @@ def call(env) RorVsWild.agent.start_request RorVsWild.agent.current_data[:path] = env["ORIGINAL_FULLPATH"] section = RorVsWild::Section.start section.file, section.line = rails_engine_location - section.command = "Rails::Engine#call" + section.commands << "Rails::Engine#call" code, headers, body = @app.call(env) [code, headers, body] ensure RorVsWild::Section.stop inject_server_timing(RorVsWild.agent.stop_request, headers) @@ -33,25 +33,25 @@ end def format_server_timing_header(sections) sections.map do |section| if section.kind == "view" - "#{section.kind};dur=#{section.self_runtime};desc=\"#{section.file}\"" + "#{section.kind};dur=#{section.self_ms.round};desc=\"#{section.file}\"" else - "#{section.kind};dur=#{section.self_runtime};desc=\"#{section.file}:#{section.line}\"" + "#{section.kind};dur=#{section.self_ms.round};desc=\"#{section.file}:#{section.line}\"" end end.join(", ") end def format_server_timing_ascii(sections, total_width = 80) - max_time = sections.map(&:self_runtime).max + max_time = sections.map(&:self_ms).max chart_width = (total_width * 0.25).to_i rows = sections.map { |section| [ section.kind == "view" ? section.file : "#{section.file}:#{section.line}", - "█" * (section.self_runtime * (chart_width-1) / max_time), - "#{section.self_runtime}ms" + "█" * (section.self_ms * (chart_width-1) / max_time), + "%.1fms" % section.self_ms, ] } time_width = rows.map { |cols| cols[2].size }.max + 1 label_width = total_width - chart_width - time_width rows.each { |cols| cols[0] = truncate_backwards(cols[0], label_width) } @@ -63,10 +63,10 @@ string.size > width ? "…" + string[-(width - 1)..-1] : string end def inject_server_timing(data, headers) return if !data || !data[:send_server_timing] || !(sections = data[:sections]) - sections = sections.sort_by(&:self_runtime).reverse[0,10] + sections = sections.sort_by(&:self_ms).reverse[0,10] headers["Server-Timing"] = format_server_timing_header(sections) if data[:name] && RorVsWild.logger.level <= Logger::Severity::DEBUG RorVsWild.logger.debug(["┤ #{data[:name]} ├".center(80, "─"), format_server_timing_ascii(sections), "─" * 80, nil].join("\n")