<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def profile(fun, *args, **kwargs):
 """ Profile a function. """

    timer_name = kwargs.pop("prof_name", None)

    if not timer_name:
        module = inspect.getmodule(fun)
        c = [module.__name__]
        parentclass = labtypes.get_class_that_defined_method(fun)
        if parentclass:
            c.append(parentclass.__name__)
        c.append(fun.__name__)
        timer_name = ".".join(c)

    start(timer_name)
    ret = fun(*args, **kwargs)
    stop(timer_name)
    return ret