From 5a82e82e2a23c35635ff1247a892457a737e498e Mon Sep 17 00:00:00 2001 From: Tom Webber Date: Tue, 23 Jul 2024 14:57:52 +0100 Subject: [PATCH] tweak: add kwargs output to timing decorator, human readable 'elapsed time' output --- ingestion/utils.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ingestion/utils.py b/ingestion/utils.py index 7a4fb4e..b837d42 100644 --- a/ingestion/utils.py +++ b/ingestion/utils.py @@ -1,5 +1,6 @@ import logging import time +from datetime import timedelta def st_time(func): @@ -7,16 +8,19 @@ def st_time(func): st decorator to calculate the total time of a func """ - def st_func(*args, **keyArgs): + def st_func(*args, **kwargs): t1 = time.time() - r = func(*args, **keyArgs) + r = func(*args, **kwargs) t2 = time.time() + elapsed = t2 - t1 logging.info( - f"Function={func.__name__}, args={args}, " + f"Function={func.__name__}, args={args}, kwargs={kwargs}, " f"start_time={time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(t1))}, " f"end_time={time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(t2))}" ) - logging.info(f"Function={func.__name__}, args={args}, total_time={t2 - t1}") + logging.info( + f"Function={func.__name__}, args={args}, kwargs={kwargs}, elapsed_time={str(timedelta(seconds=elapsed))}" + ) return r return st_func