public final class TraceDriver extends AbstractTraceDriver


The entry point to tracing APIs.

Summary

Nested types

public static class TraceDriver.Companion

Public constructors

TraceDriver(
    @NonNull AbstractTraceSink sink,
    @NonNull Function1<@NonNull String, @NonNull Boolean> isCategoryEnabled,
    Function1<@NonNull TraceAttributesUnit> attributes
)

Constructs a TraceDriver instance on the JVM.

TraceDriver(
    @NonNull Context context,
    @NonNull AbstractTraceSink sink,
    @NonNull Function1<@NonNull String, @NonNull Boolean> isCategoryEnabled,
    Function1<@NonNull TraceAttributesUnit> attributes
)

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

Public methods

void

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

void

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

void

Flushes the trace packets into the underlying AbstractTraceSink.

void

Flushes the trace packets into the underlying AbstractTraceSink.

@NonNull Tracer

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

@NonNull Tracer

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

Inherited methods

From androidx.tracing.AbstractTraceDriver
abstract void

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

abstract void

Flushes the trace packets into the underlying AbstractTraceSink.

final @NonNull AbstractTraceSink

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

final @NonNull AbstractTraceSink

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

final @NonNull AbstractTraceSink

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

abstract @NonNull Tracer

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

Public constructors

TraceDriver

public TraceDriver(
    @NonNull AbstractTraceSink sink,
    @NonNull Function1<@NonNull String, @NonNull Boolean> isCategoryEnabled,
    Function1<@NonNull TraceAttributesUnit> attributes
)

Constructs a TraceDriver instance on the JVM.

Parameters
@NonNull AbstractTraceSink sink

The TraceSink instance.

@NonNull Function1<@NonNull String, @NonNull Boolean> isCategoryEnabled

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.

Function1<@NonNull TraceAttributesUnit> attributes

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

Added in 2.0.0-alpha07
public TraceDriver(
    @NonNull Context context,
    @NonNull AbstractTraceSink sink,
    @NonNull Function1<@NonNull String, @NonNull Boolean> isCategoryEnabled,
    Function1<@NonNull TraceAttributesUnit> attributes
)

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

Parameters
@NonNull Context context

The Android application Context.

@NonNull AbstractTraceSink sink

The TraceSink instance.

@NonNull Function1<@NonNull String, @NonNull Boolean> isCategoryEnabled

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.

Function1<@NonNull TraceAttributesUnit> attributes

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 methods

close

Added in 2.0.0-alpha07
public void close()

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

close

Added in 2.0.0-alpha07
public void close()

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

flush

Added in 2.0.0-alpha07
public void flush()

Flushes the trace packets into the underlying AbstractTraceSink.

flush

Added in 2.0.0-alpha07
public void flush()

Flushes the trace packets into the underlying AbstractTraceSink.

getTracer

Added in 2.0.0-alpha07
public @NonNull Tracer getTracer()

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

getTracer

Added in 2.0.0-alpha07
public @NonNull Tracer getTracer()

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