HEX
Server: Apache
System: Linux sh-pro142.hostgator.com.br 5.14.0-162.23.1.9991722448259.nf.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jul 31 18:11:45 UTC 2024 x86_64
User: okform09 (1324)
PHP: 8.3.30
Disabled: NONE
Upload Files
File: //usr/libexec/oracle-cloud-agent/plugins/osms/tracemalloc.pyc
a

���dF�@sddlmZmZddlmZddlZddlZddlZddl	Z	ddl
Tddl
mZmZdd�Z
Gdd	�d	�ZGd
d�d�Zdd
�ZeGdd�d��ZeGdd�de��Zdd�ZGdd�d�ZGdd�de�Zdd�ZGdd�d�ZGdd�de�ZGdd�de�ZGd d!�d!�Zd"d#�ZdS)$�)�Sequence�Iterable)�total_orderingN)�*)�_get_object_traceback�_get_tracescCs�dD]|}t|�dkr@|dkr@|r0d||fSd||fSt|�dksT|dkrx|rhd||fSd	||fS|d
}qdS)N)�B�KiB�MiB�GiB�TiB�drz%+.1f %sz%.1f %si(rz%+.0f %sz%.0f %si)�abs)�size�sign�unit�r�#/usr/lib64/python3.9/tracemalloc.py�_format_size
src@sDeZdZdZdZdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dS)�	StatisticzS
    Statistic difference on memory allocations between two Snapshot instance.
    ��	tracebackr�countcCs||_||_||_dS�Nr)�selfrrrrrr�__init__%szStatistic.__init__cCst|j|j|jf�Sr)�hashrrr�rrrr�__hash__*szStatistic.__hash__cCs2t|t�stS|j|jko0|j|jko0|j|jkSr)�
isinstancer�NotImplementedrrr�r�otherrrr�__eq__-s

�
�zStatistic.__eq__cCsBd|jt|jd�|jf}|jr>|j|j}|dt|d�7}|S)Nz%s: size=%s, count=%iF�, average=%s)rrrr�r�text�averagerrr�__str__4s
��zStatistic.__str__cCsd|j|j|jfS)Nz)<Statistic traceback=%r size=%i count=%i>rrrrr�__repr__>s�zStatistic.__repr__cCs|j|j|jfSr)rrrrrrr�	_sort_keyBszStatistic._sort_keyN��__name__�
__module__�__qualname__�__doc__�	__slots__rrr#r(r)r*rrrrrs
rc@sDeZdZdZdZdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dS)�
StatisticDiffzd
    Statistic difference on memory allocations between an old and a new
    Snapshot instance.
    �rr�	size_diffr�
count_diffcCs"||_||_||_||_||_dSrr2)rrrr3rr4rrrrMs
zStatisticDiff.__init__cCst|j|j|j|j|jf�Sr)rrrr3rr4rrrrrTs�zStatisticDiff.__hash__cCsJt|t�stS|j|jkoH|j|jkoH|j|jkoH|j|jkoH|j|jkSr)rr1r rrr3rr4r!rrrr#Xs

�
�
�
�zStatisticDiff.__eq__cCsPd|jt|jd�t|jd�|j|jf}|jrL|j|j}|dt|d�7}|S)Nz %s: size=%s (%s), count=%i (%+i)FTr$)rrrr3rr4r%rrrr(as

��zStatisticDiff.__str__cCsd|j|j|j|j|jfS)Nz9<StatisticDiff traceback=%r size=%i (%+i) count=%i (%+i)>r2rrrrr)ms
��zStatisticDiff.__repr__cCs t|j�|jt|j�|j|jfSr)rr3rr4rrrrrrr*rs�zStatisticDiff._sort_keyNr+rrrrr1Fs	r1cCs�g}|��D]d\}}|�|d�}|durNt||j|j|j|j|j|j�}nt||j|j|j|j�}|�|�q|��D]*\}}t|d|jd|j�}|�|�qz|S�Nr)�items�popr1rr�append)�	old_group�	new_group�
statisticsr�stat�previousrrr�_compare_grouped_statsxs"��r>c@s\eZdZdZdZdd�Zedd��Zedd��Zd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
dS)�Framez
    Frame of a traceback.
    ��_framecCs
