python - How can I change the decorator function name dynamically to be able to understand cProfile reports? -
my problem following,
1 - created functools.wraps
decorator function log runtime information.
i choose use functools.wraps
because supposed update wrapper function wrapped function
.
so, decorator this:
def log_execution(logger): def _log_execution(method): @functools.wraps(method) def _logged_execution(*args, **kwargs): logger.log('log info') return method(*args, **kwargs) return _logged_execution return _log_execution
2 - then, considering decorated of functions that:
# create logger current_logger = create_logger('logger test') # function func_a , sub functions def func_a(): func_a1() func_a2() @log_execution(current_logger) def func_a1(): ... @log_execution(current_logger) def func_a2(): ... # function func_b , sub functions def func_b(): func_b1() func_b2() @log_execution(current_logger) def func_b1(): ... @log_execution(current_logger) def func_b2(): ...
3 - if profile code , if take @ generated reports, hard understand function called another, when passing decorator.
for example: if take @ func_a
call graph, have following:
what is:
or:
or:
so question is:
how can change decorator function name dynamically able better understand profiling reports?
functools.wraps
not seems job here!
Comments
Post a Comment