InMemoryRingBufferTraceSink



A TraceSink that stores TraceEvents in a fixed-size ring buffer to minimize allocations.

This buffer is designed to hold trace events temporarily before they are flushed. When the buffer is full, it overwrites the oldest events.

A standard flush or close will simply clear the buffer and drop the events. To persist the trace data, you must provide a BufferedSink by calling flushTo or closeAndFlushTo.

This implementation converts androidx.tracing.TraceEvents into binary protos using the Wire library.

Summary

Public constructors

InMemoryRingBufferTraceSink(
    sequenceId: @IntRange(from = 1) Int,
    capacityInBytes: Long
)
Cmn

Public functions

open Unit

Marks the InMemoryRingBufferTraceSink as closed and clears any remaining buffered events without writing them out.

Cmn
Unit

Marks the InMemoryRingBufferTraceSink as closed and flushes the remaining buffered events to the provided BufferedSink but does not close it.

Cmn
open Unit
enqueue(pooledPacketArray: PooledTracePacketArray)

Enqueue a PooledTracePacketArray to be written to the trace.

Cmn
open Unit

Clears the current buffer and drops the events without writing them out.

Cmn
Unit
flushTo(bufferedSink: BufferedSink)

Flushes the current buffer to the provided BufferedSink.

Cmn
open Unit

Called when the TraceSink cannot keep up with incoming trace events from Tracks.

Cmn

Public constructors

InMemoryRingBufferTraceSink

InMemoryRingBufferTraceSink(
    sequenceId: @IntRange(from = 1) Int,
    capacityInBytes: Long
)

Public functions

close

open fun close(): Unit

Marks the InMemoryRingBufferTraceSink as closed and clears any remaining buffered events without writing them out.

closeAndFlushTo

fun closeAndFlushTo(bufferedSink: BufferedSink): Unit

Marks the InMemoryRingBufferTraceSink as closed and flushes the remaining buffered events to the provided BufferedSink but does not close it.

enqueue

open fun enqueue(pooledPacketArray: PooledTracePacketArray): Unit

Enqueue a PooledTracePacketArray to be written to the trace.

This function may be called from any thread.

flush

open fun flush(): Unit

Clears the current buffer and drops the events without writing them out.

flushTo

fun flushTo(bufferedSink: BufferedSink): Unit

Flushes the current buffer to the provided BufferedSink.

This writes out the ring buffer's contents to the sink and then clears the ring buffer.

onDroppedTraceEvent

open fun onDroppedTraceEvent(): Unit

Called when the TraceSink cannot keep up with incoming trace events from Tracks.

This function may be called from any thread.