androidx.benchmark


Classes

BenchmarkState

Control object for microbenchmarking in Java.

ExperimentalConfig

Experimental configuration options for a benchmark.

MetricCapture

Microbenchmark metric.

MicrobenchmarkConfig

Experimental config object for microbenchmarks for defining custom metrics, tracing behavior, and profiling, which overrides options set in instrumentation arguments.

MicrobenchmarkScope

Scope handle for pausing/resuming microbenchmark measurement.

ProfilerConfig

Profiler configuration object.

ProfilerConfig.MethodTracing
ProfilerConfig.StackSampling
StartupInsightsConfig

Configuration for Startup Insights.

TimeCapture

Time metric, which reports time in nanos, based on the time passed to captureStop.

Objects

BlackHole

Function calls which can be used to prevent optimization of results.

Annotations

ExperimentalBenchmarkConfigApi

Annotates declarations that are considered experimental within the Benchmark API, and are likely to change before becoming stable.

ExperimentalBenchmarkStateApi

Annotation indicating experimental API primarily intended to allow microbenchmarks independent of the BenchmarkRule JUnit4 API.

Extension functions summary

T

Starts a Perfetto TraceProcessor shell server in http mode.

TraceProcessor.Handle

Starts a Perfetto TraceProcessor shell server in http mode.

Extension functions

TraceProcessor.Companion.runServer

@ExperimentalTraceProcessorApi
fun <T : Any?> TraceProcessor.Companion.runServer(
    timeoutMs: Long = DEFAULT_TIMEOUT_MS,
    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.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
timeoutMs: Long = DEFAULT_TIMEOUT_MS

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

block: TraceProcessor.() -> T

Command to execute using trace processor

TraceProcessor.Companion.startServer

@ExperimentalTraceProcessorApi
fun TraceProcessor.Companion.startServer(
    timeoutMs: Long = DEFAULT_TIMEOUT_MS
): TraceProcessor.Handle

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
timeoutMs: Long = DEFAULT_TIMEOUT_MS

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