def profile_func(filename=None):
 def proffunc(fun):
  def profiled_func(*args, **kwargs):
   logging.info('Profiling function {0}'.format(fun.__name__))
   try:
    profiler = cProfile.Profile()
    retval = profiler.runcall(fun, *args, **kwargs)
    profiler.dump_stats((filename or '{0}_func.profile'.format(fun.__name__)))
   except IOError:
    logging.exception('Could not open profile file {0}'.format(filename))
   return retval
  return profiled_func
 return proffunc

def profile_func ( filename = None ) : def proffunc ( fun ) : def profiled_func ( * args , ** kwargs ) : logging . info ( 'Profiling function {0}' . format ( fun . __name__ ) ) try : profiler = cProfile . Profile ( ) retval = profiler . runcall ( fun , * args , ** kwargs ) profiler . dump_stats ( ( filename or '{0}_func.profile' . format ( fun . __name__ ) ) ) except IOError : logging . exception ( 'Could not open profile file {0}' . format ( filename ) ) return retval return profiled_func return proffunc
decorator for adding profiling to a nested function in salt .