From 53dc01015fa07bd735b1dcc034ffc003a420c5ec Mon Sep 17 00:00:00 2001 From: bobo Date: Sat, 18 May 2024 14:50:24 +0800 Subject: [PATCH 1/2] chore: Add logging for step duration in Step class --- lib/chatmark/step.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/chatmark/step.py b/lib/chatmark/step.py index 9e0a8c4..93de1d4 100644 --- a/lib/chatmark/step.py +++ b/lib/chatmark/step.py @@ -1,5 +1,7 @@ from contextlib import AbstractContextManager +import time +from lib.ide_service import IDEService class Step(AbstractContextManager): """ @@ -19,10 +21,16 @@ class Step(AbstractContextManager): def __init__(self, title: str): self.title = title + self.enter_time = time.time() def __enter__(self): print(f"\n```Step\n# {self.title}", flush=True) def __exit__(self, exc_type, exc_val, exc_tb): # 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) From fa8058b5ffe91a4ec0839ccf8fcf1b36d33dcd89 Mon Sep 17 00:00:00 2001 From: bobo Date: Sat, 18 May 2024 14:55:17 +0800 Subject: [PATCH 2/2] chore: Refactor Step class to improve logging of step duration --- lib/chatmark/step.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/chatmark/step.py b/lib/chatmark/step.py index 93de1d4..349c097 100644 --- a/lib/chatmark/step.py +++ b/lib/chatmark/step.py @@ -1,8 +1,9 @@ -from contextlib import AbstractContextManager import time +from contextlib import AbstractContextManager from lib.ide_service import IDEService + class Step(AbstractContextManager): """ Show a running step in the TUI. @@ -30,7 +31,6 @@ class Step(AbstractContextManager): # close the step end_time = time.time() IDEService().ide_logging( - "debug", - f"Step {self.title} took {end_time - self.enter_time:.2f} seconds" + "debug", f"Step {self.title} took {end_time - self.enter_time:.2f} seconds" ) print("\n```", flush=True)