||_dSrr@�r�framerrrr�szFrame.__init__cCs
|jdSr5r@rrrr�filename�szFrame.filenamecCs
|jdS�N�r@rrrr�lineno�szFrame.linenocCst|t�stS|j|jkSr�rr?r rAr!rrrr#�s
zFrame.__eq__cCst|t�stS|j|jkSrrHr!rrr�__lt__�s
zFrame.__lt__cCs
t|j�Sr)rrArrrrr�szFrame.__hash__cCsd|j|jfS)Nz%s:%s�rDrGrrrrr(�sz
Frame.__str__cCsd|j|jfS)Nz<Frame filename=%r lineno=%r>rJrrrrr)�szFrame.__repr__N)r,r-r.r/r0r�propertyrDrGr#rIrr(r)rrrrr?�s

r?c@steZdZdZdZddd�Zedd��Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zddd�ZdS)�	Tracebackz`
    Sequence of Frame instances sorted from the oldest frame
    to the most recent frame.
    )�_frames�
_total_nframeNcCs"t�|�tt|��|_||_dSr)rr�tuple�reversedrMrN)r�frames�total_nframerrrr�s
zTraceback.__init__cCs|jSr)rNrrrrrR�szTraceback.total_nframecCs
t|j�Sr)�lenrMrrrr�__len__�szTraceback.__len__cCs4t|t�r"tdd�|j|D��St|j|�SdS)Ncss|]}t|�VqdSr)r?��.0�tracerrr�	<genexpr>��z(Traceback.__getitem__.<locals>.<genexpr>)r�slicerOrMr?�r�indexrrr�__getitem__�s
zTraceback.__getitem__cCs|j|jvSr)rArMrBrrr�__contains__�szTraceback.__contains__cCs
t|j�Sr)rrMrrrrr�szTraceback.__hash__cCst|t�stS|j|jkSr�rrLr rMr!rrrr#�s
zTraceback.__eq__cCst|t�stS|j|jkSrr_r!rrrrI�s
zTraceback.__lt__cCst|d�Sr5)�strrrrrr(�szTraceback.__str__cCs8dt|���}|jdur"|d7}n|d|j�d�7}|S)Nz<Traceback �>z total_nframe=)rOrNrR)r�srrrr)�s


zTraceback.__repr__FcCs�g}|dur2|dkr$||d�}q6|d|�}n|}|rBt|�}|D]@}|�d|j|jf�t�|j|j���}|rF|�d|�qF|S)Nrz  File "%s", line %sz    %s)rPr8rDrG�	linecache�getline�strip)r�limit�most_recent_first�lines�frame_slicerC�linerrr�format�s 
�zTraceback.format)N)NF)r,r-r.r/r0rrKrRrTr]r^rr#rIr(r)rkrrrrrL�s
	
rLcCs t|�}|durt|�SdSdS)z�
    Get the traceback where the Python object *obj* was allocated.
    Return a Traceback instance.

    Return None if the tracemalloc module is not tracing memory allocations or
    did not trace the allocation of the object.
    N)rrL)�objrQrrr�get_object_tracebacksrmc@s`eZdZdZdZdd�Zedd��Zedd��Zed	d
��Z	dd�Z
d
d�Zdd�Zdd�Z
dS)�Tracez"
    Trace of a memory block.
    ��_tracecCs
