# TraceDriver

Artifact: [androidx.tracing:tracing-wire](https://developer.android.com/jetpack/androidx/releases/tracing) [View Source](https://cs.android.com/search?q=file:androidx/tracing/wire/TraceDriver.+class:androidx.tracing.wire.TraceDriver) Added in [2.0.5](https://developer.android.com/jetpack/androidx/releases/tracing#2.0.5)

*** ** * ** ***


```
public final class TraceDriver extends AbstractTraceDriver
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||
| ↳ | [androidx.tracing.AbstractTraceDriver](https://developer.android.com/reference/androidx/tracing/AbstractTraceDriver) ||
|   | ↳ | [androidx.tracing.wire.TraceDriver](https://developer.android.com/reference/androidx/tracing/wire/TraceDriver) |

*** ** * ** ***

The entry point to tracing APIs.

## Summary

| ### Nested types |
|---|
| `public static class https://developer.android.com/reference/androidx/tracing/wire/TraceDriver.Companion` |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/tracing/wire/TraceDriver#TraceDriver(androidx.tracing.AbstractTraceSink,kotlin.Function1,kotlin.Function1)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/tracing/AbstractTraceSink sink, @https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Boolean.html> isCategoryEnabled, Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/tracing/TraceAttributes, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> attributes )` Constructs a `https://developer.android.com/reference/androidx/tracing/wire/TraceDriver` instance on the JVM. |
| `https://developer.android.com/reference/androidx/tracing/wire/TraceDriver#TraceDriver(android.content.Context,androidx.tracing.AbstractTraceSink,kotlin.Function1,kotlin.Function1)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/tracing/AbstractTraceSink sink, @https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Boolean.html> isCategoryEnabled, Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/tracing/TraceAttributes, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> attributes )` Constructs a `https://developer.android.com/reference/androidx/tracing/wire/TraceDriver` instance on Android based on the provided `https://developer.android.com/reference/android/content/Context.html` instance. |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/tracing/wire/TraceDriver#close()()` Flushes all outstanding packets to the `https://developer.android.com/reference/androidx/tracing/AbstractTraceSink` and then closes the `https://developer.android.com/reference/androidx/tracing/AbstractTraceSink`. |
| `void` | `https://developer.android.com/reference/androidx/tracing/wire/TraceDriver#close()()` Flushes all outstanding packets to the `https://developer.android.com/reference/androidx/tracing/AbstractTraceSink` and then closes the `https://developer.android.com/reference/androidx/tracing/AbstractTraceSink`. |
| `void` | `https://developer.android.com/reference/androidx/tracing/wire/TraceDriver#flush()()` Flushes the trace packets into the underlying `https://developer.android.com/reference/androidx/tracing/AbstractTraceSink`. |
| `void` | `https://developer.android.com/reference/androidx/tracing/wire/TraceDriver#flush()()` Flushes the trace packets into the underlying `https://developer.android.com/reference/androidx/tracing/AbstractTraceSink`. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/tracing/Tracer` | `https://developer.android.com/reference/androidx/tracing/wire/TraceDriver#getTracer()()` Return an instance of a `https://developer.android.com/reference/androidx/tracing/Tracer` that can be used to emit trace events. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/tracing/Tracer` | `https://developer.android.com/reference/androidx/tracing/wire/TraceDriver#getTracer()()` Return an instance of a `https://developer.android.com/reference/androidx/tracing/Tracer` that can be used to emit trace events. |

### Inherited methods

From [androidx.tracing.AbstractTraceDriver](https://developer.android.com/reference/androidx/tracing/AbstractTraceDriver) `abstract void` `https://developer.android.com/reference/androidx/tracing/AbstractTraceDriver#close()()`

Flushes all outstanding packets to the `https://developer.android.com/reference/androidx/tracing/AbstractTraceSink` and then closes the `https://developer.android.com/reference/androidx/tracing/AbstractTraceSink`.
`abstract void` `https://developer.android.com/reference/androidx/tracing/AbstractTraceDriver#flush()()`

Flushes the trace packets into the underlying `https://developer.android.com/reference/androidx/tracing/AbstractTraceSink`.
`final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/tracing/AbstractTraceSink` `https://developer.android.com/reference/androidx/tracing/AbstractTraceDriver#getSink()()`

The `https://developer.android.com/reference/androidx/tracing/AbstractTraceSink` that asynchronously serializes trace events to a file or buffer, depending on implementation.
`final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/tracing/AbstractTraceSink` `https://developer.android.com/reference/androidx/tracing/AbstractTraceDriver#getSink()()`

The `https://developer.android.com/reference/androidx/tracing/AbstractTraceSink` that asynchronously serializes trace events to a file or buffer, depending on implementation.
`final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/tracing/AbstractTraceSink` `https://developer.android.com/reference/androidx/tracing/AbstractTraceDriver#getSink()()`

The `https://developer.android.com/reference/androidx/tracing/AbstractTraceSink` that asynchronously serializes trace events to a file or buffer, depending on implementation.
`abstract @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/tracing/Tracer` `https://developer.android.com/reference/androidx/tracing/AbstractTraceDriver#getTracer()()`

Return an instance of a `https://developer.android.com/reference/androidx/tracing/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 TraceAttributes, Unit> attributes
)
```

Constructs a `https://developer.android.com/reference/androidx/tracing/wire/TraceDriver` instance on the JVM.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/tracing/AbstractTraceSink sink` | The `https://developer.android.com/reference/androidx/tracing/wire/TraceSink` instance. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Boolean.html> isCategoryEnabled` | returns `true` if the provided trace `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.text/index.html` should be enabled. If `false` then trace events corresponding to the `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.text/index.html` 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. Note: Disabling all categories still writes process and thread metadata packets. To fully disable tracing, use `https://developer.android.com/reference/androidx/tracing/wire/TraceDriver.Companion#getStubTraceDriver()` instead. |
| `Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/tracing/TraceAttributes, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> 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.5](https://developer.android.com/jetpack/androidx/releases/tracing#2.0.5)

```
public TraceDriver(
    @NonNull Context context,
    @NonNull AbstractTraceSink sink,
    @NonNull Function1<@NonNull String, @NonNull Boolean> isCategoryEnabled,
    Function1<@NonNull TraceAttributes, Unit> attributes
)
```

Constructs a `https://developer.android.com/reference/androidx/tracing/wire/TraceDriver` instance on Android based on the provided `https://developer.android.com/reference/android/content/Context.html` instance.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context` | The Android application `https://developer.android.com/reference/android/content/Context.html`. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/tracing/AbstractTraceSink sink` | The `https://developer.android.com/reference/androidx/tracing/wire/TraceSink` instance. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Boolean.html> isCategoryEnabled` | returns `true` if the provided trace `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.text/index.html` should be enabled. If `false` then trace events corresponding to the `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.text/index.html` 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 (`https://developer.android.com/reference/androidx/tracing/Trace#isEnabled()`). Note: Disabling all categories still writes process and thread metadata packets. To fully disable tracing, use `https://developer.android.com/reference/androidx/tracing/wire/TraceDriver.Companion#getStubTraceDriver()` instead. Note:This method should be **extremely** low overhead given it's called every time a `https://developer.android.com/reference/androidx/tracing/Tracer` can emit trace events. |
| `Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/tracing/TraceAttributes, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> 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 `https://developer.android.com/reference/androidx/tracing/wire/TraceDriver#(android.content.Context,androidx.tracing.AbstractTraceSink,kotlin.Function1,kotlin.Function1)` block, these key value pairs are dispatched to the designated `https://developer.android.com/reference/androidx/tracing/AbstractTraceSink` to be serialized. Examples include: ``` gradle_version = "9.0.10-alpha01" java_major_version = 24 ``` |

## Public methods

### close

Added in [2.0.5](https://developer.android.com/jetpack/androidx/releases/tracing#2.0.5)

```
public void close()
```

Flushes all outstanding packets to the `https://developer.android.com/reference/androidx/tracing/AbstractTraceSink` and then closes the `https://developer.android.com/reference/androidx/tracing/AbstractTraceSink`.

### close

Added in [2.0.5](https://developer.android.com/jetpack/androidx/releases/tracing#2.0.5)

```
public void close()
```

Flushes all outstanding packets to the `https://developer.android.com/reference/androidx/tracing/AbstractTraceSink` and then closes the `https://developer.android.com/reference/androidx/tracing/AbstractTraceSink`.

### flush

Added in [2.0.5](https://developer.android.com/jetpack/androidx/releases/tracing#2.0.5)

```
public void flush()
```

Flushes the trace packets into the underlying `https://developer.android.com/reference/androidx/tracing/AbstractTraceSink`.

### flush

Added in [2.0.5](https://developer.android.com/jetpack/androidx/releases/tracing#2.0.5)

```
public void flush()
```

Flushes the trace packets into the underlying `https://developer.android.com/reference/androidx/tracing/AbstractTraceSink`.

### getTracer

Added in [2.0.5](https://developer.android.com/jetpack/androidx/releases/tracing#2.0.5)

```
public @NonNull Tracer getTracer()
```

Return an instance of a `https://developer.android.com/reference/androidx/tracing/Tracer` that can be used to emit trace events.

### getTracer

Added in [2.0.5](https://developer.android.com/jetpack/androidx/releases/tracing#2.0.5)

```
public @NonNull Tracer getTracer()
```

Return an instance of a `https://developer.android.com/reference/androidx/tracing/Tracer` that can be used to emit trace events.