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,
    @NonNull Duration timeout,
    @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

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

@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,
    @NonNull Duration timeout,
    @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.

@NonNull Duration timeout

maximum duration 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

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

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.

@NonNull Duration timeout

maximum duration 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,
    @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

maximum duration 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,
    @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

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