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
| Type | Description |
|---|---|
Timer | A 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
| Name | Type | Description |
|---|---|---|
| start | time.Time | The starting timestamp of the operation to be observed. |
| end | time.Time | The 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
| Name | Type | Description |
|---|---|---|
| f | func() | The function to be executed and timed. |