Table of Contents

Class AppendOnlyChunkSink

Namespace
Typhon.Profiler
Assembly
Typhon.Profiler.dll

ICacheChunkSink implementation for live sessions: writes LZ4-compressed chunk bytes back-to-back to a caller-provided Stream (typically a temp file). No headers, no section table, no trailer — chunks only. The owning AttachSessionRuntime keeps the manifest in memory and serves chunks via offset+length lookups.

public sealed class AppendOnlyChunkSink : ICacheChunkSink, IDisposable
Inheritance
AppendOnlyChunkSink
Implements
Inherited Members

Remarks

This sink does NOT write a trailer (SupportsTrailer returns false). The builder calls WriteTrailer(IReadOnlyList<TickSummary>, in GlobalMetricsFixed, IReadOnlyList<SystemAggregateDuration>, IReadOnlyList<ChunkManifestEntry>, IReadOnlyDictionary<int, string>, ReadOnlySpan<byte>, in CacheHeader, IReadOnlyList<SystemTickSummary>, IReadOnlyList<QueueTickSummary>, IReadOnlyList<PostTickSummary>, IReadOnlyDictionary<ushort, string>, IReadOnlyList<SystemArchetypeTouchSummary>) only when this is true; live mode skips it. If a future feature wants to snapshot a live session as a sealed cache file, it can build a FileCacheSink alongside this one and stream-replay the chunks into it.

The sink is NOT thread-safe — the builder is the sole writer, on the AttachSessionRuntime's read loop thread.

Constructors

AppendOnlyChunkSink(Stream, bool)

Wrap a writable stream as a chunk sink.

public AppendOnlyChunkSink(Stream stream, bool ownsStream)

Parameters

stream Stream

Destination for compressed chunk bytes. Must be writable.

ownsStream bool

When true, Dispose() also disposes stream.

Exceptions

ArgumentNullException

stream is null.

ArgumentException

stream is not writable.

Properties

Position

The current write position in the underlying stream — equals total compressed bytes appended so far.

public long Position { get; }

Property Value

long

SupportsTrailer

True if this sink writes a trailer (TickSummaries / GlobalMetrics / ChunkManifest / SpanNameTable + cache header).

public bool SupportsTrailer { get; }

Property Value

bool

Remarks

Always false — live mode keeps trailer metadata in memory and never seals a trailer.

Methods

AppendChunk(ReadOnlySpan<byte>)

LZ4-compress and append a chunk's records to the sink's underlying storage. Returns the byte offset and lengths needed to populate the matching ChunkManifestEntry.

public (long CacheOffset, uint CompressedLength, uint UncompressedLength) AppendChunk(ReadOnlySpan<byte> uncompressedRecords)

Parameters

uncompressedRecords ReadOnlySpan<byte>

Returns

(long CacheOffset, uint CompressedLength, uint UncompressedLength)

Remarks

Flushes the stream after each append so a separate reader (the live chunk endpoint) can see the bytes immediately.

Exceptions

ArgumentException

uncompressedRecords is empty.

InvalidOperationException

LZ4 compression produced a non-positive length.

Dispose()

Flushes the stream a final time and, if this sink owns it, disposes it. Idempotent; never throws.

public void Dispose()

WriteTrailer(IReadOnlyList<TickSummary>, in GlobalMetricsFixed, IReadOnlyList<SystemAggregateDuration>, IReadOnlyList<ChunkManifestEntry>, IReadOnlyDictionary<int, string>, ReadOnlySpan<byte>, in CacheHeader, IReadOnlyList<SystemTickSummary>, IReadOnlyList<QueueTickSummary>, IReadOnlyList<PostTickSummary>, IReadOnlyDictionary<ushort, string>, IReadOnlyList<SystemArchetypeTouchSummary>)

public void WriteTrailer(IReadOnlyList<TickSummary> tickSummaries, in GlobalMetricsFixed globalMetrics, IReadOnlyList<SystemAggregateDuration> systemAggregates, IReadOnlyList<ChunkManifestEntry> chunkManifest, IReadOnlyDictionary<int, string> spanNames, ReadOnlySpan<byte> sourceMetadataBytes, in CacheHeader headerTemplate, IReadOnlyList<SystemTickSummary> systemTickSummaries, IReadOnlyList<QueueTickSummary> queueTickSummaries, IReadOnlyList<PostTickSummary> postTickSummaries, IReadOnlyDictionary<ushort, string> queueIdToName, IReadOnlyList<SystemArchetypeTouchSummary> systemArchetypeTouches)

Parameters

tickSummaries IReadOnlyList<TickSummary>
globalMetrics GlobalMetricsFixed
systemAggregates IReadOnlyList<SystemAggregateDuration>
chunkManifest IReadOnlyList<ChunkManifestEntry>
spanNames IReadOnlyDictionary<int, string>
sourceMetadataBytes ReadOnlySpan<byte>
headerTemplate CacheHeader
systemTickSummaries IReadOnlyList<SystemTickSummary>
queueTickSummaries IReadOnlyList<QueueTickSummary>
postTickSummaries IReadOnlyList<PostTickSummary>
queueIdToName IReadOnlyDictionary<ushort, string>
systemArchetypeTouches IReadOnlyList<SystemArchetypeTouchSummary>

Remarks

Not supported by the live sink — always throws NotSupportedException. Gate on SupportsTrailer.

Exceptions

NotSupportedException

Always — live mode keeps trailer metadata in memory.