# TraceKt

Added in 1.3.0

*** ** * ** ***

<br />

```
public final class TraceKt
```

<br />

*** ** * ** ***

## Summary

| ### Public methods |
|---|---|
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull T` | `<T extends https://developer.android.com/reference/java/lang/Object.html> https://developer.android.com/reference/androidx/tracing/TraceKt#trace(kotlin.String,kotlin.Function0)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html label, @https://developer.android.com/reference/androidx/annotation/NonNull Function0<@https://developer.android.com/reference/androidx/annotation/NonNull T> block)` Wrap the specified `https://developer.android.com/reference/androidx/tracing/package-summary#trace(kotlin.String,kotlin.Function0)` in calls to `https://developer.android.com/reference/android/os/Trace.html#beginSection(java.lang.String)` (with the supplied `https://developer.android.com/reference/androidx/tracing/package-summary#trace(kotlin.String,kotlin.Function0)`) and `https://developer.android.com/reference/android/os/Trace.html#endSection()`. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull T` | `<T extends https://developer.android.com/reference/java/lang/Object.html> https://developer.android.com/reference/androidx/tracing/TraceKt#trace(kotlin.Function0,kotlin.Function0)( @https://developer.android.com/reference/androidx/annotation/NonNull Function0<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html> lazyLabel, @https://developer.android.com/reference/androidx/annotation/NonNull Function0<@https://developer.android.com/reference/androidx/annotation/NonNull T> block )` Wrap the specified `https://developer.android.com/reference/androidx/tracing/package-summary#trace(kotlin.Function0,kotlin.Function0)` in calls to `https://developer.android.com/reference/android/os/Trace.html#beginSection(java.lang.String)` (with a lazy-computed `https://developer.android.com/reference/androidx/tracing/package-summary#trace(kotlin.Function0,kotlin.Function0)`, only if tracing is enabled - `https://developer.android.com/reference/android/os/Trace.html#isEnabled()`) and `https://developer.android.com/reference/android/os/Trace.html#endSection()`. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull T` | `<T extends https://developer.android.com/reference/java/lang/Object.html> https://developer.android.com/reference/androidx/tracing/TraceKt#traceAsync(kotlin.Function0,kotlin.Function0,kotlin.Function0)( @https://developer.android.com/reference/androidx/annotation/NonNull Function0<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html> lazyMethodName, @https://developer.android.com/reference/androidx/annotation/NonNull Function0<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Integer.html> lazyCookie, @https://developer.android.com/reference/androidx/annotation/NonNull Function0<@https://developer.android.com/reference/androidx/annotation/NonNull T> block )` Wrap the specified `https://developer.android.com/reference/androidx/tracing/package-summary#traceAsync(kotlin.Function0,kotlin.Function0,kotlin.Function0)` in calls to `https://developer.android.com/reference/android/os/Trace.html#beginAsyncSection(java.lang.String, int)` and `https://developer.android.com/reference/android/os/Trace.html#endAsyncSection(java.lang.String, int)`, with a lazy-computed `https://developer.android.com/reference/androidx/tracing/package-summary#traceAsync(kotlin.Function0,kotlin.Function0,kotlin.Function0)` and `https://developer.android.com/reference/androidx/tracing/package-summary#traceAsync(kotlin.Function0,kotlin.Function0,kotlin.Function0)`, only if tracing is enabled - `https://developer.android.com/reference/android/os/Trace.html#isEnabled()`. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull T` | `<T extends https://developer.android.com/reference/java/lang/Object.html> https://developer.android.com/reference/androidx/tracing/TraceKt#traceAsync(kotlin.String,kotlin.Int,kotlin.coroutines.SuspendFunction0)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html methodName, int cookie, @https://developer.android.com/reference/androidx/annotation/NonNull SuspendFunction0<@https://developer.android.com/reference/androidx/annotation/NonNull T> block )` Wrap the specified `https://developer.android.com/reference/androidx/tracing/package-summary#traceAsync(kotlin.String,kotlin.Int,kotlin.coroutines.SuspendFunction0)` in calls to `https://developer.android.com/reference/android/os/Trace.html#beginAsyncSection(java.lang.String, int)` (with the supplied `https://developer.android.com/reference/androidx/tracing/package-summary#traceAsync(kotlin.String,kotlin.Int,kotlin.coroutines.SuspendFunction0)` and `https://developer.android.com/reference/androidx/tracing/package-summary#traceAsync(kotlin.String,kotlin.Int,kotlin.coroutines.SuspendFunction0)`) and `https://developer.android.com/reference/android/os/Trace.html#endAsyncSection(java.lang.String, int)`. |

## Public methods

### trace

