Module: Perfgate::Report::Console
- Defined in:
- lib/perfgate/report/console.rb
Overview
Renders the schema_version 1 comparison-result document (plus its Policy::Engine verdict) as the plain-text console summary from spec 20.1: overall decision, run identities, a per-workload/ per-metric table with a "likely signal" diagnostic line, compatibility status, and sample counts.
Constant Summary collapse
- DURATION_METRICS =
%w[duration sql_duration].freeze
- METRIC_LABELS =
{ "duration" => "Duration", "sql_count" => "SQL queries", "sql_duration" => "SQL duration", "allocations" => "Allocations" }.freeze
Class Method Summary collapse
- .diagnostics_lines(workload) ⇒ Object
- .format_value(name, value) ⇒ Object
- .metric_line(name, metric) ⇒ Object
- .render(comparison_result:, policy_result:) ⇒ Object
- .workload_lines(workload) ⇒ Object
Class Method Details
.diagnostics_lines(workload) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/perfgate/report/console.rb', line 49 def diagnostics_lines(workload) = workload["diagnostics"] || [] return [] if .empty? [" Likely signal:"] + .map { || " #{}" } end |
.format_value(name, value) ⇒ Object
43 44 45 46 47 |
# File 'lib/perfgate/report/console.rb', line 43 def format_value(name, value) return "n/a" if value.nil? DURATION_METRICS.include?(name) ? format("%.0f ms", value / 1_000_000.0) : value.to_s end |
.metric_line(name, metric) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/perfgate/report/console.rb', line 34 def metric_line(name, metric) label = METRIC_LABELS.fetch(name, name) before = format_value(name, metric["baseline_median"]) after = format_value(name, metric["candidate_median"]) change = metric["change_percent"] ? format("%+.1f%%", metric["change_percent"]) : "n/a" format(" %<label>-15s %<before>s \u2192 %<after>s %<change>s %<decision>s", label: label, before: before, after: after, change: change, decision: metric["decision"].upcase) end |
.render(comparison_result:, policy_result:) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/perfgate/report/console.rb', line 17 def render(comparison_result:, policy_result:) lines = ["Baseline Performance Assurance", "", "Overall: #{policy_result["status"].upcase}", "Baseline: #{comparison_result["baseline_run_id"]}", "Candidate: #{comparison_result["candidate_run_id"]}", ""] comparison_result.fetch("workloads", []).each { |workload| lines.concat(workload_lines(workload)) } lines << "Compatibility: #{comparison_result.dig("compatibility", "status")}" lines.join("\n") end |
.workload_lines(workload) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/perfgate/report/console.rb', line 26 def workload_lines(workload) marker = workload["decision"] == "pass" ? "\u2713" : "\u2717" lines = ["#{marker} #{workload["id"]}"] workload["metrics"].each { |name, metric| lines << metric_line(name, metric) } lines.concat(diagnostics_lines(workload)) lines << "" end |