||_dSrro�rrWrrrrszTrace.__init__cCs
|jdSr5rorrrr�domainszTrace.domaincCs
|jdSrErorrrrrsz
Trace.sizecCst|jdd��S)N�)rLrprrrrr#szTrace.tracebackcCst|t�stS|j|jkSr)rrnr rpr!rrrr#'s
zTrace.__eq__cCs
t|j�Sr)rrprrrrr,szTrace.__hash__cCsd|jt|jd�fS)Nz%s: %sF)rrrrrrrr(/sz
Trace.__str__cCsd|jt|jd�|jfS)Nz'<Trace domain=%s size=%s, traceback=%r>F)rrrrrrrrrr)2s�zTrace.__repr__N)r,r-r.r/r0rrKrrrrr#rr(r)rrrrrns


rnc@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�_TracescCst�|�||_dSr)rr�_traces)r�tracesrrrr8s
z_Traces.__init__cCs
t|j�Sr)rSrurrrrrT=sz_Traces.__len__cCs4t|t�r"tdd�|j|D��St|j|�SdS)Ncss|]}t|�VqdSr)rnrUrrrrXBrYz&_Traces.__getitem__.<locals>.<genexpr>)rrZrOrurnr[rrrr]@s
z_Traces.__getitem__cCs|j|jvSr)rprurqrrrr^Fsz_Traces.__contains__cCst|t�stS|j|jkSr)rrtr rur!rrrr#Is
z_Traces.__eq__cCsdt|�S)Nz<Traces len=%s>)rSrrrrr)Nsz_Traces.__repr__N)	r,r-r.rrTr]r^r#r)rrrrrt7srtcCs&tj�|�}|�d�r"|dd�}|S)Nz.pyc���)�os�path�normcase�endswith)rDrrr�_normalize_filenameRs
r|c@seZdZdd�Zdd�ZdS)�
BaseFiltercCs
||_dSr)�	inclusive)rr~rrrrZszBaseFilter.__init__cCst�dSr)�NotImplementedErrorrqrrr�_match]szBaseFilter._matchN)r,r-r.rr�rrrrr}Ysr}csJeZdZd�fdd�	Zedd��Zdd�Zd	d
�Zdd�Zd
d�Z	�Z
S)�FilterNFcs2t��|�||_t|�|_||_||_||_dSr)�superrr~r|�_filename_patternrG�
all_framesrr)rr~�filename_patternrGr�rr��	__class__rrrbs
zFilter.__init__cCs|jSr)r�rrrrr�kszFilter.filename_patterncCs6t|�}t�||j�sdS|jdur(dS||jkSdS)NFT)r|�fnmatchr�rG�rrDrGrrr�_match_frame_implos
zFilter._match_frame_implcCs|�||�|jASr)r�r~r�rrr�_match_framexszFilter._match_framecsH�jr,t�fdd�|D��r"�jS�jSn|d\}}��||�SdS)Nc3s|]\}}��||�VqdSr)r�)rVrDrGrrrrX}s�z*Filter._match_traceback.<locals>.<genexpr>r)r��anyr~r�)rrrDrGrrr�_match_traceback{s�
zFilter._match_tracebackcCsF|\}}}}|�|�}|jdurB|jr4|o2||jkS|p@||jkS|Sr)r�rrr~)rrWrrrrrR�resrrrr��s

z
Filter._match)NFN)r,r-r.rrKr�r�r�r�r��
__classcell__rrr�rr�as�	
	r�cs0eZdZ�fdd�Zedd��Zdd�Z�ZS)�DomainFiltercst��|�||_dSr)r�r�_domain)rr~rrr�rrr�szDomainFilter.__init__cCs|jSr)r�rrrrrr�szDomainFilter.domaincCs|\}}}}||jk|jASr)rrr~)rrWrrrrrRrrrr��szDomainFilter._match)r,r-r.rrKrrr�r�rrr�rr��s
r�c@sXeZdZdZdd�Zdd�Zedd��Zdd	�Zd
d�Z	dd
�Z
ddd�Zddd�ZdS)�SnapshotzB
    Snapshot of traces of memory blocks allocated by Python.
    cCst|�|_||_dSr)rtrv�traceback_limit)rrvr�rrrr�s
