Interface IMetricWriter
Writer interface for zero-allocation metric collection during snapshot operations.
public interface IMetricWriter
Remarks
Implementations buffer values internally in pre-allocated structures. The resource graph provides a writer instance during snapshot collection, and metric sources write their current values to it.
The writer pattern avoids allocations by having sources write to a buffer rather than returning metric objects. This keeps the snapshot path allocation-free.
For methods that can be called multiple times (WriteThroughput, WriteDuration), each call appends to an internal list. For fixed methods (WriteMemory, WriteCapacity, etc.), the last call wins if called multiple times.
Methods
WriteCapacity(long, long)
Reports capacity utilization metrics for this node.
void WriteCapacity(long current, long maximum)
Parameters
Remarks
Utilization (current / maximum) is computed by the snapshot builder, not by the writer. This keeps ReadMetrics fast (no division).
WriteDiskIO(long, long, long, long)
Reports disk I/O metrics for this node.
void WriteDiskIO(long readOps, long writeOps, long readBytes, long writeBytes)
Parameters
readOpslongNumber of read operations (counter).
writeOpslongNumber of write operations (counter).
readByteslongTotal bytes read (counter).
writeByteslongTotal bytes written (counter).
WriteDuration(string, long, long, long)
Reports a named duration metric.
void WriteDuration(string name, long lastUs, long avgUs, long maxUs)
Parameters
namestringOperation name (e.g., "Checkpoint", "GroupCommit"). Must be a static string.
lastUslongDuration of the most recent operation in microseconds.
avgUslongExponential moving average in microseconds.
maxUslongLongest operation observed (high-water mark).
Remarks
Call multiple times for multiple duration types. Use static strings only to maintain zero-allocation — avoid string interpolation.
WriteMemory(long, long)
Reports memory allocation metrics for this node.
void WriteMemory(long allocatedBytes, long peakBytes)
Parameters
allocatedByteslongCurrent live allocation in bytes.
peakByteslongMaximum allocation ever observed (high-water mark).
WriteThroughput(string, long)
Reports a named throughput counter.
void WriteThroughput(string name, long count)
Parameters
namestringCounter name (e.g., "CacheHits", "Commits"). Must be a static string.
countlongTotal operations since startup (monotonically increasing).
Remarks
Call multiple times for multiple counters (e.g., "Lookups", "Inserts"). Use static strings only to maintain zero-allocation — avoid string interpolation.