glean / mozilla.telemetry.glean.private / TimespanMetricType

TimespanMetricType

class TimespanMetricType

This implements the developer facing API for recording timespans.

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.

The timespans API exposes the start, stop and cancel methods.

Constructors

<init>

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

The public constructor used by automatically generated metrics.

Functions

cancel

fun cancel(): 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

setRawNanos

fun setRawNanos(elapsedNanos: Long): Unit

Explicitly set the timespan value, in nanoseconds.

start

fun start(): Unit

Start tracking time for the provided metric. This records an error if it’s already tracking time (i.e. start was already called with no corresponding stop): in that case the original start time will be preserved.

stop

fun stop(): Unit

Stop tracking time for the provided metric. Sets the metric to the elapsed time, but does not overwrite an already existing value. This will record an error if no start was called or there is an already existing value.

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()): Long

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