4

My problem is the following,

1 - I created a functools.wraps decorator function to log some runtime information.

I choose to use functools.wraps because it was supposed to update a wrapper function to look like the wrapped function.

So, my decorator look like this:

def log_execution(logger):

    def _log_execution(method):

        @functools.wraps(method)
        def _logged_execution(*args, **kwargs):
            logger.log('log some info')
            return method(*args, **kwargs)

        return _logged_execution

    return _log_execution

2 - Then, considering I decorated some of my functions like that:

# Create logger
current_logger = create_logger('logger test')


# Function func_a and 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 and sub functions
def func_b():
    func_b1()
    func_b2()

@log_execution(current_logger)
def func_b1():
    ...

@log_execution(current_logger)
def func_b2():
    ...

3 - Now if I profile my code and if I take a look at the generated reports, it is really hard to understand which function is called by another, when passing by this decorator.

For example: if I take a look at func_a call graph, I will have the following:

enter image description here

What I would like is:

enter image description here

or:

enter image description here

or:

enter image description here

So my question is:

How can I change the decorator function name dynamically to be able to better understand my profiling reports?

functools.wraps does not seems to do the job here!

Axel Borja
  • 3,718
  • 7
  • 36
  • 50

0 Answers0