Module: Polyrun::Timing::VarianceReport
- Defined in:
- lib/polyrun/timing/variance_report.rb
Overview
Flags high-variance, flaky, and regression timing entries.
Class Method Summary collapse
-
.analyze(merged_stats) ⇒ Object
rubocop:disable Metrics/AbcSize -- variance flag scan.
-
.emit_warnings!(merged_stats) ⇒ Object
rubocop:enable Metrics/AbcSize.
- .format_report(merged_stats) ⇒ Object
Class Method Details
.analyze(merged_stats) ⇒ Object
rubocop:disable Metrics/AbcSize -- variance flag scan
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/polyrun/timing/variance_report.rb', line 8 def analyze(merged_stats) flags = [] merged_stats.each do |path, entry| h = Stats.normalize_entry(entry) next if h["runs"] < 2 median = h["mean"] if median.positive? && (h["p95"] / median) > 2.0 flags << {path: path, kind: "high_variance", detail: "p95/mean=#{format("%.2f", h["p95"] / median)}"} end if h["runs"] >= 3 && (h["failures"].to_f / h["runs"]) > 0.3 flags << {path: path, kind: "often_failed", detail: "failures=#{h["failures"]}/#{h["runs"]}"} end if h["timeouts"].to_i >= 2 flags << {path: path, kind: "timeout_cluster", detail: "timeouts=#{h["timeouts"]}"} end if h["mean"].positive? && h["last_seconds"] > (2.0 * h["mean"]) flags << {path: path, kind: "runtime_regression", detail: "last=#{h["last_seconds"]} mean=#{h["mean"]}"} end end flags end |
.emit_warnings!(merged_stats) ⇒ Object
rubocop:enable Metrics/AbcSize
35 36 37 38 39 |
# File 'lib/polyrun/timing/variance_report.rb', line 35 def emit_warnings!(merged_stats) analyze(merged_stats).each do |f| Polyrun::Log.warn "polyrun timing #{f[:kind]}: #{f[:path]} (#{f[:detail]})" end end |
.format_report(merged_stats) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/polyrun/timing/variance_report.rb', line 41 def format_report(merged_stats) lines = ["Polyrun timing variance report", ""] analyze(merged_stats).each do |f| lines << " [#{f[:kind]}] #{f[:path]} — #{f[:detail]}" end lines << " (none)" if lines.size == 2 lines.join("\n") + "\n" end |