TraceProcessor.Companion


public static class TraceProcessor.Companion


Summary

Public methods

static final @NonNull T
@ExperimentalTraceProcessorApi
@<Error class: unknown class>
<T extends Object> runServer(
    @NonNull ServerLifecycleManager serverLifecycleManager,
    @NonNull TraceProcessor.EventCallback eventCallback,
    @NonNull TraceProcessor.Tracer tracer,
    long timeoutMs,
    @ExtensionFunctionType @NonNull Function1<@NonNull TraceProcessor, @NonNull T> block
)

Starts a Perfetto trace processor shell server in http mode, loads a trace and executes the given block.

static final @NonNull TraceProcessor.Handle
@ExperimentalTraceProcessorApi
@<Error class: unknown class>
startServer(
    @NonNull ServerLifecycleManager serverLifecycleManager,
    @NonNull TraceProcessor.EventCallback eventCallback,
    @NonNull TraceProcessor.Tracer tracer,
    long timeoutMs
)

Starts a Perfetto trace processor shell server in http mode, and returns a Handle which can be used to access and close the TraceProcessor server instance.

Extension functions

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

runServer

Added in 1.4.0-alpha11
@ExperimentalTraceProcessorApi
@<Error class: unknown class>
public static final @NonNull T <T extends Object> runServer(
    @NonNull ServerLifecycleManager serverLifecycleManager,
    @NonNull TraceProcessor.EventCallback eventCallback,
    @NonNull TraceProcessor.Tracer tracer,
    long timeoutMs,
    @ExtensionFunctionType @NonNull Function1<@NonNull TraceProcessor, @NonNull T> block
)

Starts a Perfetto trace processor shell server in http mode, loads a trace and executes the given block.

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 ServerLifecycleManager serverLifecycleManager

controls starting and stopping the TraceProcessor process.

@NonNull TraceProcessor.EventCallback eventCallback

callback for events such as trace load failure.

@NonNull TraceProcessor.Tracer tracer

used to trace begin and end of significant events within this managed run.

long timeoutMs

maximum duration in milliseconds for waiting for operations like loading the server, or querying a trace.

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

Command to execute using trace processor

startServer

Added in 1.4.0-alpha11
@ExperimentalTraceProcessorApi
@<Error class: unknown class>
public static final @NonNull TraceProcessor.Handle startServer(
    @NonNull ServerLifecycleManager serverLifecycleManager,
    @NonNull TraceProcessor.EventCallback eventCallback,
    @NonNull TraceProcessor.Tracer tracer,
    long timeoutMs
)

Starts a Perfetto trace processor shell server in http mode, and returns a Handle which can be used to access and close the TraceProcessor server instance.

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 ServerLifecycleManager serverLifecycleManager

controls starting and stopping the TraceProcessor process.

@NonNull TraceProcessor.EventCallback eventCallback

callback for events such as trace load failure.

@NonNull TraceProcessor.Tracer tracer

used to trace begin and end of significant events within this managed run.

long timeoutMs

maximum duration in milliseconds for waiting for operations like loading the server, or querying a trace.

Extension functions

TraceProcessorExtensionsKt.runServer

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

maximum duration in milliseconds for waiting for operations like loading the server, or querying a trace.

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

Command to execute using trace processor

TraceProcessorExtensionsKt.startServer

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

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
long timeoutMs

maximum duration in milliseconds for waiting for operations like loading the server, or querying a trace.