glean / mozilla.telemetry.glean.private / TimingDistributionMetricType

TimingDistributionMetricType

class TimingDistributionMetricType : HistogramBase

This implements the developer facing API for recording timing distribution metrics.

Instances of this class type are automatically generated by the parsers at build time, allowing developers to record values that were previously registered in the metrics.yaml file.

Constructors

<init>

TimingDistributionMetricType(disabled: Boolean, category: String, lifetime: Lifetime, name: String, sendInPings: List<String>, timeUnit: TimeUnit = TimeUnit.Minute)

The public constructor used by automatically generated metrics.

Functions

accumulateSamples

fun accumulateSamples(samples: LongArray): Unit

Accumulates the provided samples in the metric.

cancel

fun cancel(timerId: GleanTimerId?): Unit

Abort a previous start call. No error is recorded if no start was called.

measure

fun <U> measure(funcToMeasure: () -> U): U

Convenience method to simplify measuring a function or block of code.

start

fun start(): GleanTimerId?

Start tracking time for the provided metric. Multiple timers can run simultaneously.

stopAndAccumulate

fun stopAndAccumulate(timerId: GleanTimerId?): Unit

Stop tracking time for the provided metric and associated timer id. Add a count to the corresponding bucket in the timing distribution. This will record an error if no start was called.

testGetNumRecordedErrors

fun testGetNumRecordedErrors(errorType: ErrorType, pingName: String = sendInPings.first()): Int

Returns the number of errors recorded for the given metric.

testGetValue

fun testGetValue(pingName: String = sendInPings.first()): DistributionData

Returns the stored value for testing purposes only.

testHasValue

fun testHasValue(pingName: String = sendInPings.first()): Boolean

Tests whether a value is stored for the metric for testing purposes only.