The trace sink that writes BufferedSink, to a new file per trace session.

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

The outputs created by WireTraceSync can be visualized with ui.perfetto.dev, and queried by TraceProcessor from the androidx.benchmark:benchmark-traceprocessor library, the C++ tool it's built on, or the Python wrapper.

As binary protos embed strings as UTF-8, note that any strings serialized by TraceSink will be serialized as UTF-8.

To create a TraceSink for a File, you can use File("myFile").appendingSink().buffer().

Summary

Public constructors

TraceSink(
    sequenceId: @IntRange(from = 1) Int,
    bufferedSink: BufferedSink,
    coroutineContext: CoroutineContext
)
Cmn

Public functions

open Unit

Close the AbstractTraceSink, completing any enqueued writes.

Cmn
open Unit
enqueue(pooledPacketArray: PooledTracePacketArray)

Enqueue a PooledTracePacketArray to be written to the trace.

Cmn
open Unit

Flush any enqueued trace events to the AbstractTraceSink.

Cmn
open Unit

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

Cmn

Public constructors

TraceSink

TraceSink(
    sequenceId: @IntRange(from = 1) Int,
    bufferedSink: BufferedSink,
    coroutineContext: CoroutineContext = NonCancellable + Dispatchers.IO
)

Public functions

close

open fun close(): Unit

Close the AbstractTraceSink, completing any enqueued writes.

This function may be called from any thread.

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

Flush any enqueued trace events to the AbstractTraceSink.

If the trace sink writes to persistent storage, this forces any buffered events to be written immediately. For in-memory sinks, this is typically a no-op because they do not have an underlying persistent storage destination by default.

This function may be called from any thread.

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.