HEX
Server: LiteSpeed
System: Linux us-phx-web1284.main-hosting.eu 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: u300739242 (300739242)
PHP: 8.2.30
Disabled: system, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail
Upload Files
File: //opt/alt/python37/lib/python3.7/site-packages/exabgp/vendoring/__pycache__/profiler.cpython-37.pyc
B

RP�e�M�
@s�dZdZdZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZyddlm
Z
mZWn$ek
r�ddlm
Z
mZYnXyddlZdd�ZWn:ek
r�e�d	�ejd
kr�dd�Zned��YnXGd
d�de
�Zd9dd�Zdd�ZGdd�d�Zd:dd�Zd;dd�Zdd�Zd<dd �Zd!d"�Zd=d#d$�Ze d%k�r�dd&l!m"Z"e"eed'�Z#e#�$�e#j%d(d)d*d+d,d-d.�e#j%d/d0d1d,dd2d3�ej&d4d��s�e#�'�e�(d5�e#�)�\Z*Z+ej&d=ee*j,d6�Z-ee+d�Z.z�ej/ddk�r2ddl0Z0e-e0j1d$<ee2��Z3e-e3d$<e4e.e3e3�nFddl5Z5e-e5j1d$<ee2��Z3e-e3d$<e6e7e8e.��9�e.d7�e3ee:���Wdee-e*j;d8�XdS)>z,Profile the memory usage of a Python programz0.26z(python -m memory_profiler script_file.py�N)�copy)�Process�PipecCsBt�|�}yt|��d�d}Wntjk
r<d}YnX|S)Nri���)�psutilr�floatZget_memory_infoZAccessDenied)�pid�process�mem�r�J/opt/alt/python37/lib/python3.7/site-packages/exabgp/vendoring/profiler.py�_get_memorys

r
z5psutil module not found. memory_profiler will be slow�posixcCsntjdddt|�gtjd���d�d�}y*|d���d�}t|d��|�d	Stk
rhd
SXdS)NZps�vz-p)�stdoutr�
sRSS�ir)	�
subprocess�Popen�str�PIPE�communicate�split�indexr�	Exception)r�outZ	vsz_indexrrrr
*s*z4The psutil module is required for non-unix platformscs(eZdZdZ�fdd�Zdd�Z�ZS)�Timerz<
    Fetch memory consumption from over a time interval
    cs.||_||_||_d|_tt|�j||�dS)NT)�monitor_pid�interval�pipe�cont�superr�__init__)�selfrrr�args�kw)�	__class__rrr"@s
zTimer.__init__cCsTt|j�}|g}|j�d�x&|j�|j�sBt|j�}|�|�qW|j�|�dS)Nr)r
rr�send�pollr�append)r#�mZtimingsrrr�runGs

z	Timer.run)�__name__�
__module__�__qualname__�__doc__r"r+�
__classcell__rr)r&rr;srr皙�����?cCs*g}|dk	rt||�}nt|t�r*d}ntd�}t|d�rF|dif}t|ttf��rpt|�dkrx|ddi}}}nTt|�dkr�|d|di}}}n.t|�dkr�|d|d|d}}}nt�t�	|�}t|j
�}	|jdk	r�|	t|j�8}	|	t|�k�rtd	|	t|�f��t�\}
}t
t��||
�}|��|��|||�|�d�|��}|�d
|�n�t|tj��r�x�|�t|j��t�|�|dk	�r�|d8}|dk�r�P|��dk	�r�P�q�WnV|dk�r�t��}|dk�r�d}d}
x0|
|k�r$|
d7}
|�t|��t�|��q�W|S)a+
    Return the memory usage of a process or piece of code

    Parameters
    ----------
    proc : {int, string, tuple, subprocess.Popen}, optional
        The process to monitor. Can be given by an integer/string
        representing a PID, by a Popen object or by a tuple
        representing a Python function. The tuple contains three
        values (f, args, kw) and specifies to run the function
        f(*args, **kw).
        Set to -1 (default) for current process.

    interval : float, optional
        Interval at which measurements are collected.

    timeout : float, optional
        Maximum amount of time (in seconds) to wait before returning.

    Returns
    -------
    mem_usage : list of floating-poing values
        memory usage, in MB. It's length is always < timeout / interval
    Nr�inf�__call__rr��z/Function expects %s value(s) but %s where given�r)�int�
