TraceProcessor.Companion
public static class TraceProcessor.Companion
Summary
Public methods |
|
|---|---|
static final @NonNull T |
@ExperimentalTraceProcessorApiStarts a Perfetto trace processor shell server in http mode, loads a trace and executes the given block. |
static final @NonNull TraceProcessor.Handle |
@ExperimentalTraceProcessorApiStarts a Perfetto trace processor shell server in http mode, and returns a |
Extension functions |
|
|---|---|
static final @NonNull T |
@ExperimentalTraceProcessorApiStarts a Perfetto TraceProcessor shell server in http mode. |
static final @NonNull TraceProcessor.Handle |
@ExperimentalTraceProcessorApiStarts a Perfetto TraceProcessor shell server in http mode. |
Public methods
runServer
@ExperimentalTraceProcessorApi
public static final @NonNull T <T extends Object> runServer(
@NonNull ServerLifecycleManager serverLifecycleManager,
@NonNull TraceProcessor.EventCallback eventCallback,
@NonNull TraceProcessor.Tracer tracer,
long timeoutMs,
@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.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. |
@NonNull Function1<@NonNull TraceProcessor, @NonNull T> block |
Command to execute using trace processor |
startServer
@ExperimentalTraceProcessorApi
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.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
TraceProcessorExtensions.runServer
@ExperimentalTraceProcessorApi
public static final @NonNull T <T extends Object> TraceProcessorExtensions.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.
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. |
@NonNull Function1<@NonNull TraceProcessor, @NonNull T> block |
Command to execute using trace processor |
TraceProcessorExtensions.startServer
@ExperimentalTraceProcessorApi
public static final @NonNull TraceProcessor.Handle TraceProcessorExtensions.startServer(
@NonNull TraceProcessor.Companion receiver,
long timeoutMs
)
Starts a Perfetto TraceProcessor shell server in http mode.
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. |