# TraceProcessorExtensions

Added in 1.5.0

*** ** * ** ***


```
public final class TraceProcessorExtensions
```

<br />

*** ** * ** ***

## Summary

| ### Public methods |
|---|---|
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull T` | `@https://developer.android.com/reference/androidx/benchmark/traceprocessor/ExperimentalTraceProcessorApi <T extends https://developer.android.com/reference/java/lang/Object.html> https://developer.android.com/reference/androidx/benchmark/TraceProcessorExtensions#(androidx.benchmark.traceprocessor.TraceProcessor.Companion).runServer(kotlin.Long,kotlin.Function1)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/benchmark/traceprocessor/TraceProcessor.Companion receiver, long timeoutMs, @https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/benchmark/traceprocessor/TraceProcessor, @https://developer.android.com/reference/androidx/annotation/NonNull T> block )` Starts a Perfetto TraceProcessor shell server in http mode. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/benchmark/traceprocessor/TraceProcessor.Handle` | `@https://developer.android.com/reference/androidx/benchmark/traceprocessor/ExperimentalTraceProcessorApi https://developer.android.com/reference/androidx/benchmark/TraceProcessorExtensions#(androidx.benchmark.traceprocessor.TraceProcessor.Companion).startServer(kotlin.Long)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/benchmark/traceprocessor/TraceProcessor.Companion receiver, long timeoutMs)` Starts a Perfetto TraceProcessor shell server in http mode. |

## Public methods

### runServer

Artifact: [androidx.benchmark:benchmark-common](https://developer.android.com/jetpack/androidx/releases/benchmark) [View Source](https://cs.android.com/search?q=file:androidx/benchmark/TraceProcessorExtensions.kt+function:runServer) Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/benchmark#1.5.0)

```
@ExperimentalTraceProcessorApi
public static final @NonNull T <T extends Object> runServer(
    @NonNull TraceProcessor.Companion receiver,
    long timeoutMs,
    @NonNull Function1<@NonNull TraceProcessor, @NonNull T> block
)
```

Starts a Perfetto TraceProcessor shell server in http mode.

The server is stopped after the block is complete.

```kotlin
import androidx.benchmark.runServer
import androidx.benchmark.traceprocessor.PerfettoTrace
import androidx.benchmark.traceprocessor.TraceProcessor

// Collect the duration of all slices named "activityStart" in the trace
val activityStartDurNs = TraceProcessor.runServer {
    loadTrace(PerfettoTrace("/path/to/trace.perfetto-trace")) {
            query("SELECT dur FROM slice WHERE name = 'activityStart'").map {
                it.long("dur")
            }
        }
        .toList()
}
return activityStartDurNs
```

| Parameters |
|---|---|
| `long timeoutMs` | maximum duration in milliseconds for waiting for operations like loading the server, or querying a trace. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/benchmark/traceprocessor/TraceProcessor, @https://developer.android.com/reference/androidx/annotation/NonNull T> block` | Command to execute using trace processor |

### startServer

Artifact: [androidx.benchmark:benchmark-common](https://developer.android.com/jetpack/androidx/releases/benchmark) [View Source](https://cs.android.com/search?q=file:androidx/benchmark/TraceProcessorExtensions.kt+function:startServer) Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/benchmark#1.5.0)

```
@ExperimentalTraceProcessorApi
public static final @NonNull TraceProcessor.Handle startServer(@NonNull TraceProcessor.Companion receiver, long timeoutMs)
```

Starts a Perfetto TraceProcessor shell server in http mode.

```kotlin
import androidx.benchmark.startServer
import androidx.benchmark.traceprocessor.PerfettoTrace
import androidx.benchmark.traceprocessor.TraceProcessor

// Collect the duration of all slices named "activityStart" in the trace
val activityStartDurNs =
    TraceProcessor.startServer().use {
        it.traceProcessor.startSession(PerfettoTrace("/path/to/trace.perfetto-trace")).use {
            it.session
                .query("SELECT dur FROM slice WHERE name = 'activityStart'")
                .map { it.long("dur") }
                .toList()
        }
    }
return activityStartDurNs
```

| Parameters |
|---|---|
| `long timeoutMs` | maximum duration in milliseconds for waiting for operations like loading the server, or querying a trace. |