isinstancer�hasattr�list�tuple�len�
ValueError�inspect�
getargspecr$�defaultsrr�os�getpid�start�recvr'�joinrrr)r
r�time�sleepr()�procr�timeout�retZmax_iter�fr$r%ZaspecZn_argsZ
child_connZparent_conn�p�counterrrr�memory_usageQsd














rNcCsztj�|�r|St�dtj��tj�}x4|D],}|dkr:q,tj�||�}tj�|�r,|Sq,Wtj	�
d�|��td��dS)zT Find the script.

    If the input is not a file, then $PATH will be searched.
    �PATH�zCould not find script {0}
rN)
rA�path�isfile�getenv�defpathr�pathseprE�sys�stderr�write�format�
SystemExit)�script_namerQ�folder�fnrrr�_find_script�s
r^c@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd S)!�LineProfilerz< A profiler that records the amount of memory for each line cKs&t�|_i|_d|_|�dd�|_dS)Nr�max_mem)r:�	functions�code_map�enable_count�getr`)r#r%rrrr"�szLineProfiler.__init__cCsD|�|�|�|�}|j|_|j|_|j|_|j�t|di��|S)N�__dict__)�add_function�
wrap_functionr-r,r/re�update�getattr)r#�funcrKrrrr3�s

zLineProfiler.__call__cCs\y
|j}Wn,tk
r6ddl}|�d|f�dSX||jkrXi|j|<|j�|�dS)zJ Record line profiling information for the given Python function.
        rNz1Could not extract a code object for the object %r)�__code__�AttributeError�warnings�warnrbrar))r#rj�codermrrrrf�s


zLineProfiler.add_functioncs��fdd�}|S)z( Wrap a function to profile it.
        cs&���z�||�}Wd���X|S)N)�enable_by_count�disable_by_count)r$�kwds�result)rjr#rrrK�s

z%LineProfiler.wrap_function.<locals>.fr)r#rjrKr)rjr#rrg�szLineProfiler.wrap_functioncCsddl}|j}|�|||�S)zE Profile a single executable statment in the main namespace.
        rN)�__main__re�runctx)r#�cmdrtZ	main_dictrrrr+�szLineProfiler.runcCs(|��zt|||�Wd|��X|S)zH Profile a single executable statement in the given namespaces.
        N)rp�execrq)r#rv�globals�localsrrrru�s

zLineProfiler.runctxcOs"|��z
|||�S|��XdS)z) Profile a single function call.
        N)rprq)r#rjr$r%rrr�runcalls
zLineProfiler.runcallcCs$|jdkr|��|jd7_dS)z? Enable the profiler if it hasn't been enabled before.
        rrN)rc�enable)r#rrrrps
zLineProfiler.enable_by_countcCs.|jdkr*|jd8_|jdkr*|��dS)zo Disable the profiler if the number of disable requests matches the
        number of enable requests.
        rrN)rc�disable)r#rrrrqs

zLineProfiler.disable_by_countcCsV|dkrP|j|jkrP|j}|dkr*|d7}|j|j�|g�}|�tt����|jS)zCallback for sys.settrace)�line�returnr~r)	�f_coderb�f_lineno�
setdefaultr)r
rArB�trace_memory_usage)r#�frame�event�arg�lineno�entryrrrr�szLineProfiler.trace_memory_usagecCs�|dkr�|j|jkr�tt���}||jkr�d�|�d�|j�}tj�	|�tj�	d�|j
d8_
t��}d|_
||_d|_|j
d|_d|_|jS|jS)N)r}r~z/Current memory {0:.2f} MB exceeded the maximum zof {0:.2f} MB
zStepping into the debugger 
r4Fr5)rrbr
rArBr`rYrVrrXr��pdbZPdbZquittingZ	stopframeZreturnframeZ
stoplinenoZbotframeZtrace_dispatch�
trace_max_mem)r#r�r�r��c�trLrrrr�&s
zLineProfiler.trace_max_memcCs|��dS)N)rp)r#rrr�	__enter__9szLineProfiler.__enter__cCs|��dS)N)rq)r#�exc_type�exc_val�exc_tbrrr�__exit__<szLineProfiler.__exit__cCs(|jdk	rt�|j�nt�|j�dS)N)r`rV�settracer�r�)r#rrrr{?s
zLineProfiler.enablecCsi|_t�d�dS)N)Z	last_timerVr�)r#rrrr|EszLineProfiler.disableN)r,r-r.r/r"r3rfrgr+rurzrprqr�r�r�r�r{r|rrrrr_�s 	

	r_r5cCs�|dkrtj}d}�x~|jD�]r}|j|}|s2q|j}|�d�rN|dd�}|�d|d�tj�|�s�|�d|d�|�	d�s�|�	d	�rt
