InMemoryRingBufferTraceSink
A AbstractTraceSink 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 will do nothing. A 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( |
Cmn
|
Public functions |
||
|---|---|---|
open Unit |
close()Marks the |
Cmn
|
Unit |
closeAndFlushTo(bufferedSink: BufferedSink)Marks the |
Cmn
|
open Unit |
enqueue(pooledPacketArray: PooledTracePacketArray)Enqueue a |
Cmn
|
open Unit |
flush()Intentionally a no-op because we expect the caller to explicitly flush to a sink via |
Cmn
|
Unit |
flushTo(bufferedSink: BufferedSink)Flushes the current buffer to the provided |
Cmn
|
open Unit |
Called when the |
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
Intentionally a no-op because we expect the caller to explicitly flush to a sink via flushTo.
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 AbstractTraceSink cannot keep up with incoming trace events from Tracks.
This function may be called from any thread.