TraceProcessor.Companion



Summary

Public functions

T
@ExperimentalTraceProcessorApi
@<Error class: unknown class>
<T : Any?> runServer(
    serverLifecycleManager: ServerLifecycleManager,
    eventCallback: TraceProcessor.EventCallback,
    tracer: TraceProcessor.Tracer,
    timeout: Duration,
    block: TraceProcessor.() -> T
)

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

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

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.

Cmn

Extension functions

T

Starts a Perfetto TraceProcessor shell server in http mode.

android
TraceProcessor.Handle

Starts a Perfetto TraceProcessor shell server in http mode.

android

Public functions

runServer

@ExperimentalTraceProcessorApi
@<Error class: unknown class>
fun <T : Any?> runServer(
    serverLifecycleManager: ServerLifecycleManager,
    eventCallback: TraceProcessor.EventCallback,
    tracer: TraceProcessor.Tracer,
    timeout: Duration = DEFAULT_TIMEOUT,
    block: TraceProcessor.() -> T
): T

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

controls starting and stopping the TraceProcessor process.

eventCallback: TraceProcessor.EventCallback

callback for events such as trace load failure.

tracer: TraceProcessor.Tracer

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

timeout: Duration = DEFAULT_TIMEOUT

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

block: TraceProcessor.() -> T

Command to execute using trace processor

startServer

@ExperimentalTraceProcessorApi
@<Error class: unknown class>
fun startServer(
    serverLifecycleManager: ServerLifecycleManager,
    eventCallback: TraceProcessor.EventCallback,
    tracer: TraceProcessor.Tracer,
    timeout: Duration = DEFAULT_TIMEOUT
): 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.

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

controls starting and stopping the TraceProcessor process.

eventCallback: TraceProcessor.EventCallback

callback for events such as trace load failure.

tracer: TraceProcessor.Tracer

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

timeout: Duration = DEFAULT_TIMEOUT

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

Extension functions

runServer

@ExperimentalTraceProcessorApi
fun <T : Any?> TraceProcessor.Companion.runServer(
    timeout: Duration = DEFAULT_TIMEOUT,
    block: TraceProcessor.() -> T
): T

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
timeout: Duration = DEFAULT_TIMEOUT

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

block: TraceProcessor.() -> T

Command to execute using trace processor

startServer

@ExperimentalTraceProcessorApi
fun TraceProcessor.Companion.startServer(timeout: Duration = DEFAULT_TIMEOUT): TraceProcessor.Handle

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
timeout: Duration = DEFAULT_TIMEOUT

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