Class: CpuInspectCore::Store
- Inherits:
-
Object
- Object
- CpuInspectCore::Store
- Includes:
- MonitorMixin
- Defined in:
- lib/cpu_inspect_core/store.rb
Overview
Thread-safe ring buffer holding the most recent CPU samples. Uses MonitorMixin (reentrant) rather than Mutex so that calling CpuInspectCore.status from within a synchronized block doesn’t deadlock.
Instance Method Summary collapse
-
#initialize(capacity: 1) ⇒ Store
constructor
A new instance of Store.
- #latest ⇒ Object
- #push(data) ⇒ Object
Constructor Details
#initialize(capacity: 1) ⇒ Store
Returns a new instance of Store.
12 13 14 15 16 |
# File 'lib/cpu_inspect_core/store.rb', line 12 def initialize(capacity: 1) super() @capacity = capacity @samples = [] end |
Instance Method Details
#latest ⇒ Object
25 26 27 |
# File 'lib/cpu_inspect_core/store.rb', line 25 def latest synchronize { @samples.last } end |
#push(data) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/cpu_inspect_core/store.rb', line 18 def push(data) synchronize do @samples << data @samples.shift if @samples.size > @capacity end end |