我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用werkzeug.contrib.profiler.ProfilerMiddleware()。
def make_action(app_factory, hostname='localhost', port=5000, threaded=False, processes=1, stream=None, sort_by=('time', 'calls'), restrictions=()): """Return a new callback for :mod:`werkzeug.script` that starts a local server with the profiler enabled. :: from werkzeug.contrib import profiler action_profile = profiler.make_action(make_app) """ def action(hostname=('h', hostname), port=('p', port), threaded=threaded, processes=processes): """Start a new development server.""" from werkzeug.serving import run_simple app = ProfilerMiddleware(app_factory(), stream, sort_by, restrictions) run_simple(hostname, port, app, False, None, threaded, processes) return action
def setup_profiling(application): # Setup profiling from werkzeug.contrib.profiler import ProfilerMiddleware, MergeStream profiling_dir = 'profiling' f = open('profiler.log', 'w') stream = MergeStream(sys.stdout, f) if not os.path.exists(profiling_dir): os.makedirs(profiling_dir) application.config['PROFILE'] = True application.wsgi_app = ProfilerMiddleware( application.wsgi_app, stream, profile_dir=profiling_dir) application.debug = True