zSnapshot.__init__cCs>t|d�� }t�||tj�Wd�n1s00YdS)z1
        Write the snapshot into a file.
        �wbN)�open�pickle�dump�HIGHEST_PROTOCOL)rrD�fprrrr��sz
Snapshot.dumpcCs8t|d��}t�|�Wd�S1s*0YdS)z.
        Load a snapshot from a file.
        �rbN)r�r��load)rDr�rrrr��sz
Snapshot.loadcs@|rt�fdd�|D��sdS|r<t�fdd�|D��r<dSdS)Nc3s|]}|���VqdSr�r��rV�trace_filter�rWrrrX�s�z)Snapshot._filter_trace.<locals>.<genexpr>Fc3s|]}|���VqdSrr�r�r�rrrX�s�T)r�)r�include_filters�exclude_filtersrWrr�r�
_filter_trace�s��zSnapshot._filter_tracecs�t|t�stdt|�j��|rjg�g�|D] }|jrB��|�q,��|�q,���fdd��jjD�}n�jj�	�}t
|�j�S)z�
        Create a new Snapshot instance with a filtered traces sequence, filters
        is a list of Filter or DomainFilter instances.  If filters is an empty
        list, return a new Snapshot instance with a copy of the traces.
        z)filters must be a list of filters, not %scsg|]}����|�r|�qSr)r�rU�r�r�rrr�
<listcomp>�s
��z*Snapshot.filter_traces.<locals>.<listcomp>)rr�	TypeError�typer,r~r8rvru�copyr�r�)r�filtersr��
new_tracesrr�r�
filter_traces�s
�zSnapshot.filter_tracesc
Cs�|dvrtd|f��|r.|dvr.td|��i}i}|�s|jjD]�}|\}}}}	z||}
WnXty�|dkr||}n(|dkr�|dd�}n|dddff}t|�}
|
||<Yn0z(||
}|j|7_|jd7_WqDt�yt|
|d�||
<YqD0qDn�|jjD]�}|\}}}}	|D]�}
z||
}
WnDt�y||dk�rZ|
f}n|
ddff}t|�}
|
||
<Yn0z(||
}|j|7_|jd7_Wn$t�y�t|
|d�||
<Yn0�q(�q|S)	N)rrDrGzunknown key_type: %r)rGrDz/cumulative mode cannot by used with key type %rrrGrFr)�
ValueErrorrvru�KeyErrorrLrrr)r�key_type�
cumulative�stats�
tracebacksrWrrr�trace_tracebackrRrrQr<rCrrr�	_group_by�sZ�
zSnapshot._group_byFcCs,|�||�}t|���}|jdtjd�|S)zd
        Group statistics by key_type. Return a sorted list of Statistic
        instances.
        T��reverse�key)r��list�values�sortrr*)rr�r��groupedr;rrrr;szSnapshot.statisticscCs6|�||�}|�||�}t||�}|jdtjd�|S)z�
        Compute the differences with an old snapshot old_snapshot. Get
        statistics as a sorted list of StatisticDiff instances, grouped by
        group_by.
        Tr�)r�r>r�r1r*)r�old_snapshotr�r�r:r9r;rrr�
compare_tos

zSnapshot.compare_toN)F)F)
r,r-r.r/rr��staticmethodr�r�r�r�r;r�rrrrr��s
3

r�cCs$t�std��t�}t�}t||�S)zI
    Take a snapshot of traces of memory blocks allocated by Python.
    zLthe tracemalloc module must be tracing memory allocations to take a snapshot)�
is_tracing�RuntimeErrorr�get_traceback_limitr�)rvr�rrr�
take_snapshot's
r�)�collections.abcrr�	functoolsrr�rc�os.pathrxr��_tracemallocrrrrr1r>r?rLrmrnrtr|r}r�r�r�r�rrrr�<module>s2(2&M'0