'Wraps the function call in a cProfile run, processing and logging the output with pstats.Stats
Useful for profiling individual checks.
:param func: The function to profile'

@staticmethod
def wrap_profiling(func):

    def wrapped_func(*args, **kwargs):
        try:
            profiler = cProfile.Profile()
            profiler.enable()
            log.debug('Agent    profiling    is    enabled')
        except Exception:
            log.warn('Cannot    enable    profiler')
        ret_val = func(*args, **kwargs)
        try:
            profiler.disable()
            s = StringIO()
            ps = pstats.Stats(profiler, stream=s).sort_stats('cumulative')
            ps.print_stats(AgentProfiler.PSTATS_LIMIT)
            log.info(s.getvalue())
        except Exception:
            log.warn('Cannot    disable    profiler')
        return ret_val
    return wrapped_func