Artifact: [androidx.tracing:tracing](https://developer.android.com/jetpack/androidx/releases/tracing) [View Source](https://cs.android.com/search?q=file:androidx/tracing/Trace.android.kt+function:trace) Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/tracing#1.3.0)

```
public static final @NonNull T <T extends Object> trace(@NonNull String label, @NonNull Function0<@NonNull T> block)
```

Wrap the specified `https://developer.android.com/reference/androidx/tracing/package-summary#trace(kotlin.String,kotlin.Function0)` in calls to `https://developer.android.com/reference/android/os/Trace.html#beginSection(java.lang.String)` (with the supplied `https://developer.android.com/reference/androidx/tracing/package-summary#trace(kotlin.String,kotlin.Function0)`) and `https://developer.android.com/reference/android/os/Trace.html#endSection()`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html label` | A name of the code section to appear in the trace. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull Function0<@https://developer.android.com/reference/androidx/annotation/NonNull T> block` | A block of code which is being traced. |

### trace

Artifact: [androidx.tracing:tracing](https://developer.android.com/jetpack/androidx/releases/tracing) [View Source](https://cs.android.com/search?q=file:androidx/tracing/Trace.android.kt+function:trace) Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/tracing#1.3.0)

```
public static final @NonNull T <T extends Object> trace(
    @NonNull Function0<@NonNull String> lazyLabel,
    @NonNull Function0<@NonNull T> block
)
```

Wrap the specified `https://developer.android.com/reference/androidx/tracing/package-summary#trace(kotlin.Function0,kotlin.Function0)` in calls to `https://developer.android.com/reference/android/os/Trace.html#beginSection(java.lang.String)` (with a lazy-computed `https://developer.android.com/reference/androidx/tracing/package-summary#trace(kotlin.Function0,kotlin.Function0)`, only if tracing is enabled - `https://developer.android.com/reference/android/os/Trace.html#isEnabled()`) and `https://developer.android.com/reference/android/os/Trace.html#endSection()`.

This variant allows you to build a dynamic label, but only when tracing is enabled, avoiding the cost of String construction otherwise.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull Function0<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html> lazyLabel` | A name of the code section to appear in the trace, computed lazily if needed. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull Function0<@https://developer.android.com/reference/androidx/annotation/NonNull T> block` | A block of code which is being traced. |

### traceAsync

Artifact: [androidx.tracing:tracing](https://developer.android.com/jetpack/androidx/releases/tracing) [View Source](https://cs.android.com/search?q=file:androidx/tracing/Trace.android.kt+function:traceAsync) Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/tracing#1.3.0)

```
public static final @NonNull T <T extends Object> traceAsync(
    @NonNull Function0<@NonNull String> lazyMethodName,
    @NonNull Function0<@NonNull Integer> lazyCookie,
    @NonNull Function0<@NonNull T> block
)
```

Wrap the specified `https://developer.android.com/reference/androidx/tracing/package-summary#traceAsync(kotlin.Function0,kotlin.Function0,kotlin.Function0)` in calls to `https://developer.android.com/reference/android/os/Trace.html#beginAsyncSection(java.lang.String, int)` and `https://developer.android.com/reference/android/os/Trace.html#endAsyncSection(java.lang.String, int)`, with a lazy-computed `https://developer.android.com/reference/androidx/tracing/package-summary#traceAsync(kotlin.Function0,kotlin.Function0,kotlin.Function0)` and `https://developer.android.com/reference/androidx/tracing/package-summary#traceAsync(kotlin.Function0,kotlin.Function0,kotlin.Function0)`, only if tracing is enabled - `https://developer.android.com/reference/android/os/Trace.html#isEnabled()`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull Function0<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html> lazyMethodName` | The method name to appear in the trace, computed lazily if needed. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull Function0<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Integer.html> lazyCookie` | Unique identifier for distinguishing simultaneous events, computed lazily if needed. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull Function0<@https://developer.android.com/reference/androidx/annotation/NonNull T> block` | a code block to be wrapped between `https://developer.android.com/reference/android/os/Trace.html#beginAsyncSection(java.lang.String, int)` and `https://developer.android.com/reference/android/os/Trace.html#endAsyncSection(java.lang.String, int)`. |

### traceAsync

Artifact: [androidx.tracing:tracing](https://developer.android.com/jetpack/androidx/releases/tracing) [View Source](https://cs.android.com/search?q=file:androidx/tracing/Trace.android.kt+function:traceAsync)

```
public static final @NonNull T <T extends Object> traceAsync(
    @NonNull String methodName,
    int cookie,
    @NonNull SuspendFunction0<@NonNull T> block
)
```

Wrap the specified `https://developer.android.com/reference/androidx/tracing/package-summary#traceAsync(kotlin.String,kotlin.Int,kotlin.coroutines.SuspendFunction0)` in calls to `https://developer.android.com/reference/android/os/Trace.html#beginAsyncSection(java.lang.String, int)` (with the supplied `https://developer.android.com/reference/androidx/tracing/package-summary#traceAsync(kotlin.String,kotlin.Int,kotlin.coroutines.SuspendFunction0)` and `https://developer.android.com/reference/androidx/tracing/package-summary#traceAsync(kotlin.String,kotlin.Int,kotlin.coroutines.SuspendFunction0)`) and `https://developer.android.com/reference/android/os/Trace.html#endAsyncSection(java.lang.String, int)`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html methodName` | The method name to appear in the trace. |
| `int cookie` | Unique identifier for distinguishing simultaneous events |
| `@https://developer.android.com/reference/androidx/annotation/NonNull SuspendFunction0<@https://developer.android.com/reference/androidx/annotation/NonNull T> block` | A code block to be wrapped between `https://developer.android.com/reference/android/os/Trace.html#beginAsyncSection(java.lang.String, int)` and `https://developer.android.com/reference/android/os/Trace.html#endAsyncSection(java.lang.String, int)`. |