pub struct PoolStatsTracker { /* private fields */ }Expand description
Thread-safe allocation tracking for memory pools.
Uses an RwLock-protected inner state so that multiple readers can
snapshot stats concurrently while mutations are serialized.
Implementations§
Source§impl PoolStatsTracker
impl PoolStatsTracker
Sourcepub fn record_alloc(&self, size: usize)
pub fn record_alloc(&self, size: usize)
Records an allocation of size bytes.
Updates allocated_bytes, peak_bytes, allocation_count, and the
histogram.
Sourcepub fn record_free(&self, size: usize)
pub fn record_free(&self, size: usize)
Records a deallocation of size bytes.
Updates allocated_bytes and free_count.
Sourcepub fn snapshot(&self) -> PoolReport
pub fn snapshot(&self) -> PoolReport
Takes a snapshot of current stats as a PoolReport.
The fragmentation field is set to default values since this tracker
does not have visibility into the free-list structure.
Sourcepub fn current_allocated(&self) -> usize
pub fn current_allocated(&self) -> usize
Returns the current number of allocated bytes.
Sourcepub fn peak_allocated(&self) -> usize
pub fn peak_allocated(&self) -> usize
Returns the peak number of allocated bytes.
Sourcepub fn trim(&self) -> usize
pub fn trim(&self) -> usize
Trims the pool: simulates cuMemPoolTrimTo, releasing all freed
(outstanding) allocations back to the system.
Returns the number of bytes that were outstanding and are now released.
After trim, current_allocated() is set to 0 and is_fully_trimmed()
returns true.
In a real GPU pool (cuMemPoolTrimTo), this releases pool memory pages
back to the OS. Here we track the logical accounting: after all frees
have been recorded via PoolStatsTracker::record_free, trim marks the remaining
outstanding bytes as released.
Sourcepub fn is_fully_trimmed(&self) -> bool
pub fn is_fully_trimmed(&self) -> bool
Returns true when there are no outstanding allocations — i.e.,
every allocated byte has been freed (and optionally trimmed).
Equivalent to current_allocated() == 0.