# 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)

*** ** * ** ***

Android/JVM
- android

  ```
  class TraceDriver : AbstractTraceDriver
  ```

|---|---|---|
| [kotlin.Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html) |||
| ↳ | [androidx.tracing.AbstractTraceDriver](https://developer.android.com/reference/kotlin/androidx/tracing/AbstractTraceDriver) ||
|   | ↳ | [androidx.tracing.wire.TraceDriver](https://developer.android.com/reference/kotlin/androidx/tracing/wire/TraceDriver) |

*** ** * ** ***

The entry point to tracing APIs.

## Summary

| ### Public companion functions |
|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/tracing/wire/TraceDriver` | `https://developer.android.com/reference/kotlin/androidx/tracing/wire/TraceDriver#getStubTraceDriver()()` | android |

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

| ### Public functions |
|---|---|---|
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/tracing/wire/TraceDriver#close()()` Flushes all outstanding packets to the `https://developer.android.com/reference/kotlin/androidx/tracing/AbstractTraceSink` and then closes the `https://developer.android.com/reference/kotlin/androidx/tracing/AbstractTraceSink`. | android |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/tracing/wire/TraceDriver#close()()` Flushes all outstanding packets to the `https://developer.android.com/reference/kotlin/androidx/tracing/AbstractTraceSink` and then closes the `https://developer.android.com/reference/kotlin/androidx/tracing/AbstractTraceSink`. | android |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/tracing/wire/TraceDriver#flush()()` Flushes the trace packets into the underlying `https://developer.android.com/reference/kotlin/androidx/tracing/AbstractTraceSink`. | android |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/tracing/wire/TraceDriver#flush()()` Flushes the trace packets into the underlying `https://developer.android.com/reference/kotlin/androidx/tracing/AbstractTraceSink`. | android |

| ### Public properties |
|---|---|---|
| `open https://developer.android.com/reference/kotlin/androidx/tracing/Tracer` | `https://developer.android.com/reference/kotlin/androidx/tracing/wire/TraceDriver#tracer()` Return an instance of a `https://developer.android.com/reference/kotlin/androidx/tracing/Tracer` that can be used to emit trace events. | android |
| `open https://developer.android.com/reference/kotlin/androidx/tracing/Tracer` | `https://developer.android.com/reference/kotlin/androidx/tracing/wire/TraceDriver#tracer()` Return an instance of a `https://developer.android.com/reference/kotlin/androidx/tracing/Tracer` that can be used to emit trace events. | android |

### Inherited functions

From [androidx.tracing.AbstractTraceDriver](https://developer.android.com/reference/kotlin/androidx/tracing/AbstractTraceDriver) `abstract https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/tracing/AbstractTraceDriver#close()()`

Flushes all outstanding packets to the `https://developer.android.com/reference/kotlin/androidx/tracing/AbstractTraceSink` and then closes the `https://developer.android.com/reference/kotlin/androidx/tracing/AbstractTraceSink`.
android `abstract https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/tracing/AbstractTraceDriver#flush()()`

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

### Inherited properties

From [androidx.tracing.AbstractTraceDriver](https://developer.android.com/reference/kotlin/androidx/tracing/AbstractTraceDriver) `https://developer.android.com/reference/kotlin/androidx/tracing/AbstractTraceSink` `https://developer.android.com/reference/kotlin/androidx/tracing/AbstractTraceDriver#sink()`

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

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

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

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

## Public companion functions

### getStubTraceDriver

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

```
fun getStubTraceDriver(): TraceDriver
```

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/tracing/wire/TraceDriver` | a `https://developer.android.com/reference/kotlin/androidx/tracing/wire/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 `https://developer.android.com/reference/kotlin/androidx/tracing/Tracer` that drops all trace packets. To get a stub tracer, you can also use the `https://developer.android.com/reference/kotlin/androidx/tracing/Tracer#getStubTracer()` API. |

## Public constructors

### TraceDriver

android

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

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

| Parameters |
|---|---|
| `sink: https://developer.android.com/reference/kotlin/androidx/tracing/AbstractTraceSink` | The `https://developer.android.com/reference/kotlin/androidx/tracing/wire/TraceSink` instance. |
| `isCategoryEnabled: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html = { true }` | 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/kotlin/androidx/tracing/wire/TraceDriver#getStubTraceDriver()` instead. |
| `attributes: (https://developer.android.com/reference/kotlin/androidx/tracing/TraceAttributes.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)? = 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: ```kotlin gradle_version = "9.0.10-alpha01" java_major_version = 24 ``` |

### TraceDriver

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

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

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

| Parameters |
|---|---|
| `context: https://developer.android.com/reference/android/content/Context.html` | The Android application `https://developer.android.com/reference/android/content/Context.html`. |
| `sink: https://developer.android.com/reference/kotlin/androidx/tracing/AbstractTraceSink` | The `https://developer.android.com/reference/kotlin/androidx/tracing/wire/TraceSink` instance. |
| `isCategoryEnabled: (category: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html = { Trace.isEnabled() }` | 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/kotlin/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/kotlin/androidx/tracing/wire/TraceDriver#getStubTraceDriver()` instead. Note:This method should be **extremely** low overhead given it's called every time a `https://developer.android.com/reference/kotlin/androidx/tracing/Tracer` can emit trace events. |
| `attributes: (https://developer.android.com/reference/kotlin/androidx/tracing/TraceAttributes.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)? = 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 `https://developer.android.com/reference/kotlin/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/kotlin/androidx/tracing/AbstractTraceSink` to be serialized. Examples include: ```kotlin gradle_version = "9.0.10-alpha01" java_major_version = 24 ``` |

## Public functions

### close

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

```
open fun close(): Unit
```

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

### close

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

```
open fun close(): Unit
```

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

### flush

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

```
open fun flush(): Unit
```

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

### flush

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

```
open fun flush(): Unit
```

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

## Public properties

### tracer

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

```
open val tracer: Tracer
```

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

### tracer

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

```
open val tracer: Tracer
```

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