Use monotonic_ns

This commit is contained in:
Kovid Goyal 2024-09-18 12:18:16 +05:30
parent 685fc41ce8
commit df6e5863ec
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -3,7 +3,7 @@
import sys import sys
from time import monotonic from time import monotonic_ns
from calibre.constants import DEBUG from calibre.constants import DEBUG
@ -60,15 +60,15 @@ def url_for_book_in_library():
class PerformanceMonitor: class PerformanceMonitor:
def __init__(self): def __init__(self):
self.start_time = monotonic() self.start_time = monotonic_ns()
def __call__(self, desc='', reset=False): def __call__(self, desc='', reset=False):
if DEBUG: if DEBUG:
at = monotonic() at = monotonic_ns()
if reset: if reset:
self.start_time = at self.start_time = at
if desc: if desc:
ts = at - self.start_time ts = (at - self.start_time) / 1e9
print(f'[{ts:.3f}] {desc}', file=sys.stderr) print(f'[{ts:.3f}] {desc}', file=sys.stderr)