TimespanMetricType

public class TimespanMetricType

This implements the developer facing API for recording timespan 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.

The timespan API only exposes the TimespanMetricType.start(), TimespanMetricType.stop() and TimespanMetricType.cancel() methods.

  • The public constructor used by automatically generated metrics.

    Declaration

    Swift

    public init(
        category: String,
        name: String,
        sendInPings: [String],
        lifetime: Lifetime,
        disabled: Bool,
        timeUnit: TimeUnit = .minute
    )
  • 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.

    Declaration

    Swift

    public func start()
  • 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.

    Declaration

    Swift

    public func stop()
  • Abort a previous start() call. No error is recorded if no start() was called.

    Declaration

    Swift

    public func cancel()
  • Convenience method to simplify measuring a function or block of code

    Declaration

    Swift

    public func measure<U>(funcToMeasure: () -> U) -> U

    Parameters

    funcToMeasure

    Accepts a function or closure to measure that can return a value

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

    If the measured function throws, the measurement is canceled and the exception rethrown.

    Declaration

    Swift

    public func measure<U>(funcToMeasure: () throws -> U) throws -> U

    Parameters

    funcToMeasure

    Accepts a function or closure to measure that can return a value

  • Explicitly set the timespan value, in nanoseconds.

    This API should only be used if your library or application requires recording times in a way that can not make use of start() / stop() / cancel().

    setRawNanos does not overwrite a running timer or an already existing value.

    Declaration

    Swift

    public func setRawNanos(_ elapsedNanos: UInt64)

    Parameters

    elapsedNanos

    The elapsed time to record, in nanoseconds.

  • Tests whether a value is stored for the metric for testing purposes only. This function will attempt to await the last task (if any) writing to the the metric’s storage engine before returning a value.

    Declaration

    Swift

    public func testHasValue(_ pingName: String? = nil) -> Bool

    Parameters

    pingName

    represents the name of the ping to retrieve the metric for. Defaults to the first value in sendInPings.

    Return Value

    true if metric value exists, otherwise false

  • Returns the stored value for testing purposes only. This function will attempt to await the last task (if any) writing to the the metric’s storage engine before returning a value.

    Throws a “Missing value” exception if no value is stored

    Declaration

    Swift

    public func testGetValue(_ pingName: String? = nil) throws -> UInt64

    Parameters

    pingName

    represents the name of the ping to retrieve the metric for. Defaults to the first value in sendInPings.

    Return Value

    value of the stored metric

  • Returns the number of errors recorded for the given metric.

    Declaration

    Swift

    public func testGetNumRecordedErrors(_ errorType: ErrorType, pingName: String? = nil) -> Int32

    Parameters

    errorType

    The type of error recorded.

    pingName

    represents the name of the ping to retrieve the metric for. Defaults to the first value in sendInPings.

    Return Value

    The number of errors recorded for the metric for the given error type.