Skip to content

Commit

Permalink
tweak: add kwargs output to timing decorator, human readable 'elapsed…
Browse files Browse the repository at this point in the history
… time' output
  • Loading branch information
tom-webber committed Jul 23, 2024
1 parent 065b81e commit 6e484f0
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions ingestion/utils.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
import logging
import time
from datetime import timedelta


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

0 comments on commit 6e484f0

Please sign in to comment.