Back to index

moin  1.9.0~rc2
Public Member Functions | Private Attributes
MoinMoin.support.werkzeug.contrib.profiler.ProfilerMiddleware Class Reference

List of all members.

Public Member Functions

def __init__
def __call__

Private Attributes

 _app
 _stream
 _sort_by
 _restrictions

Detailed Description

Simple profiler middleware.  Wraps a WSGI application and profiles
a request.  This intentionally buffers the response so that timings are
more exact.

For the exact meaning of `sort_by` and `restrictions` consult the
:mod:`profile` documentation.

:param app: the WSGI application to profile.
:param stream: the stream for the profiled stats.  defaults to stderr.
:param sort_by: a tuple of columns to sort the result by.
:param restrictions: a tuple of profiling strictions.

Definition at line 50 of file profiler.py.


Constructor & Destructor Documentation

def MoinMoin.support.werkzeug.contrib.profiler.ProfilerMiddleware.__init__ (   self,
  app,
  stream = None,
  sort_by = ('time', 'calls',
  restrictions = () 
)

Definition at line 65 of file profiler.py.

00065 
00066                  sort_by=('time', 'calls'), restrictions=()):
00067         if not available:
00068             raise RuntimeError('the profiler is not available because '
00069                                'profile or pstat is not installed.')
00070         self._app = app
00071         self._stream = stream or sys.stdout
00072         self._sort_by = sort_by
00073         self._restrictions = restrictions


Member Function Documentation

def MoinMoin.support.werkzeug.contrib.profiler.ProfilerMiddleware.__call__ (   self,
  environ,
  start_response 
)

Definition at line 74 of file profiler.py.

00074 
00075     def __call__(self, environ, start_response):
00076         response_body = []
00077 
00078         def catching_start_response(status, headers, exc_info=None):
00079             start_response(status, headers, exc_info)
00080             return response_body.append
00081 
00082         def runapp():
00083             appiter = self._app(environ, catching_start_response)
00084             response_body.extend(appiter)
00085             if hasattr(appiter, 'close'):
00086                 appiter.close()
00087 
00088         p = Profile()
00089         p.runcall(runapp)
00090         body = ''.join(response_body)
00091         stats = Stats(p)
00092         stats.sort_stats(*self._sort_by)
00093 
00094         self._stream.write('-' * 80)
00095         self._stream.write('\nPATH: %r\n' % environ.get('PATH_INFO'))
00096         stats.print_stats(*self._restrictions)
00097         self._stream.write('-' * 80 + '\n\n')
00098 
00099         return [body]
00100 

Here is the call graph for this function:


Member Data Documentation

Definition at line 69 of file profiler.py.

Definition at line 72 of file profiler.py.

Definition at line 71 of file profiler.py.

Definition at line 70 of file profiler.py.


The documentation for this class was generated from the following file: