Skip to content
Snippets Groups Projects
Commit 922c3b58 authored by Alán Muñoz's avatar Alán Muñoz
Browse files

refactor(log): #47 use add timer decorator

parent 54373ea6
No related branches found
No related tags found
No related merge requests found
......@@ -10,6 +10,8 @@ from typing import Union
from flatten_dict import flatten
from yaml import dump, safe_load
from agora.logging import timer
atomic = t.Union[int, float, str, bool]
......@@ -239,21 +241,12 @@ class StepABC(ProcessABC):
def _run_tp(self):
pass
def run_tp(self, tp: int, log: bool = True, **kwargs):
@timer
def run_tp(self, tp: int, **kwargs):
"""
Time and log the timing of a step.
"""
if log:
t = perf_counter()
result = self._run_tp(tp, **kwargs)
self._log(
f"Timing:{self.__class__.__name__}:{perf_counter()-t}s",
"debug",
)
else:
result = self._run_tp(tp, **kwargs)
return result
return self._run_tp(tp, **kwargs)
def run(self):
# Replace run withn run_tp
......
#!/usr/bin/env jupyter
"""
Add general logging functions and decorators
"""
import logging
from time import perf_counter
def timer(func):
# Log duration of a function into aliby logfile
def wrap_func(*args, **kwargs):
t1 = perf_counter()
result = func(*args, **kwargs)
logging.getLogger("aliby").debug(
f"{func.__qualname__} took {(perf_counter()-t1):.4f}s"
)
return result
return wrap_func
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment