Class: HeapScope::Notifications::GrowthProbe
- Inherits:
-
Object
- Object
- HeapScope::Notifications::GrowthProbe
- Defined in:
- lib/heapscope/notifications.rb
Overview
Track a specific notification pattern count via wrapping — records samples.
Instance Method Summary collapse
- #finish ⇒ Object
-
#initialize(pattern) ⇒ GrowthProbe
constructor
A new instance of GrowthProbe.
- #sample! ⇒ Object
- #start! ⇒ Object
Constructor Details
#initialize(pattern) ⇒ GrowthProbe
Returns a new instance of GrowthProbe.
39 40 41 42 43 44 |
# File 'lib/heapscope/notifications.rb', line 39 def initialize(pattern) @pattern = pattern @samples = [] @count = 0 @sub = nil end |
Instance Method Details
#finish ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/heapscope/notifications.rb', line 59 def finish ActiveSupport::Notifications.unsubscribe(@sub) if @sub series = @samples trend = Growth.analyze(series) finding = if %i[monotonic_growth linear_growth exponential_like].include?(trend[:pattern]) Finding.new( code: "HS005", severity: :high, subject: @pattern.to_s, facts: ["Observed fact: notification #{@pattern} sample counts #{series.inspect}."], derived: ["Derived: pattern=#{trend[:pattern]}."], hypothesis: "Possible repeated registration without unsubscribe.", suggestions: ["Register subscribers once at boot", "Unsubscribe on teardown"] ) end { series: series, trend: trend, finding: finding } end |
#sample! ⇒ Object
53 54 55 56 57 |
# File 'lib/heapscope/notifications.rb', line 53 def sample! # Prefer explicit counter if subscribe block used; otherwise inventory @samples << (@_count || 0) @samples.last end |
#start! ⇒ Object
46 47 48 49 50 51 |
# File 'lib/heapscope/notifications.rb', line 46 def start! raise CapabilityError, "ActiveSupport::Notifications not loaded" unless Notifications.available? @sub = ActiveSupport::Notifications.subscribe(@pattern) { @_count = (@_count || 0) + 1 } self end |