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](labeled/timer.md?sid=flytestdlib_promutils_labeled_timer)

Starts a new timer. Callers use this to begin a timing interval that can later be observed.

Returns

TypeDescription
[Timer](labeled/timer.md?sid=flytestdlib_promutils_labeled_timer)A Timer object representing the start time of the interval.

Observe()

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

Records the duration between a start and end time. This method is used to submit a completed timing interval to the StopWatch for observation.

Parameters

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

Time()

@classmethod
def Time(
f: func()
)

Executes a given function and measures its execution time. Callers use this to easily time the duration of a function's execution.

Parameters

NameTypeDescription
ffunc()The function to be timed.