Class: Ignis::Memory::Stats
- Inherits:
-
Object
- Object
- Ignis::Memory::Stats
- Defined in:
- lib/nvruby/memory/stats.rb
Overview
Thread-safe allocation statistics tracking Provides real-time visibility into memory usage patterns
Class Method Summary collapse
-
.allocation_count ⇒ Integer
Total allocation count since startup.
-
.deallocation_count ⇒ Integer
Total deallocation count since startup.
-
.peak_allocated_bytes ⇒ Integer
Peak bytes allocated (high-water mark).
-
.record_allocation(bytes) ⇒ void
Record an allocation.
-
.record_deallocation(bytes) ⇒ void
Record a deallocation.
-
.reset! ⇒ void
Reset all statistics.
-
.snapshot ⇒ Hash
Statistics snapshot.
-
.to_s ⇒ String
Human-readable statistics.
-
.total_allocated_bytes ⇒ Integer
Total bytes currently allocated.
Class Method Details
.allocation_count ⇒ Integer
Returns Total allocation count since startup.
20 21 22 |
# File 'lib/nvruby/memory/stats.rb', line 20 def allocation_count @allocation_count ||= 0 end |
.deallocation_count ⇒ Integer
Returns Total deallocation count since startup.
25 26 27 |
# File 'lib/nvruby/memory/stats.rb', line 25 def deallocation_count @deallocation_count ||= 0 end |
.peak_allocated_bytes ⇒ Integer
Returns Peak bytes allocated (high-water mark).
15 16 17 |
# File 'lib/nvruby/memory/stats.rb', line 15 def peak_allocated_bytes @peak_allocated_bytes ||= 0 end |
.record_allocation(bytes) ⇒ void
This method returns an undefined value.
Record an allocation
32 33 34 35 36 37 38 |
# File 'lib/nvruby/memory/stats.rb', line 32 def record_allocation(bytes) mutex.synchronize do @total_allocated_bytes = (total_allocated_bytes + bytes) @peak_allocated_bytes = [@peak_allocated_bytes || 0, @total_allocated_bytes].max @allocation_count = (allocation_count + 1) end end |
.record_deallocation(bytes) ⇒ void
This method returns an undefined value.
Record a deallocation
43 44 45 46 47 48 |
# File 'lib/nvruby/memory/stats.rb', line 43 def record_deallocation(bytes) mutex.synchronize do @total_allocated_bytes = [total_allocated_bytes - bytes, 0].max @deallocation_count = (deallocation_count + 1) end end |
.reset! ⇒ void
This method returns an undefined value.
Reset all statistics
52 53 54 55 56 57 58 59 |
# File 'lib/nvruby/memory/stats.rb', line 52 def reset! mutex.synchronize do @total_allocated_bytes = 0 @peak_allocated_bytes = 0 @allocation_count = 0 @deallocation_count = 0 end end |
.snapshot ⇒ Hash
Returns Statistics snapshot.
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/nvruby/memory/stats.rb', line 62 def snapshot mutex.synchronize do { total_allocated_bytes: total_allocated_bytes, peak_allocated_bytes: peak_allocated_bytes, allocation_count: allocation_count, deallocation_count: deallocation_count, active_allocations: allocation_count - deallocation_count } end end |
.to_s ⇒ String
Returns Human-readable statistics.
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/nvruby/memory/stats.rb', line 75 def to_s s = snapshot format( "Memory Stats: %s allocated (peak: %s), %d allocs, %d frees, %d active", format_bytes(s[:total_allocated_bytes]), format_bytes(s[:peak_allocated_bytes]), s[:allocation_count], s[:deallocation_count], s[:active_allocations] ) end |
.total_allocated_bytes ⇒ Integer
Returns Total bytes currently allocated.
10 11 12 |
# File 'lib/nvruby/memory/stats.rb', line 10 def total_allocated_bytes @total_allocated_bytes ||= 0 end |