d
�qt�|�}t
�||jdd��}t|j|jt|��}	i}
|�dd
dd�}|�|d�|�dt|�d�t|���}|dd}
||d|
|dd<x8tdt|
|dd��D]}d|
|dd|<�qXW|�d�}x\|�r�||d|
|<x0tt|
|
�t|
|��D]}d|
||<�q�W|}
|�d�}�q�Wt|
���d}t|
|�}t|�}d�|d|�d}xnt|	�D]b\}}d}d}||
k�rft|
|�}||}|}|�|�}|�|�}|�|�|||||���q W|�d�qWdS)Nz{0:>6} {1:>12} {2:>12}   {3:<})z.pycz.pyorz
Filename: z

zERROR: Could not find file �
z
ipython-inputz<ipython-inputziNOTE: %mprun can only be used on functions defined in physical files, and not in the IPython environment.rzLine #z	Mem usageZ	Incrementz
Line Contents�=rg�z{{0:{0}.{1}�zf} MBrP)rVrrb�co_filename�endswithrXrArQ�exists�
startswith�print�	linecache�getlinesr>�getblock�co_firstlineno�ranger<rY�sorted�keys�pop�maxr7�	enumerate)�prof�stream�	precision�templatero�lines�filename�	all_linesZ	sub_linesZlinenosZlines_normalized�headerr�Zk_old�i�k�
first_lineZmem_oldZtemplate_mem�lr
�incrrr�show_resultsJsf


 
 


 r�rPcCs�yddlm}Wn tk
