Class MemoryStatistics
- Namespace
- DotCompute.Memory
- Assembly
- DotCompute.Memory.dll
CONSOLIDATED memory usage and performance statistics. This replaces all duplicate MemoryStatistics implementations across the codebase.
Provides comprehensive tracking for:
- Allocation and deallocation counts
- Memory usage (current, peak, total)
- Pool efficiency metrics
- Performance timing data
- Error and failure statistics
public sealed class MemoryStatistics
- Inheritance
-
MemoryStatistics
- Inherited Members
Properties
ActiveAllocations
Gets the number of active allocations (allocations - deallocations).
public long ActiveAllocations { get; }
Property Value
AverageAllocationSize
Gets the average allocation size in bytes.
public double AverageAllocationSize { get; }
Property Value
AverageAllocationTime
Gets the average time taken for allocation operations in milliseconds.
public double AverageAllocationTime { get; }
Property Value
AverageCopyTime
Gets the average time taken for copy operations in milliseconds.
public double AverageCopyTime { get; }
Property Value
AverageDeallocationTime
Gets the average time taken for deallocation operations in milliseconds.
public double AverageDeallocationTime { get; }
Property Value
CopyOperations
Gets the total number of copy operations performed.
public long CopyOperations { get; }
Property Value
CurrentlyAllocatedBytes
Gets the number of bytes currently allocated and not yet freed.
public long CurrentlyAllocatedBytes { get; }
Property Value
FailedAllocations
Gets the number of failed allocation attempts.
public long FailedAllocations { get; }
Property Value
MemoryEfficiency
Gets the memory efficiency ratio (bytes freed / bytes allocated). A value of 1.0 indicates all allocated memory has been freed.
public double MemoryEfficiency { get; }
Property Value
PeakAllocatedBytes
Gets the peak number of bytes allocated at any point in time.
public long PeakAllocatedBytes { get; }
Property Value
PoolHitRate
Gets the memory pool hit rate (percentage of allocations satisfied by the pool).
public double PoolHitRate { get; }
Property Value
PoolHits
Gets the number of allocations satisfied by the memory pool.
public long PoolHits { get; }
Property Value
PoolMisses
Gets the number of allocations that could not be satisfied by the memory pool.
public long PoolMisses { get; }
Property Value
TotalAllocations
Gets the total number of allocation operations performed.
public long TotalAllocations { get; }
Property Value
TotalBytesAllocated
Gets the total number of bytes that have been allocated (cumulative).
public long TotalBytesAllocated { get; }
Property Value
TotalBytesFreed
Gets the total number of bytes that have been freed (cumulative).
public long TotalBytesFreed { get; }
Property Value
TotalDeallocations
Gets the total number of deallocation operations performed.
public long TotalDeallocations { get; }
Property Value
Methods
CreateSnapshot()
Creates a snapshot of the current statistics. This is useful for reporting without affecting the ongoing statistics collection.
public MemoryStatistics CreateSnapshot()
Returns
- MemoryStatistics
A new MemoryStatistics instance containing the current values.
RecordAllocation(long, double, bool)
Records a successful allocation operation.
public void RecordAllocation(long bytes, double timeMs, bool fromPool)
Parameters
byteslongThe number of bytes allocated.
timeMsdoubleThe time taken for the allocation in milliseconds.
fromPoolboolWhether the allocation was satisfied by the memory pool.
RecordBufferCreation(long)
Records buffer creation (for tracking buffer lifecycle).
public static void RecordBufferCreation(long bytes)
Parameters
byteslongThe size of the buffer created.
RecordCopyOperation(long, double, bool)
Records a memory copy operation.
public void RecordCopyOperation(long bytes, double timeMs, bool isHostToDevice)
Parameters
byteslongThe number of bytes copied.
timeMsdoubleThe time taken for the copy operation in milliseconds.
isHostToDeviceboolWhether this was a host-to-device transfer.
RecordDeallocation(long, double)
Records a successful deallocation operation.
public void RecordDeallocation(long bytes, double timeMs = 0)
Parameters
byteslongThe number of bytes deallocated.
timeMsdoubleThe time taken for the deallocation in milliseconds (optional).
RecordFailedAllocation(long)
Records a failed allocation attempt.
public void RecordFailedAllocation(long requestedBytes)
Parameters
requestedByteslongThe number of bytes that were requested but could not be allocated.
Reset()
Resets all statistics to zero. Use with caution as this will clear all historical data.
public void Reset()
ToDetailedString()
Gets detailed statistics for diagnostic purposes.
public string ToDetailedString()
Returns
- string
A detailed string representation of all statistics.
ToString()
Gets a summary of the current memory statistics.
public override string ToString()
Returns
- string
A formatted string containing key statistics.