8000 time can not go backwards if it is monotonic · prometheus/client_python@5df1730 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5df1730

Browse files
committed
time can not go backwards if it is monotonic
Signed-off-by: George Mossessian <gmossessian@gmail.com>
1 parent 3ab0374 commit 5df1730

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

prometheus_client/context_managers.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import unicode_literals
22

3-
from timeit import default_timer
3+
from time import monotonic
44

55
from .decorator import decorate
66

@@ -51,11 +51,10 @@ def _new_timer(self):
5151
return self.__class__(self._callback)
5252

5353
def __enter__(self):
54-
self._start = default_timer()
54+
self._start = monotonic()
5555

5656
def __exit__(self, typ, value, traceback):
57-
# Time can go backwards.
58-
duration = max(default_timer() - self._start, 0)
57+
duration = monotonic() - self._start
5958
self._callback(duration)
6059

6160
def __call__(self, f):

0 commit comments

Comments
 (0)
0