Module: Polyrun::Timing::Summary

Defined in:
lib/polyrun/timing/summary.rb

Overview

Human-readable slow-file list from merged timing JSON (per-file cost).

Class Method Summary collapse

Class Method Details

.format_slow_files(merged, top: 30, title: "Polyrun slowest files (by wall time, seconds)") ⇒ Object

merged is path (String) => seconds (Float), as produced by Timing::Merge.merge_files.



8
9
10
11
12
13
14
15
16
17
# File 'lib/polyrun/timing/summary.rb', line 8

def format_slow_files(merged, top: 30, title: "Polyrun slowest files (by wall time, seconds)")
  return "#{title}\n  (no data)\n" if merged.nil? || merged.empty?

  pairs = merged.sort_by { |_, sec| -sec.to_f }.first(Integer(top))
  lines = [title, ""]
  pairs.each_with_index do |(path, sec), i|
    lines << format("  %2d. %s  %.4f", i + 1, path, sec.to_f)
  end
  lines.join("\n") + "\n"
end

.write_file(merged, path, **kwargs) ⇒ Object



19
20
21
22
# File 'lib/polyrun/timing/summary.rb', line 19

def write_file(merged, path, **kwargs)
  File.write(path, format_slow_files(merged, **kwargs))
  path
end