/usr/local/lib/python3.6/site-packages/werkzeug/middleware/__pycache__
Edit: /usr/local/lib/python3.6/site-packages/werkzeug/middleware/__pycache__/profiler.cpython-36.pyc (4804B)
3
_TBg# @ s d Z ddlZddlZddlZddlZddlmZ yddl m
Z
W n ek
r` ddlm
Z
Y nX ej
rddlmZ ddlmZ ddlmZ G dd d ZdS )
a9
Application Profiler
====================
This module provides a middleware that profiles each request with the
:mod:`cProfile` module. This can help identify bottlenecks in your code
that may be slowing down your application.
.. autoclass:: ProfilerMiddleware
:copyright: 2007 Pallets
:license: BSD-3-Clause
N)Stats)Profile)
StartResponse)WSGIApplication)WSGIEnvironmentc @ st e Zd ZdZejdf ddfdeje ej e ej ej
eeef ej
e edddd Zd
dej e dd
dZdS )ProfilerMiddlewarea Wrap a WSGI application and profile the execution of each
request. Responses are buffered so that timings are more exact.
If ``stream`` is given, :class:`pstats.Stats` are written to it
after each request. If ``profile_dir`` is given, :mod:`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 :meth:`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.
:param app: The WSGI application to wrap.
:param stream: Write stats to this stream. Disable with ``None``.
:param sort_by: A tuple of columns to sort stats by. See
:meth:`pstats.Stats.sort_stats`.
:param restrictions: A tuple of restrictions to filter stats by. See
:meth:`pstats.Stats.print_stats`.
:param profile_dir: Save profile data files to this directory.
:param filename_format: Format string for profile data file names,
or a callable returning a name. See explanation above.
.. code-block:: python
from werkzeug.middleware.profiler import ProfilerMiddleware
app = ProfilerMiddleware(app)
.. versionchanged:: 0.15
Stats are written even if ``profile_dir`` is given, and can be
disable by passing ``stream=None``.
.. versionadded:: 0.15
Added ``filename_format``.
.. versionadded:: 0.9
Added ``restrictions`` and ``profile_dir``.
timecallsNz/{method}.{path}.{elapsed:.0f}ms.{time:.0f}.profr )appstreamsort_byrestrictionsprofile_dirfilename_formatreturnc C s( || _ || _|| _|| _|| _|| _d S )N)_app_stream_sort_by
_restrictions_profile_dir_filename_format)selfr
r r r
r r r @/tmp/pip-build-0s3hx122/Werkzeug/werkzeug/middleware/profiler.py__init__M s zProfilerMiddleware.__init__r r )environstart_responser c sL g dfdd d d fdd}t }tj }|j| dj}tj | }jd k rtjrzj}n6jjd d jd j d d
pd|d tj d
}t
jjj|}|j| j
d k rFt|j
d} | jj tdd j
d jdd}
td|
j
d | jj tdd dj
d |gS )Nc s | || j S )N)append)statusheadersexc_info)
response_bodyr r r catching_start_responseb s z
.catching_start_response)r c s4 j tjd } j| t| dr0| j d S )Nr close)r tcastextendhasattrr# )Zapp_iter)r" r r! r r r runappf s
z+ProfilerMiddleware.__call__..runapp REQUEST_METHODZ PATH_INFO/.rootg @@)methodpathelapsedr )r -P )file zPATH:
)N)r r Zruncalljoinr callabler formatstripreplaceosr/ Z
dump_statsr r Z
sort_statsr printgetZprint_statsr )r r r r( profilestartbodyr0 filenamestatsZ path_infor )r" r r! r r r __call__] s6
zProfilerMiddleware.__call__)r r )__name__
__module____qualname____doc__sysstdoutr$ ZIOstrIterableUnionintfloatOptionalr bytesrC r r r r r s ,4 r )rG os.pathr; rH r Ztypingr$ Zpstatsr ZcProfiler ImportErrorr> Z
TYPE_CHECKINGZ_typeshed.wsgir r r r r r r r
s