Timer

public class Timer
extension Timer: CustomStringConvertible

A timer collects observations within a time window (usually things like request durations) and provides aggregated information about the data sample, for example, min, max and various quantiles. It is similar to a Recorder but specialized for values that represent durations.

This is the user-facing Timer API.

Its behavior depends on the TimerHandler implementation.

  • Undocumented

    Declaration

    Swift

    public let label: String
  • Undocumented

    Declaration

    Swift

    public let dimensions: [(String, String)]
  • Alternative way to create a new Timer, while providing an explicit TimerHandler.

    Warning

    This initializer provides an escape hatch for situations where one must use a custom factory instead of the global one. We do not expect this API to be used in normal circumstances, so if you find yourself using it make sure it’s for a good reason.

    See also

    Use init(label:dimensions:) to create Recorder instances using the configured metrics backend.

    Declaration

    Swift

    public init(label: String, dimensions: [(String, String)], handler: TimerHandler)

    Parameters

    label

    The label for the Timer.

    dimensions

    The dimensions for the Timer.

    handler

    The custom backend.

  • Record a duration in nanoseconds.

    Declaration

    Swift

    @inlinable
    public func recordNanoseconds(_ duration: Int64)

    Parameters

    value

    Duration to record.

  • Record a duration in nanoseconds.

    Declaration

    Swift

    @inlinable
    public func recordNanoseconds<DataType>(_ duration: DataType) where DataType : BinaryInteger

    Parameters

    value

    Duration to record.

  • Record a duration in microseconds.

    Declaration

    Swift

    @inlinable
    public func recordMicroseconds<DataType>(_ duration: DataType) where DataType : BinaryInteger

    Parameters

    value

    Duration to record.

  • Record a duration in microseconds.

    Declaration

    Swift

    @inlinable
    public func recordMicroseconds<DataType>(_ duration: DataType) where DataType : BinaryFloatingPoint

    Parameters

    value

    Duration to record.

  • Record a duration in milliseconds.

    Declaration

    Swift

    @inlinable
    public func recordMilliseconds<DataType>(_ duration: DataType) where DataType : BinaryInteger

    Parameters

    value

    Duration to record.

  • Record a duration in milliseconds.

    Declaration

    Swift

    @inlinable
    public func recordMilliseconds<DataType>(_ duration: DataType) where DataType : BinaryFloatingPoint

    Parameters

    value

    Duration to record.

  • Record a duration in seconds.

    Declaration

    Swift

    @inlinable
    public func recordSeconds<DataType>(_ duration: DataType) where DataType : BinaryInteger

    Parameters

    value

    Duration to record.

  • Record a duration in seconds.

    Declaration

    Swift

    @inlinable
    public func recordSeconds<DataType>(_ duration: DataType) where DataType : BinaryFloatingPoint

    Parameters

    value

    Duration to record.

User API

  • Create a new Timer.

    Declaration

    Swift

    convenience init(label: String, dimensions: [(String, String)] = [])

    Parameters

    label

    The label for the Timer.

    dimensions

    The dimensions for the Timer.

  • Create a new Timer.

    Declaration

    Swift

    convenience init(label: String, dimensions: [(String, String)] = [], preferredDisplayUnit displayUnit: TimeUnit)

    Parameters

    label

    The label for the Timer.

    dimensions

    The dimensions for the Timer.

    displayUnit

    A hint to the backend responsible for presenting the data of the preferred display unit. This is not guaranteed to be supported by all backends.

  • Signal the underlying metrics library that this timer will never be updated again. In response the library MAY decide to eagerly release any resources held by this Timer.

    Declaration

    Swift

    @inlinable
    func destroy()
  • Declaration

    Swift

    public var description: String { get }