r0ddlm}YnXddlm}ddl}||j�}|dkr~ddlm}ddl	m
}ddlm}n$ddl
m}ddlm
}ddlm}|d	ggd
�}	|�dd��d
d�}|j|ddd�\}
}|
�|	�|jj}|jj}
g}x`|
jD]V}y|�t|||
��Wq�tk
�rR}z|d||jj|f��Wdd}~XYq�Xq�Wt�}x|D]}||��qdWyddl}Wntk
�r�ddl}YnXd|jk�r�d}|jd}nd}d}||jd<zNy|� |||
�d	}Wn2t!k
�rd}Ynt"k
�rd}YnXWd|�r0||jd<X|�}t#||�|�$�}|�%�}|dk�rp|||jj&j'd�n||�t(|�|
j)d}|�r�t*|d��}|�+|�WdQRXt(d||f�d}d|
k�r�|}|S)a� Execute a statement under the line-by-line memory profiler from the
    memory_profilser module.

    Usage:
      %mprun -f func1 -f func2 <statement>

    The given statement (which doesn't require quote marks) is run via the
    LineProfiler. Profiling is enabled for the functions specified by the -f
    options. The statistics will be shown side-by-side with the code through
    the pager once the statement has completed.

    Options:

    -f <function>: LineProfiler only profiles functions and methods it is told
    to profile.  This option tells the profiler about these functions. Multiple
    -f options may be used. The argument may be any expression that gives
    a Python function or method object. However, one must be careful to avoid
    spaces that may confuse the option parser. Additionally, functions defined
    in the interpreter at the In[] prompt or via %run currently cannot be
    displayed.  Write these functions out to a separate file and import them.

    One or more -f options are required to get any useful results.

    -T <filename>: dump the text-formatted statistics with the code
    side-by-side out to a text file.

    -r: return the LineProfiler object after it has completed profiling.
    r)�StringIO)�LooseVersionNz0.11)�page)�Struct)�
UsageErrorrP)�TrK�"z\"�'z\'zrf:T:T)Zlist_allz"Could not find function %r.
%s: %s�profileFz7*** SystemExit exception caught in code being profiled.z>*** KeyboardInterrupt exception caught in code being profiled.)Zscreen_lines�wz/
*** Profile printout saved to text file %s. %s�r),r��ImportError�ioZdistutils.versionr��IPython�__version__ZIPython.genutilsr�ZIPython.ipstructr�Z
IPython.ipapir�ZIPython.core.pageZIPython.utils.ipstructZIPython.core.error�replace�
parse_options�merge�shellZuser_global_ns�user_nsrKr)�evalrr&r,r_�builtins�__builtin__rerurZ�KeyboardInterruptr��getvalue�rstrip�rcZ
screen_lengthr�r��openrX)r#Zparameter_sr�r�r�Zipython_versionr�r�r�Zopts_def�optsZarg_str�	global_nsZlocal_ns�funcs�name�er�rjr�Zhad_profileZold_profile�messageZstdout_trap�outputZ	text_fileZpfileZreturn_valuerrr�magic_mprun�s�

,





r�cCst||�dS)N)rw)�stmt�nsrrr�
_func_execsr�c	Cs�|j|dddd�\}}tt|dd��}|dkr2d}tt|dd��}|dkrNd}g}x2t|�D]&}tt||jjff|d	�}|�|�q\W|r�t	d
|t
|�f�nt	d�dS)a:Measure memory usage of a Python statement

    Usage, in line mode:
      %memit [-r<R>t<T>] statement

    Options:
    -r<R>: repeat the loop iteration <R> times and take the best result.
    Default: 1

    -t<T>: timeout after <T> seconds. Default: None

    Examples
    --------
    ::

      In [1]: import numpy as np

      In [2]: %memit np.zeros(1e7)
      maximum of 1: 76.402344 MB per loop

      In [3]: %memit np.ones(1e6)
      maximum of 1: 7.820312 MB per loop

      In [4]: %memit -r 10 np.empty(1e8)
      maximum of 10: 0.101562 MB per loop

    zr:tF)r�strictr�rr�rN)rIzmaximum of %d: %f MB per loopzPERROR: could not read memory usage, try with a lower interval or more iterations)r�r7rir�rNr�r�r��extendr�r�)	r#r}r�r��repeatrIZ	mem_usage�_�tmprrr�magic_memitsr�cCs|�dt�|�dt�dS)z:This is called to load the module as an IPython extension.ZmprunZmemitN)Zdefine_magicr�r�)�iprrr�load_ipython_extension6sr�cs��fdd�}|S)zO
    Decorator that will run the function and print a line-by-line profile
    cs$t�}|��||�}t|�d�|S)N)r�)r_r�)r$�kwargsr��val)rjr�rr�wrapperAszprofile.<locals>.wrapperr)rjr�r�r)rjr�rr�<sr�rt)�OptionParser)�usage�versionz
--pdb-mmemr`ZMAXMEMr�storez1step into the debugger when memory exceeds MAXMEM)�dest�metavar�type�action�helpz--precisionr�r7z:precision of memory output in number of significant digits)r�r�r��defaultr�rr4)r`rw)r�)rr1N)Nr5)rP)rP)N)<r/r�Z
_CMD_USAGErFrVrAr�rmr�r>rr�multiprocessingrrr�Zmultiprocessing.dummyrr
rnr��NotImplementedErrorrrNr^r_r�r�r�r�r�r�r,�optparser��parser�disable_interspersed_args�
add_option�argv�
print_help�exit�
parse_args�optionsr$r`r��__file__�version_infor�reryr�Zexecfiler�rw�compiler��readrxr�rrrr�<module>s� 	



\
?
w
/






&