TraceProcessorExtensionsKt

Added in 1.4.0-alpha09

public final class TraceProcessorExtensionsKt


Summary

Public methods

static final @NonNull T

Starts a Perfetto TraceProcessor shell server in http mode.

static final @NonNull TraceProcessor.Handle

Starts a Perfetto TraceProcessor shell server in http mode.

Public methods

@ExperimentalTraceProcessorApi
public static final @NonNull T <T extends Object> runServer(
    @NonNull TraceProcessor.Companion receiver,
    @NonNull Duration timeout,
    @ExtensionFunctionType @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.

import androidx.benchmark.macro.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
@NonNull Duration timeout

waiting for the server to start. If less or equal to zero uses 60 seconds

@ExtensionFunctionType @NonNull Function1<@NonNull TraceProcessor, @NonNull T> block

Command to execute using trace processor

@ExperimentalTraceProcessorApi
public static final @NonNull TraceProcessor.Handle startServer(
    @NonNull TraceProcessor.Companion receiver,
    @NonNull Duration timeout
)

Starts a Perfetto TraceProcessor shell server in http mode.

import androidx.benchmark.macro.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
@NonNull Duration timeout

waiting for the server to start. If less or equal to zero uses 60 seconds