def METHOD_NAME(func: Optional[FunctionType] = None, /, *,
            sort_order: pstats.SortKey = pstats.SortKey.TIME, threshold_duration: float = 0.1):
    """
    Enables profiling for the wrapped function.
    Example 1:
        >>> @profile:
        ... def my_function():
                ...
    Example 2:
        >>> @profile(threshold_duration=1.0):
        ... def my_function():
                ...
    Args:
        func: positional-only argument for a function, used when the decorator is specified without parentheses;
        sort_order: how to sort the output, by default it's the time inside the function itself without nested calls;
        threshold_duration: do not print statistics if the function executed faster than the threshold duration.
    """
    def profile_decorator(func: FunctionType):
        @wraps(func)
        def profile_wrapper(*args, **kwargs):
            profiler = cProfile.Profile()
            prev_profiler = sys.getprofile()
            sys.setprofile(None)
            try:
                t = time.time()
                profiler.enable()
                try:
                    result = func(*args, **kwargs)
                finally:
                    profiler.disable()
                duration = time.time() - t
            finally:
                # To be able to combine the @profile decorator with the main thread stack tracing
                sys.setprofile(prev_profiler)
            if duration < threshold_duration:
                logger.info(f'Profiled function `{func.__name__}` executed in {duration:.3f} seconds')
            else:
                stats = _get_statistics(profiler, sort_order)
                logger.info(f'Profiled results for `{func.__name__}`:\n{stats}')
            return result
        return profile_wrapper
    if func is not None:
        return profile_decorator(func)
    return profile_decorator