Files
AiDA_Python/app/service/utils/decorator.py
zhouchengrong 9e1a1996c7 feat(新功能):
fix(修复bug): RunTime判定修改为0.05秒内触发打印
docs(文档变更):
refactor(重构):
test(增加测试):
2025-01-10 15:02:28 +08:00

29 lines
818 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import logging
import time
def RunTime(func):
def wrapper(*args, **kwargs):
t1 = time.time()
res = func(*args, **kwargs)
t2 = time.time()
if t2 - t1 > 0.05:
logging.info(f"function{func.__name__}】,runtime{str(t2 - t1)}】s")
# logging.info(f"function【{func.__name__}】,runtime【{str(t2 - t1)}】s")
return res
return wrapper
def ClassCallRunTime(func):
def wrapper(*args, **kwargs):
start_time = time.time()
result = func(*args, **kwargs)
end_time = time.time()
execution_time = end_time - start_time
class_name = args[0].__class__.__name__ # 获取类名
print(f"class name: {class_name} , run time is : {execution_time} s")
return result
return wrapper