Skip to main content

StopWatch

This class implements a stopwatch-style interface that integrates with Prometheus summaries. It automatically scales the output to match the expected time scale, such as milliseconds or seconds. Users should not create StopWatch objects directly; instead, they should obtain new instances using a Scope.

Methods​


Start()​

@classmethod
def Start() - > Timer

Starts a new timer, returning a Timer object that can be used to record the elapsed time. Callers use this to begin timing an operation.

Returns​

TypeDescription
TimerA Timer object representing the start time of the operation.

Observe()​

@classmethod
def Observe(
start: time.Time,
end: time.Time
)

Records the duration between a start and end time, scaling the output to match the expected time scale. Callers use this to manually record a duration for observation.

Parameters​

NameTypeDescription
starttime.TimeThe starting timestamp of the operation to be observed.
endtime.TimeThe ending timestamp of the operation to be observed.

Time()​

@classmethod
def Time(
f: func()
)

Executes a given function and records the time it takes for the function to complete. Callers use this to easily time the execution of a function.

Parameters​

NameTypeDescription
ffunc()The function to be executed and timed.