Module: HeapScope::Notifications
- Defined in:
- lib/heapscope/notifications.rb
Overview
Optional ActiveSupport::Notifications adapter — not required in core.
Defined Under Namespace
Classes: GrowthProbe
Class Method Summary collapse
Class Method Details
.available? ⇒ Boolean
8 9 10 |
# File 'lib/heapscope/notifications.rb', line 8 def available? defined?(ActiveSupport::Notifications) end |
.subscriber_counts ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/heapscope/notifications.rb', line 12 def subscriber_counts raise CapabilityError, "ActiveSupport::Notifications not loaded" unless available? # Best-effort: AS does not always expose a public subscriber registry. # We sample notifier internals when present, otherwise return empty. notifier = ActiveSupport::Notifications.notifier counts = Hash.new(0) if notifier.respond_to?(:listeners_for) # Can't enumerate all patterns easily — return structure placeholder { note: "Use listen_growth to track specific patterns over time." } elsif notifier.instance_variable_defined?(:@subscribers) Array(notifier.instance_variable_get(:@subscribers)).each do |sub| pattern = begin sub.respond_to?(:pattern) ? sub.pattern : sub.class.name rescue StandardError "unknown" end counts[pattern.to_s] += 1 end counts else { note: "Subscriber registry not introspectable on this Rails version." } end end |