zmc
2023-12-22 9fdbf60165db0400c2e8e6be2dc6e88138ac719a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
U
Þ=®d*ã@sªdZddlmZddlZddlZddlZddlZddl    m
Z
zddl m Z Wn e k
rlddlm Z YnXejr˜ddlmZddlmZddlmZGd    d
„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
é)Ú annotationsN)ÚStats)ÚProfile)Ú StartResponse)ÚWSGIApplication)ÚWSGIEnvironmentc    @sJeZdZdZejddddfdddd    d
d d d œdd„Zddddœdd„ZdS)ÚProfilerMiddlewareaWrap 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``.
    )ÚtimeZcalls©Nz/{method}.{path}.{elapsed:.0f}ms.{time:.0f}.profrzt.IO[str] | Nonezt.Iterable[str]zt.Iterable[str | int | float]z
str | NoneÚstrÚNone)ÚappÚstreamÚsort_byÚ restrictionsÚ profile_dirÚfilename_formatÚreturncCs(||_||_||_||_||_||_dS©N)Ú_appÚ_streamÚ_sort_byÚ _restrictionsÚ _profile_dirÚ_filename_format)Úselfr rrrrrr
r
úSd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\werkzeug/middleware/profiler.pyÚ__init__Os     zProfilerMiddleware.__init__rrzt.Iterable[bytes])ÚenvironÚstart_responserc sDg‰d‡‡fdd„    ‰ddœ‡‡‡‡fdd„ }tƒ}t ¡}| |¡d ˆ¡}t ¡|}ˆjdk    rÊtˆjƒrzˆ ˆ¡}n6ˆjjˆdˆd     d
¡     d
d ¡pžd |d t ¡d}t
j  ˆj|¡}|  |¡ˆj dk    r>t|ˆj d}    |    jˆjŽtdˆj dˆ d    d¡}
td|
›ˆj d|    jˆjŽtd›dˆj d|gS)Ncsˆ|||ƒˆjSr)Úappend)ÚstatusÚheadersÚexc_info)Ú response_bodyrr
rÚcatching_start_responseds z<ProfilerMiddleware.__call__.<locals>.catching_start_responser )rcs4ˆ ˆt dˆ¡¡}ˆ |¡t|dƒr0| ¡dS)NrÚclose)rÚtÚcastÚextendÚhasattrr&)Zapp_iter)r%rr$rr
rÚrunapphs
ÿ
 
z+ProfilerMiddleware.__call__.<locals>.runappóÚREQUEST_METHODZ    PATH_INFOú/Ú.Úrootg@@)ÚmethodÚpathÚelapsedr    )rzP--------------------------------------------------------------------------------)ÚfileÚzPATH: Ú
)N)rr    ZruncallÚjoinrÚcallablerÚformatÚstripÚreplaceÚosr2Z
dump_statsrrZ
sort_statsrÚprintÚgetZ print_statsr) rrrr+ÚprofileÚstartÚbodyr3ÚfilenameÚstatsZ    path_infor
)r%rr$rrrÚ__call___s8    
 
 
 
 ü
    zProfilerMiddleware.__call__)Ú__name__Ú
__module__Ú __qualname__Ú__doc__ÚsysÚstdoutrrDr
r
r
rr!s0ùr)rHÚ
__future__rÚos.pathr<rIr    Útypingr'ZpstatsrZcProfilerÚ ImportErrorr?Ú TYPE_CHECKINGZ_typeshed.wsgirrrrr
r
r
rÚ<module>s