HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/cherrypy/lib/__pycache__/profiler.cpython-310.pyc
o

�N�g��@s�dZddlZddlZddlZddlZddlZddlZzddlZddlZdd�Z	e	e_
Wn
ey8dZdZYnwdaGdd�de
�ZGdd�de�ZGd	d
�d
�Zddd
�Zedkrheeejdd���dSdS)aiProfiler tools for CherryPy.

CherryPy users
==============

You can profile any of your pages as follows::

    from cherrypy.lib import profiler

    class Root:
        p = profiler.Profiler("/path/to/profile/dir")

        @cherrypy.expose
        def index(self):
            self.p.run(self._index)

        def _index(self):
            return "Hello, world!"

    cherrypy.tree.mount(Root())

You can also turn on profiling for all requests
using the ``make_app`` function as WSGI middleware.

CherryPy developers
===================

This module can be used whenever you make changes to CherryPy,
to get a quick sanity-check on overall CP performance. Use the
``--profile`` flag when running the test suite. Then, use the ``serve()``
function to browse the results in a web browser. If you run this
module from the command line, it will call ``serve()`` for you.

�NcCsL|\}}}|�d�rtj�|dd��|dd�||fStj�|�||fS)zQMake profiler output more readable by adding `__init__` modules' parents
        z__init__.pyNi�)�endswith�os�path�basename)Z	func_name�filename�line�name�r	�I/opt/saltstack/salt/lib/python3.10/site-packages/cherrypy/lib/profiler.py�new_func_strip_path1s

�rc@sZeZdZddd�Zdd�Zdd�Zdd	d
�Zejdd��Z	ejd
d��Z
ejdd��ZdS)�ProfilerNcCs>|s
tj�tj�t�d�}||_tj�|�st�|�dSdS)N�profile)rr�join�dirname�__file__�exists�makedirs��selfrr	r	r
�__init__Hs�zProfiler.__init__cOsNtd}atj�|jd|�}t��}|j|g|�Ri|��}|�|�|S)z!Dump profile data into self.path.��cp_%04d.prof)�_countrrrr
�Profile�runcall�
dump_stats)r�func�args�params�crZprof�resultr	r	r
�runOs
zProfiler.runcCsdd�t�|j�D�S)z,:rtype: list of available profiles.
        cSs$g|]}|�d�r|�d�r|�qS)Zcp_z.prof)�
startswithr)�.0�fr	r	r
�
<listcomp>\s
�
�z&Profiler.statfiles.<locals>.<listcomp>)r�listdirr�rr	r	r
�	statfilesYszProfiler.statfiles�
cumulativecCs�t��}tjdkr$tjtj�|j|�|d�}|�	�|�
|�|��n(t�tj�|j|��}|�	�|�
|�tj}z|t_|��W|t_n|t_w|�
�}|��|S)zL:rtype stats(index): output of print_stats() for the given profile.
        )��)�stream)�io�StringIO�sys�version_info�pstatsZStatsrrrZ
strip_dirsZ
sort_statsZprint_stats�stdout�getvalue�close)rrZsortby�sio�sZoldout�responser	r	r
�stats_s"




zProfiler.statscCsdS)Nz�<html>
        <head><title>CherryPy profile data</title></head>
        <frameset cols='200, 1*'>
            <frame src='menu' />
            <frame name='main' src='' />
        </frameset>
        </html>
        r	r'r	r	r
�indexxszProfiler.indexccs:�dVdV|��}|��|D]	}d||fVqdS)Nz<h2>Profiling runs</h2>z<<p>Click on one of the runs below to see profiling data.</p>z7<a href='report?filename=%s' target='main'>%s</a><br />)r(�sort)r�runs�ir	r	r
�menu�s�
��z
Profiler.menucCsdtjjd<|�|�S)Nz
text/plainzContent-Type)�cherrypyr7�headersr8)rrr	r	r
�report�s
zProfiler.report�N)r))�__name__�
__module__�__qualname__rr!r(r8r>Zexposer9r=r@r	r	r	r
rFs





	rc@seZdZddd�Zdd�ZdS)�ProfileAggregatorNcCs(t�||�td|_at��|_dS)Nr)rrr�countr
r�profilerrr	r	r
r�szProfileAggregator.__init__cOs@tj�|jd|j�}|jj|g|�Ri|��}|j�|�|S)Nr)rrrrFrGrr)rrrrrr r	r	r
r!�szProfileAggregator.runrA)rBrCrDrr!r	r	r	r
rE�s
rEc@seZdZddd�Zdd�ZdS)�make_appNFcCsJtdustdurd}t�|�||_||_|rt|�|_dSt|�|_dS)a�Make a WSGI middleware app which wraps 'nextapp' with profiling.

        nextapp
            the WSGI application to wrap, usually an instance of
            cherrypy.Application.

        path
            where to dump the profiling output.

        aggregate
            if True, profile data for all HTTP requests will go in
            a single file. If False (the default), each HTTP request will
            dump its profile data into a separate file.

        N��Your installation of Python does not have a profile module. If you're on Debian, try `sudo apt-get install python-profiler`. See http://www.cherrypy.org/wiki/ProfilingOnDebian for details.)	r
r1�warnings�warn�nextapp�	aggregaterErGr)rrLrrM�msgr	r	r
r�s
zmake_app.__init__cs���fdd�}�j�|�S)Ncs$g}�����D]}|�|�q|SrA)rL�append)r r��environr�start_responser	r
�gather�sz!make_app.__call__.<locals>.gather)rGr!)rrQrRrSr	rPr
�__call__�szmake_app.__call__)NF)rBrCrDrrTr	r	r	r
rH�s
rH�cCsHtdustdurd}t�|�tj�t|�ddd��t�t	|��dS)NrI�
�
production)zserver.socket_portzserver.thread_poolZenvironment)
r
r1rJrKr>Zconfig�update�intZ
quickstartr)r�portrNr	r	r
�serve�s
�r[�__main__r)NrU)�__doc__r-rZos.pathr/rJr>r
r1rZfunc_strip_path�ImportErrorr�objectrrErHr[rB�tuple�argvr	r	r	r
�<module>s0#
�M
*