Merge pull request #107 from devchat-ai/log_time_for_step

chore: Add logging for step duration in Step class
This commit is contained in:
kagami 2024-05-19 01:27:19 +00:00 committed by GitHub
commit bbc53e488e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,5 +1,8 @@
import time
from contextlib import AbstractContextManager from contextlib import AbstractContextManager
from lib.ide_service import IDEService
class Step(AbstractContextManager): class Step(AbstractContextManager):
""" """
@ -19,10 +22,15 @@ class Step(AbstractContextManager):
def __init__(self, title: str): def __init__(self, title: str):
self.title = title self.title = title
self.enter_time = time.time()
def __enter__(self): def __enter__(self):
print(f"\n```Step\n# {self.title}", flush=True) print(f"\n```Step\n# {self.title}", flush=True)
def __exit__(self, exc_type, exc_val, exc_tb): def __exit__(self, exc_type, exc_val, exc_tb):
# close the step # close the step
end_time = time.time()
IDEService().ide_logging(
"debug", f"Step {self.title} took {end_time - self.enter_time:.2f} seconds"
)
print("\n```", flush=True) print("\n```", flush=True)