def profiled(target=None, **target_opts):
 profile_config = {'targets': set(), 'report': True, 'print_callers': False, 'print_callees': False, 'graphic': False, 'sort': ('time', 'calls'), 'limit': None}
 if (target is None):
  target = 'anonymous_target'
 @decorator
 def decorate(fn, *args, **kw):
  (elapsed, load_stats, result) = _profile(fn, *args, **kw)
  graphic = target_opts.get('graphic', profile_config['graphic'])
  if graphic:
   os.system(('runsnake %s' % filename))
  else:
   report = target_opts.get('report', profile_config['report'])
   if report:
    sort_ = target_opts.get('sort', profile_config['sort'])
    limit = target_opts.get('limit', profile_config['limit'])
    print ("Profile report for target '%s'" % (target,))
    stats = load_stats()
    stats.sort_stats(*sort_)
    if limit:
     stats.print_stats(limit)
    else:
     stats.print_stats()
    print_callers = target_opts.get('print_callers', profile_config['print_callers'])
    if print_callers:
     stats.print_callers()
    print_callees = target_opts.get('print_callees', profile_config['print_callees'])
    if print_callees:
     stats.print_callees()
  return result
 return decorate

def profiled ( target = None , ** target_opts ) : profile_config = { 'targets' : set ( ) , 'report' : True , 'print_callers' : False , 'print_callees' : False , 'graphic' : False , 'sort' : ( 'time' , 'calls' ) , 'limit' : None } if ( target is None ) : target = 'anonymous_target' @ decorator def decorate ( fn , * args , ** kw ) : ( elapsed , load_stats , result ) = _profile ( fn , * args , ** kw ) graphic = target_opts . get ( 'graphic' , profile_config [ 'graphic' ] ) if graphic : os . system ( ( 'runsnake %s' % filename ) ) else : report = target_opts . get ( 'report' , profile_config [ 'report' ] ) if report : sort_ = target_opts . get ( 'sort' , profile_config [ 'sort' ] ) limit = target_opts . get ( 'limit' , profile_config [ 'limit' ] ) print ( "Profile report for target '%s'" % ( target , ) ) stats = load_stats ( ) stats . sort_stats ( * sort_ ) if limit : stats . print_stats ( limit ) else : stats . print_stats ( ) print_callers = target_opts . get ( 'print_callers' , profile_config [ 'print_callers' ] ) if print_callers : stats . print_callers ( ) print_callees = target_opts . get ( 'print_callees' , profile_config [ 'print_callees' ] ) if print_callees : stats . print_callees ( ) return result return decorate
this decorator should obviously be used only in a dev environment .