class documentation

class ProfilerMiddleware:

View In Hierarchy

Wrap a WSGI application and profile the execution of each request. Responses are buffered so that timings are more exact.

If stream is given, pstats.Stats are written to it after each request. If profile_dir is given, cProfile data files are saved to that directory, one file per request.

The filename can be customized by passing filename_format. If it is a string, it will be formatted using str.format with the following fields available:

  • {method} - The request method; GET, POST, etc.
  • {path} - The request path or 'root' should one not exist.
  • {elapsed} - The elapsed time of the request.
  • {time} - The time of the request.

If it is a callable, it will be called with the WSGI environ dict and should return a filename.

from werkzeug.middleware.profiler import ProfilerMiddleware
app = ProfilerMiddleware(app)
Changed in version 0.15: Stats are written even if profile_dir is given, and can be disable by passing stream=None.
New in version 0.15: Added filename_format.
New in version 0.9: Added restrictions and profile_dir.
Parameters
appThe WSGI application to wrap.
streamWrite stats to this stream. Disable with None.
sort​_byA tuple of columns to sort stats by. See pstats.Stats.sort_stats.
restrictionsA tuple of restrictions to filter stats by. See pstats.Stats.print_stats.
profile​_dirSave profile data files to this directory.
filename​_formatFormat string for profile data file names, or a callable returning a name. See explanation above.
Method __call__ Undocumented
Method __init__ Undocumented
Instance Variable ​_app Undocumented
Instance Variable ​_filename​_format Undocumented
Instance Variable ​_profile​_dir Undocumented
Instance Variable ​_restrictions Undocumented
Instance Variable ​_sort​_by Undocumented
Instance Variable ​_stream Undocumented
def __call__(self, environ, start_response):

Undocumented

Parameters
environ:WSGIEnvironmentUndocumented
start​_response:StartResponseUndocumented
Returns
t.Iterable[bytes]Undocumented
def __init__(self, app, stream=sys.stdout, sort_by=('time', 'calls'), restrictions=(), profile_dir=None, filename_format='{method}.{path}.{elapsed:.0f}ms.{time:.0f}.prof'):

Undocumented

Parameters
app:WSGIApplicationUndocumented
stream:t.IO[str]Undocumented
sort​_by:t.Iterable[str]Undocumented
restrictions:t.Iterable[t.Union[str, int, float]]Undocumented
profile​_dir:t.Optional[str]Undocumented
filename​_format:strUndocumented
_app =

Undocumented

_filename_format =

Undocumented

_profile_dir =

Undocumented

_restrictions =

Undocumented

_sort_by =

Undocumented

_stream =

Undocumented