The entry point to tracing APIs.

Summary

Public companion functions

TraceDriver
Cmn
android

Public constructors

TraceDriver(
    sink: AbstractTraceSink,
    isCategoryEnabled: (String) -> Boolean,
    attributes: (TraceAttributes.() -> Unit)?
)

Constructs a TraceDriver instance on the JVM.

android
TraceDriver(
    context: Context,
    sink: AbstractTraceSink,
    isCategoryEnabled: (category: String) -> Boolean,
    attributes: (TraceAttributes.() -> Unit)?
)

Constructs a TraceDriver instance on Android based on the provided Context instance.

android

Public functions

open Unit

Flushes all outstanding packets to the AbstractTraceSink and then closes the AbstractTraceSink.

android
open Unit

Flushes all outstanding packets to the AbstractTraceSink and then closes the AbstractTraceSink.

android
open Unit

Flushes the trace packets into the underlying AbstractTraceSink.

android
open Unit

Flushes the trace packets into the underlying AbstractTraceSink.

android

Public properties

open Tracer

Return an instance of a Tracer that can be used to emit trace events.

android
open Tracer

Return an instance of a Tracer that can be used to emit trace events.

android

Inherited functions

From androidx.tracing.AbstractTraceDriver
abstract Unit

Flushes all outstanding packets to the AbstractTraceSink and then closes the AbstractTraceSink.

Cmn
abstract Unit

Flushes the trace packets into the underlying AbstractTraceSink.

Cmn

Inherited properties

From androidx.tracing.AbstractTraceDriver
AbstractTraceSink

The AbstractTraceSink that asynchronously serializes trace events to a file or buffer, depending on implementation.

android
AbstractTraceSink

The AbstractTraceSink that asynchronously serializes trace events to a file or buffer, depending on implementation.

Cmn
AbstractTraceSink

The AbstractTraceSink that asynchronously serializes trace events to a file or buffer, depending on implementation.

android
abstract Tracer

Return an instance of a Tracer that can be used to emit trace events.

Cmn

Public companion functions

getStubTraceDriver

@<error>
fun getStubTraceDriver(): TraceDriver
Returns
TraceDriver

a TraceDriver instance that is a stub (does nothing). This is useful as a placeholder when you want to enable / disable tracing for the program.

Effectively, this uses a androidx.tracing.Tracer that drops all trace packets. To get a stub tracer, you can also use the androidx.tracing.Tracer.getStubTracer API.

Public constructors

TraceDriver

TraceDriver(
    sink: AbstractTraceSink,
    isCategoryEnabled: (String) -> Boolean = { true },
    attributes: (TraceAttributes.() -> Unit)? = null
)

Constructs a TraceDriver instance on the JVM.

Parameters
sink: AbstractTraceSink

The TraceSink instance.

isCategoryEnabled: (String) -> Boolean = { true }

returns true if the provided trace category should be enabled. If false then trace events corresponding to the category are dropped to reduce tracing overhead. This is particularly useful when you want to lower the overhead of trace events from uninteresting or noisy categories.

attributes: (TraceAttributes.() -> Unit)? = null

Collection of key value pairs to be attached to a trace to provide additional context about any facet of the trace. This can include what data it contains, and properties of the host / machine the trace was collected on, and other interesting information about a trace.

Examples include:

gradle_version = "9.0.10-alpha01"
java_major_version = 24

TraceDriver

TraceDriver(
    context: Context,
    sink: AbstractTraceSink,
    isCategoryEnabled: (category: String) -> Boolean = { Trace.isEnabled() },
    attributes: (TraceAttributes.() -> Unit)? = null
)

Constructs a TraceDriver instance on Android based on the provided Context instance.

Parameters
context: Context

The Android application Context.

sink: AbstractTraceSink

The TraceSink instance.

isCategoryEnabled: (category: String) -> Boolean = { Trace.isEnabled() }

returns true if the provided trace category should be enabled. If false then trace events corresponding to the category are dropped to reduce tracing overhead. This is particularly useful when you want to lower the overhead of trace events from uninteresting or noisy categories. The default implementation of this check allows all trace categories as long as a Perfetto tracing session is active (Trace.isEnabled).

Note:This method should be extremely low overhead given it's called every time a Tracer can emit trace events.

attributes: (TraceAttributes.() -> Unit)? = null

Collection of key value pairs to be attached to a trace to provide additional context about any facet of the trace. This can include what data it contains, and properties of the host / machine the trace was collected on, and other interesting information about a trace. At the end of the attributes block, these key value pairs are dispatched to the designated AbstractTraceSink to be serialized.

Examples include:

gradle_version = "9.0.10-alpha01"
java_major_version = 24

Public functions

close

open fun close(): Unit

Flushes all outstanding packets to the AbstractTraceSink and then closes the AbstractTraceSink.

close

open fun close(): Unit

Flushes all outstanding packets to the AbstractTraceSink and then closes the AbstractTraceSink.

flush

open fun flush(): Unit

Flushes the trace packets into the underlying AbstractTraceSink.

flush

open fun flush(): Unit

Flushes the trace packets into the underlying AbstractTraceSink.

Public properties

tracer

open val tracerTracer

Return an instance of a Tracer that can be used to emit trace events.

tracer

open val tracerTracer

Return an instance of a Tracer that can be used to emit trace events.