def decorator(fn): def profiled(*args, **kw): if (target not in profile_config['targets'] and not target_opts.get('always', None)): return fn(*args, **kw) elapsed, load_stats, result = _profile(filename, fn, *args, **kw) 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' (%s)" % (target, filename) stats = load_stats() stats.sort_stats(*sort_) if limit: stats.print_stats(limit) else: stats.print_stats() #stats.print_callers() os.unlink(filename) return result return function_named(profiled, fn.__name__)
def decorator(fn): def counted(*args, **kw): try: filename = "%s.prof" % fn.__name__ elapsed, stat_loader, result = _profile( filename, fn, *args, **kw) stats = stat_loader() calls = stats.total_calls stats.sort_stats('calls', 'cumulative') stats.print_stats() #stats.print_callers() deviance = int(count * variance) if (calls < (count - deviance) or calls > (count + deviance)): raise AssertionError( "Function call count %s not within %s%% " "of expected %s. (Python version %s)" % (calls, (variance * 100), count, py_version)) return result finally: if os.path.exists(filename): os.unlink(filename) return function_named(counted, fn.__name__)
def decorator(fn): def profiled(*args, **kw): if (target not in profile_config['targets'] and not target_opts.get('always', None)): return fn(*args, **kw) elapsed, load_stats, result = _profile( filename, fn, *args, **kw) 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' (%s)" % ( target, filename) stats = load_stats() stats.sort_stats(*sort_) if limit: stats.print_stats(limit) else: stats.print_stats() #stats.print_callers() os.unlink(filename) return result return function_named(profiled, fn.__name__)
def decorator(fn): def counted(*args, **kw): try: filename = "%s.prof" % fn.__name__ elapsed, stat_loader, result = _profile( filename, fn, *args, **kw) stats = stat_loader() calls = stats.total_calls stats.sort_stats('calls', 'cumulative') stats.print_stats() #stats.print_callers() deviance = int(count * variance) if (calls < (count - deviance) or calls > (count + deviance)): raise AssertionError( "Function call count %s not within %s%% " "of expected %s. (Python version %s)" % ( calls, (variance * 100), count, py_version)) return result finally: if os.path.exists(filename): os.unlink(filename) return function_named(counted, fn.__name__)
def decorator(fn): def at_runtime(*args, **kw): criteria = categories.get(discriminator(), None) if criteria is None: return fn(*args, **kw) rewrapped = function_call_count(*criteria)(fn) return rewrapped(*args, **kw) return function_named(at_runtime, fn.__name__)
def decorator(fn): def at_runtime(*args, **kw): criteria = categories.get(discriminator(), None) if criteria is None: return fn(*args, **kw) rewrapped = function_call_count(*criteria)(fn) return rewrapped(*args, **kw) return function_named(at_runtime, fn.__name__)