add console.timing context
Log debug messages with timing for different processes.
This commit is contained in:
parent
8a0e288f71
commit
a944a34e63
@ -2,8 +2,10 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import contextlib
|
||||||
import inspect
|
import inspect
|
||||||
import shutil
|
import shutil
|
||||||
|
import time
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from types import FrameType
|
from types import FrameType
|
||||||
|
|
||||||
@ -317,3 +319,20 @@ def status(*args, **kwargs):
|
|||||||
A new status.
|
A new status.
|
||||||
"""
|
"""
|
||||||
return _console.status(*args, **kwargs)
|
return _console.status(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
@contextlib.contextmanager
|
||||||
|
def timing(msg: str):
|
||||||
|
"""Create a context manager to time a block of code.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
msg: The message to display.
|
||||||
|
|
||||||
|
Yields:
|
||||||
|
None.
|
||||||
|
"""
|
||||||
|
start = time.time()
|
||||||
|
try:
|
||||||
|
yield
|
||||||
|
finally:
|
||||||
|
debug(f"[white]\\[timing] {msg}: {time.time() - start:.2f}s[/white]")
|
||||||
|
Loading…
Reference in New Issue
Block a user