Class: HeapScope::Scorecard
- Inherits:
-
Object
- Object
- HeapScope::Scorecard
- Defined in:
- lib/heapscope/scorecard.rb
Overview
Compact executive summary for CI logs and consoles.
Instance Attribute Summary collapse
-
#finding_codes ⇒ Object
readonly
Returns the value of attribute finding_codes.
-
#healthy ⇒ Object
readonly
Returns the value of attribute healthy.
-
#live_delta ⇒ Object
readonly
Returns the value of attribute live_delta.
-
#retention_ratio ⇒ Object
readonly
Returns the value of attribute retention_ratio.
-
#rss_delta ⇒ Object
readonly
Returns the value of attribute rss_delta.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#top_suspects ⇒ Object
readonly
Returns the value of attribute top_suspects.
-
#verdict ⇒ Object
readonly
Returns the value of attribute verdict.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(**attrs) ⇒ Scorecard
constructor
A new instance of Scorecard.
- #to_h ⇒ Object
- #to_text ⇒ Object
Constructor Details
#initialize(**attrs) ⇒ Scorecard
Returns a new instance of Scorecard.
47 48 49 |
# File 'lib/heapscope/scorecard.rb', line 47 def initialize(**attrs) attrs.each { |k, v| instance_variable_set("@#{k}", v) } end |
Instance Attribute Details
#finding_codes ⇒ Object (readonly)
Returns the value of attribute finding_codes.
31 32 33 |
# File 'lib/heapscope/scorecard.rb', line 31 def finding_codes @finding_codes end |
#healthy ⇒ Object (readonly)
Returns the value of attribute healthy.
31 32 33 |
# File 'lib/heapscope/scorecard.rb', line 31 def healthy @healthy end |
#live_delta ⇒ Object (readonly)
Returns the value of attribute live_delta.
31 32 33 |
# File 'lib/heapscope/scorecard.rb', line 31 def live_delta @live_delta end |
#retention_ratio ⇒ Object (readonly)
Returns the value of attribute retention_ratio.
31 32 33 |
# File 'lib/heapscope/scorecard.rb', line 31 def retention_ratio @retention_ratio end |
#rss_delta ⇒ Object (readonly)
Returns the value of attribute rss_delta.
31 32 33 |
# File 'lib/heapscope/scorecard.rb', line 31 def rss_delta @rss_delta end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
31 32 33 |
# File 'lib/heapscope/scorecard.rb', line 31 def title @title end |
#top_suspects ⇒ Object (readonly)
Returns the value of attribute top_suspects.
31 32 33 |
# File 'lib/heapscope/scorecard.rb', line 31 def top_suspects @top_suspects end |
#verdict ⇒ Object (readonly)
Returns the value of attribute verdict.
31 32 33 |
# File 'lib/heapscope/scorecard.rb', line 31 def verdict @verdict end |
Class Method Details
.from_report(report, title: "HeapScope") ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/heapscope/scorecard.rb', line 34 def self.from_report(report, title: "HeapScope") new( title: title, healthy: report.healthy?, verdict: report.healthy? ? "HEALTHY" : "ATTENTION", rss_delta: report.diff&.rss_delta, live_delta: report.diff&.heap_live_delta, retention_ratio: report.diff&.retention_ratio, top_suspects: Array(report.suspects).first(3).map { |s| "#{s[:name]}(+#{s[:delta_count]}/#{s[:severity]})" }, finding_codes: report.findings.map { |f| "#{f.code}:#{f.severity}" } ) end |
Instance Method Details
#to_h ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/heapscope/scorecard.rb', line 51 def to_h { title: title, verdict: verdict, healthy: healthy, rss_delta: rss_delta, live_delta: live_delta, retention_ratio: retention_ratio, top_suspects: top_suspects, finding_codes: finding_codes } end |
#to_text ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/heapscope/scorecard.rb', line 64 def to_text lines = [] lines << "┌─ HeapScope scorecard ─────────────────────────" lines << "│ #{title}" lines << "│ Verdict: #{verdict}" lines << "│ RSS Δ: #{fmt_bytes(rss_delta)} Live slots Δ: #{live_delta || 'n/a'}" lines << "│ Retention: #{retention_ratio ? format('%.2f%%', retention_ratio * 100) : 'n/a'}" lines << "│ Suspects: #{top_suspects.empty? ? 'none' : top_suspects.join(', ')}" lines << "│ Findings: #{finding_codes.empty? ? 'none' : finding_codes.join(', ')}" lines << "└───────────────────────────────────────────────" lines.join("\n") end |