codecamp

WSGI Application Profiler

WSGI Application Profiler

This module provides a simple WSGI profiler middleware for findingbottlenecks in web application. It uses the profile orcProfile module to do the profiling and writes the stats to thestream provided (defaults to stderr).

Example usage:

from werkzeug.contrib.profiler import ProfilerMiddleware
app = ProfilerMiddleware(app)

class werkzeug.contrib.profiler.MergeStream(*streams)
An object that redirects write calls to multiple streams.Use this to log to both sys.stdout and a file:

f = open('profiler.log', 'w')
stream = MergeStream(sys.stdout, f)
profiler = ProfilerMiddleware(app, stream)

class werkzeug.contrib.profiler.ProfilerMiddleware(app, stream=None, sort_by=('time', 'calls'), restrictions=(), profile_dir=None)
Simple profiler middleware. Wraps a WSGI application and profilesa request. This intentionally buffers the response so that timings aremore exact.

By giving the profile_dir argument, pstat.Stats files are saved to thatdirectory, one file per request. Without it, a summary is printed tostream instead.

For the exact meaning of sort_by and restrictions consult theprofile documentation.

0.9 新版功能: Added support for restrictions and profile_dir.

参数:
  • app – the WSGI application to profile.
  • stream – the stream for the profiled stats. defaults to stderr.
  • sort_by – a tuple of columns to sort the result by.
  • restrictions – a tuple of profiling strictions, not used if dumpingto profile_dir.
  • profile_dir – directory name to save pstat files

werkzeug.contrib.profiler.make_action(app_factory, hostname='localhost', port=5000, threaded=False, processes=1, stream=None, sort_by=('time', 'calls'), restrictions=())
Return a new callback for werkzeug.script that starts a localserver with the profiler enabled.

from werkzeug.contrib import profiler
action_profile = profiler.make_action(make_app)
Fixers
Lint Validation Middleware
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }