# PerfettoTrace.Companion

Artifact: [androidx.benchmark:benchmark-traceprocessor](https://developer.android.com/jetpack/androidx/releases/benchmark) [View Source](https://cs.android.com/search?q=file:androidx/benchmark/traceprocessor/PerfettoTrace.kt+class:androidx.benchmark.traceprocessor.PerfettoTrace.Companion) Added in [1.4.0](https://developer.android.com/jetpack/androidx/releases/benchmark#1.4.0)

*** ** * ** ***

<br />

```
public static class PerfettoTrace.Companion
```

<br />

*** ** * ** ***

## Summary

| ### Extension functions |
|---|---|
| `static final void` | `@https://developer.android.com/reference/androidx/benchmark/perfetto/ExperimentalPerfettoCaptureApi https://developer.android.com/reference/androidx/benchmark/traceprocessor/PerfettoTraceKt.https://developer.android.com/reference/androidx/benchmark/traceprocessor/PerfettoTrace.Companion#(androidx.benchmark.traceprocessor.PerfettoTrace.Companion).record(kotlin.String,kotlin.collections.List,kotlin.String,kotlin.Function1,kotlin.Function0)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/benchmark/traceprocessor/PerfettoTrace.Companion receiver, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html fileLabel, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html> appTagPackages, https://developer.android.com/reference/java/lang/String.html userspaceTracingPackage, Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/benchmark/traceprocessor/PerfettoTrace, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> traceCallback, @https://developer.android.com/reference/androidx/annotation/NonNull Function0<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> block )` Record a Perfetto System Trace for the specified `https://developer.android.com/reference/androidx/benchmark/traceprocessor/package-summary#(androidx.benchmark.traceprocessor.PerfettoTrace.Companion).record(kotlin.String,kotlin.collections.List,kotlin.String,kotlin.Function1,kotlin.Function0)`. |
| `static final void` | `@https://developer.android.com/reference/androidx/benchmark/perfetto/ExperimentalPerfettoCaptureApi https://developer.android.com/reference/androidx/benchmark/traceprocessor/PerfettoTraceKt.https://developer.android.com/reference/androidx/benchmark/traceprocessor/PerfettoTrace.Companion#(androidx.benchmark.traceprocessor.PerfettoTrace.Companion).record(kotlin.String,androidx.benchmark.perfetto.PerfettoConfig,kotlin.String,kotlin.Function1,kotlin.Function0)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/benchmark/traceprocessor/PerfettoTrace.Companion receiver, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html fileLabel, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/benchmark/perfetto/PerfettoConfig config, https://developer.android.com/reference/java/lang/String.html userspaceTracingPackage, Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/benchmark/traceprocessor/PerfettoTrace, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> traceCallback, @https://developer.android.com/reference/androidx/annotation/NonNull Function0<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> block )` Record a Perfetto System Trace for the specified `https://developer.android.com/reference/androidx/benchmark/traceprocessor/package-summary#(androidx.benchmark.traceprocessor.PerfettoTrace.Companion).record(kotlin.String,androidx.benchmark.perfetto.PerfettoConfig,kotlin.String,kotlin.Function1,kotlin.Function0)`, with a fully custom Perfetto config, either text or binary. |

## Extension functions

### PerfettoTraceKt.record

Artifact: [androidx.benchmark:benchmark-traceprocessor](https://developer.android.com/jetpack/androidx/releases/benchmark) [View Source](https://cs.android.com/search?q=file:androidx/benchmark/traceprocessor/PerfettoTrace.kt+function:record)

```
@ExperimentalPerfettoCaptureApi
public static final void PerfettoTraceKt.record(
    @NonNull PerfettoTrace.Companion receiver,
    @NonNull String fileLabel,
    @NonNull List<@NonNull String> appTagPackages,
    String userspaceTracingPackage,
    Function1<@NonNull PerfettoTrace, Unit> traceCallback,
    @NonNull Function0<Unit> block
)
```

Record a Perfetto System Trace for the specified `https://developer.android.com/reference/androidx/benchmark/traceprocessor/package-summary#(androidx.benchmark.traceprocessor.PerfettoTrace.Companion).record(kotlin.String,kotlin.collections.List,kotlin.String,kotlin.Function1,kotlin.Function0)`.

```
PerfettoTrace.record("myTrace") {
    // content in here is traced to myTrace_<timestamp>.perfetto_trace
}
```

Reentrant Perfetto trace capture is not supported, so this API may not be combined with `BenchmarkRule`, `MacrobenchmarkRule`, or `PerfettoTraceRule`.

If the block throws, the trace is still captured and passed to `https://developer.android.com/reference/androidx/benchmark/traceprocessor/package-summary#(androidx.benchmark.traceprocessor.PerfettoTrace.Companion).record(kotlin.String,kotlin.collections.List,kotlin.String,kotlin.Function1,kotlin.Function0)`.

### PerfettoTraceKt.record

Artifact: [androidx.benchmark:benchmark-traceprocessor](https://developer.android.com/jetpack/androidx/releases/benchmark) [View Source](https://cs.android.com/search?q=file:androidx/benchmark/traceprocessor/PerfettoTrace.kt+function:record)

```
@ExperimentalPerfettoCaptureApi
public static final void PerfettoTraceKt.record(
    @NonNull PerfettoTrace.Companion receiver,
    @NonNull String fileLabel,
    @NonNull PerfettoConfig config,
    String userspaceTracingPackage,
    Function1<@NonNull PerfettoTrace, Unit> traceCallback,
    @NonNull Function0<Unit> block
)
```

Record a Perfetto System Trace for the specified `https://developer.android.com/reference/androidx/benchmark/traceprocessor/package-summary#(androidx.benchmark.traceprocessor.PerfettoTrace.Companion).record(kotlin.String,androidx.benchmark.perfetto.PerfettoConfig,kotlin.String,kotlin.Function1,kotlin.Function0)`, with a fully custom Perfetto config, either text or binary.

```
PerfettoTrace.record("myTrace", config = """...""") {
    // content in here is traced to myTrace_<timestamp>.perfetto_trace
}
```

Reentrant Perfetto trace capture is not supported, so this API may not be combined with `BenchmarkRule`, `MacrobenchmarkRule`, or `PerfettoTraceRule`.

If the block throws, the trace is still captured and passed to `https://developer.android.com/reference/androidx/benchmark/traceprocessor/package-summary#(androidx.benchmark.traceprocessor.PerfettoTrace.Companion).record(kotlin.String,androidx.benchmark.perfetto.PerfettoConfig,kotlin.String,kotlin.Function1,kotlin.Function0)`.