Files
AiDA_Python/app/service/utils/decorator.py
zhouchengrong 48cfb4c1ca feat(新功能):
fix(修复bug): 关闭调试日志打印
docs(文档变更):
refactor(重构):
test(增加测试):
2025-01-10 15:07:06 +08:00

30 lines
863 B
Python
Raw Permalink 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__ # 获取类名
if execution_time > 0.05:
logging.info(f"class name: {class_name} , run time is : {execution_time} s")
return result
return wrapper