MetricCapture


@ExperimentalBenchmarkConfigApi
public abstract class MetricCapture

Known direct subclasses
TimeCapture

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


Microbenchmark metric.

Note that the API is designed around low overhead, even in the case of multiple submetrics (such as cpu perf event counters) that must be started/stopped together for efficiency.

This class may be initialized on a different thread from where measurement occurs, but all capture methods must be invoked from the same thread.

Summary

Public constructors

Public methods

abstract void

Pause data collection.

abstract void

Resume data collection

abstract void
captureStart(long timeNs)

Starts collecting data for a run.

abstract void
captureStop(long timeNs, @NonNull long[] output, int offset)

Mark the end of a run, and store offset metrics in the output array, per sub metric.

boolean
equals(Object other)
final @NonNull List<@NonNull String>

List of names of metrics produced by this MetricCapture.

int

Public constructors

MetricCapture

Added in 1.2.0
public MetricCapture(@NonNull List<@NonNull String> names)

Public methods

capturePaused

Added in 1.2.0
public abstract void capturePaused()

Pause data collection.

captureResumed

Added in 1.2.0
public abstract void captureResumed()

Resume data collection

captureStart

Added in 1.2.0
public abstract void captureStart(long timeNs)

Starts collecting data for a run.

Called at the start of each run.

Parameters
long timeNs

Current time, just before starting metrics. Can be used directly to drive a timing metric produced.

captureStop

Added in 1.2.0
public abstract void captureStop(long timeNs, @NonNull long[] output, int offset)

Mark the end of a run, and store offset metrics in the output array, per sub metric.

To output values, store them in the output array offset by both the parameter offset, and their submetric index, for example:

class MyMetricCapture("firstSubMetricName", "secondSubMetricName") {
//...
override fun captureStop(timeNs: Long, output: LongArray, offset: Int) {
output[offset + 0] = firstSubMetricValue
output[offset + 1] = secondSubMetricValue
}
}
Parameters
long timeNs

Time of metric capture start, in monotonic time (java.lang.System.nanoTime)

@NonNull long[] output

LongArray sized to hold all simultaneous sub metric outputs, use offset as the initial position in output to start writing submetrics.

int offset

Offset into the output array to start writing sub metrics.

equals

public boolean equals(Object other)

getNames

Added in 1.2.0
public final @NonNull List<@NonNull StringgetNames()

List of names of metrics produced by this MetricCapture.

The length of this list defines how many metrics will be produced by captureStart and captureStop.

hashCode

public int hashCode()