관리-도구
편집 파일: tracemalloc.cpython-39.opt-1.pyc
a �����DOgF����������������������@���s��d�dl�mZmZ�d�dlmZ�d�dlZd�dlZd�dlZd�dl Z d�dl T�d�dl mZmZ�dd��Z G�dd ��d �ZG�d d��d�Zdd ��ZeG�dd��d��ZeG�dd��de��Zdd��ZG�dd��d�ZG�dd��de�Zdd��ZG�dd��d�ZG�dd��de�ZG�dd��de�ZG�d d!��d!�Zd"d#��ZdS�)$�����)�Sequence�Iterable)�total_orderingN)�*)�_get_object_traceback�_get_tracesc�����������������C���s����dD�]|}t�|��dk�r@|dkr@|r0d|�|f���S�d|�|f���S�t�|��dk�sT|dkrx|rhd|�|f���S�d |�|f���S�|�d �}�qd�S�)N)�BZKiBZMiBZGiB�TiB�d���r���z%+.1f %sz%.1f %si�(��r ���z%+.0f %sz%.0f %si���)�abs)�size�signZunit��r����#/usr/lib64/python3.9/tracemalloc.py�_format_size ���s����r���c�������������������@���sD���e�Zd�ZdZdZdd��Zdd��Zdd��Zd d ��Zdd��Z d d��Z dS�)� StatisticzS Statistic difference on memory allocations between two Snapshot instance. �� tracebackr����countc�����������������C���s���||�_�||�_||�_d�S��Nr���)�selfr���r���r���r���r���r����__init__%���s����zStatistic.__init__c�����������������C���s���t�|�j|�j|�jf�S�r���)�hashr���r���r����r���r���r���r����__hash__*���s����zStatistic.__hash__c�����������������C���s2���t�|t�stS�|�j|jko0|�j|jko0|�j|jkS�r���)� isinstancer����NotImplementedr���r���r����r����otherr���r���r����__eq__-���s���� � �zStatistic.__eq__c�����������������C���sB���d|�j�t|�jd�|�jf�}|�jr>|�j|�j�}|dt|d��7�}|S�)Nz%s: size=%s, count=%iF�, average=%s)r���r���r���r����r����textZaverager���r���r����__str__4���s���� ��zStatistic.__str__c�����������������C���s���d|�j�|�j|�jf�S�)Nz)<Statistic traceback=%r size=%i count=%i>r���r���r���r���r����__repr__>���s�����zStatistic.__repr__c�����������������C���s���|�j�|�j|�jfS�r���)r���r���r���r���r���r���r���� _sort_keyB���s����zStatistic._sort_keyN��__name__� __module__�__qualname__�__doc__� __slots__r���r���r���r#���r$���r%���r���r���r���r���r������s��� r���c�������������������@���sD���e�Zd�ZdZdZdd��Zdd��Zdd��Zd d ��Zdd��Z d d��Z dS�)� StatisticDiffzd Statistic difference on memory allocations between an old and a new Snapshot instance. �r���r���� size_diffr���� count_diffc�����������������C���s"���||�_�||�_||�_||�_||�_d�S�r���r-���)r���r���r���r.���r���r/���r���r���r���r���M���s ����zStatisticDiff.__init__c�����������������C���s���t�|�j|�j|�j|�j|�jf�S�r���)r���r���r���r.���r���r/���r���r���r���r���r���T���s�����zStatisticDiff.__hash__c�����������������C���sJ���t�|t�stS�|�j|jkoH|�j|jkoH|�j|jkoH|�j|jkoH|�j|jkS�r���)r���r,���r���r���r���r.���r���r/���r���r���r���r���r���X���s���� � � � �zStatisticDiff.__eq__c�����������������C���sP���d|�j�t|�jd�t|�jd�|�j|�jf�}|�jrL|�j|�j�}|dt|d��7�}|S�)Nz %s: size=%s (%s), count=%i (%+i)FTr ���)r���r���r���r.���r���r/���r!���r���r���r���r#���a���s���� ��zStatisticDiff.__str__c�����������������C���s���d|�j�|�j|�j|�j|�jf�S�)Nz9<StatisticDiff traceback=%r size=%i (%+i) count=%i (%+i)>r-���r���r���r���r���r$���m���s ������zStatisticDiff.__repr__c�����������������C���s ���t�|�j�|�jt�|�j�|�j|�jfS�r���)r���r.���r���r/���r���r���r���r���r���r���r%���r���s�����zStatisticDiff._sort_keyNr&���r���r���r���r���r,���F���s��� r,���c�����������������C���s����g�}|����D�]d\}}|��|d��}|d�urNt||j|j|j�|j|j|j��}nt||j|j|j|j�}|�|��q|�����D�]*\}}t|d|j�d|j��}|�|��qz|S��Nr���)�items�popr,���r���r����append)� old_group� new_group� statisticsr����statZpreviousr���r���r����_compare_grouped_statsx���s"������r8���c�������������������@���s\���e�Zd�ZdZdZdd��Zedd���Zedd���Zd d ��Z dd��Z d d��Zdd��Zdd��Z dS�)�Framez Frame of a traceback. ��_framec�����������������C���s ���||�_�d�S�r���r:����r����framer���r���r���r�������s����zFrame.__init__c�����������������C���s ���|�j�d�S�r0���r:���r���r���r���r����filename����s����zFrame.filenamec�����������������C���s ���|�j�d�S��N����r:���r���r���r���r����lineno����s����zFrame.linenoc�����������������C���s���t�|t�stS�|�j|jkS�r����r���r9���r���r;���r���r���r���r���r�������s���� zFrame.__eq__c�����������������C���s���t�|t�stS�|�j|jk�S�r���rB���r���r���r���r����__lt__����s���� zFrame.__lt__c�����������������C���s ���t�|�j�S�r���)r���r;���r���r���r���r���r�������s����zFrame.__hash__c�����������������C���s���d|�j�|�jf�S�)Nz%s:%s�r>���rA���r���r���r���r���r#�������s����z Frame.__str__c�����������������C���s���d|�j�|�jf�S�)Nz<Frame filename=%r lineno=%r>rD���r���r���r���r���r$�������s����zFrame.__repr__N)r'���r(���r)���r*���r+���r����propertyr>���rA���r���rC���r���r#���r$���r���r���r���r���r9�������s��� r9���c�������������������@���st���e�Zd�ZdZdZddd�Zedd���Zdd ��Zd d��Z dd ��Z dd��Zdd��Zdd��Z dd��Zdd��Zddd�ZdS�)� Tracebackz` Sequence of Frame instances sorted from the oldest frame to the most recent frame. )�_frames� _total_nframeNc�����������������C���s"���t��|���tt|��|�_||�_d�S�r���)r���r����tuple�reversedrG���rH���)r����frames�total_nframer���r���r���r�������s���� zTraceback.__init__c�����������������C���s���|�j�S�r���)rH���r���r���r���r���rL�������s����zTraceback.total_nframec�����������������C���s ���t�|�j�S�r���)�lenrG���r���r���r���r����__len__����s����zTraceback.__len__c�����������������C���s4���t�|t�r"tdd��|�j|�D���S�t|�j|��S�d�S�)Nc�����������������s���s���|�]}t�|�V��qd�S�r���)r9�����.0�tracer���r���r���� <genexpr>���������z(Traceback.__getitem__.<locals>.<genexpr>)r����slicerI���rG���r9����r����indexr���r���r����__getitem__����s���� zTraceback.__getitem__c�����������������C���s���|j�|�jv�S�r���)r;���rG���r<���r���r���r����__contains__����s����zTraceback.__contains__c�����������������C���s ���t�|�j�S�r���)r���rG���r���r���r���r���r�������s����zTraceback.__hash__c�����������������C���s���t�|t�stS�|�j|jkS�r����r���rF���r���rG���r���r���r���r���r�������s���� zTraceback.__eq__c�����������������C���s���t�|t�stS�|�j|jk�S�r���rY���r���r���r���r���rC�������s���� zTraceback.__lt__c�����������������C���s���t�|�d��S�r0���)�strr���r���r���r���r#�������s����zTraceback.__str__c�����������������C���s8���dt�|�����}|�jd�u�r"|d7�}n|d|�j��d�7�}|S�)Nz<Traceback �>z total_nframe=)rI���rH���rL���)r����sr���r���r���r$�������s ���� zTraceback.__repr__Fc�����������������C���s����g�}|d�ur2|dkr$|�|�d���}q6|�d�|��}n|�}|rBt�|�}|D�]@}|�d|j|jf���t�|j|j����}|rF|�d|���qF|S�)Nr���z File "%s", line %sz %s)rJ���r3���r>���rA���� linecache�getline�strip)r����limitZmost_recent_first�linesZframe_slicer=����liner���r���r����format����s ���� �zTraceback.format)N)NF)r'���r(���r)���r*���r+���r���rE���rL���rN���rW���rX���r���r���rC���r#���r$���rc���r���r���r���r���rF�������s��� rF���c�����������������C���s ���t�|��}|durt|�S�dS�dS�)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)r���rF���)�objrK���r���r���r����get_object_traceback��s����re���c�������������������@���s`���e�Zd�ZdZdZdd��Zedd���Zedd���Zed d ���Z dd��Z d d��Zdd��Zdd��Z dS�)�Tracez" Trace of a memory block. ��_tracec�����������������C���s ���||�_�d�S�r���rg����r���rQ���r���r���r���r�����s����zTrace.__init__c�����������������C���s ���|�j�d�S�r0���rg���r���r���r���r����domain��s����zTrace.domainc�����������������C���s ���|�j�d�S�r?���rg���r���r���r���r���r�����s����z Trace.sizec�����������������C���s���t�|�jdd�����S�)N����)rF���rh���r���r���r���r���r���#��s����zTrace.tracebackc�����������������C���s���t�|t�stS�|�j|jkS�r���)r���rf���r���rh���r���r���r���r���r���'��s���� zTrace.__eq__c�����������������C���s ���t�|�j�S�r���)r���rh���r���r���r���r���r���,��s����zTrace.__hash__c�����������������C���s���d|�j�t|�jd�f�S�)Nz%s: %sF)r���r���r���r���r���r���r���r#���/��s����z Trace.__str__c�����������������C���s���d|�j�t|�jd�|�jf�S�)Nz'<Trace domain=%s size=%s, traceback=%r>F)rj���r���r���r���r���r���r���r���r$���2��s�����zTrace.__repr__N)r'���r(���r)���r*���r+���r���rE���rj���r���r���r���r���r#���r$���r���r���r���r���rf�����s��� rf���c�������������������@���s<���e�Zd�Zdd��Zdd��Zdd��Zdd��Zd d ��Zdd��Zd S�)�_Tracesc�����������������C���s���t��|���||�_d�S�r���)r���r����_traces)r����tracesr���r���r���r���8��s���� z_Traces.__init__c�����������������C���s ���t�|�j�S�r���)rM���rm���r���r���r���r���rN���=��s����z_Traces.__len__c�����������������C���s4���t�|t�r"tdd��|�j|�D���S�t|�j|��S�d�S�)Nc�����������������s���s���|�]}t�|�V��qd�S�r���)rf���rO���r���r���r���rR���B��rS���z&_Traces.__getitem__.<locals>.<genexpr>)r���rT���rI���rm���rf���rU���r���r���r���rW���@��s���� z_Traces.__getitem__c�����������������C���s���|j�|�jv�S�r���)rh���rm���ri���r���r���r���rX���F��s����z_Traces.__contains__c�����������������C���s���t�|t�stS�|�j|jkS�r���)r���rl���r���rm���r���r���r���r���r���I��s���� z_Traces.__eq__c�����������������C���s���dt�|���S�)Nz<Traces len=%s>)rM���r���r���r���r���r$���N��s����z_Traces.__repr__N) r'���r(���r)���r���rN���rW���rX���r���r$���r���r���r���r���rl���7��s���rl���c�����������������C���s&���t�j�|��}�|��d�r"|�d�d��}�|�S�)Nz.pyc���)�os�path�normcase�endswith)r>���r���r���r����_normalize_filenameR��s���� rt���c�������������������@���s���e�Zd�Zdd��Zdd��ZdS�)� BaseFilterc�����������������C���s ���||�_�d�S�r���)� inclusive)r���rv���r���r���r���r���Z��s����zBaseFilter.__init__c�����������������C���s���t��d�S�r���)�NotImplementedErrorri���r���r���r����_match]��s����zBaseFilter._matchN)r'���r(���r)���r���rx���r���r���r���r���ru���Y��s���ru���c�����������������������sJ���e�Zd�Zd��fdd� Zedd���Zdd��Zd d ��Zdd��Zd d��Z ���Z S�)�FilterNFc��������������������s2���t����|��||�_t|�|�_||�_||�_||�_d�S�r���)�superr���rv���rt����_filename_patternrA���� all_framesrj���)r���rv����filename_patternrA���r|���rj����� __class__r���r���r���b��s���� zFilter.__init__c�����������������C���s���|�j�S�r���)r{���r���r���r���r���r}���k��s����zFilter.filename_patternc�����������������C���s6���t�|�}t�||�j�sdS�|�jd�u�r(dS�||�jkS�d�S�)NFT)rt����fnmatchr{���rA����r���r>���rA���r���r���r����_match_frame_implo��s���� zFilter._match_frame_implc�����������������C���s���|���||�|�j�A�S�r���)r����rv���r����r���r���r����_match_framex��s����zFilter._match_framec��������������������sH�����j�r,t��fdd�|D���r"��jS���j�S�n|d�\}}���||�S�d�S�)Nc�����������������3���s���|�]\}}����||�V��qd�S�r���)r����)rP���r>���rA���r���r���r���rR���}��s����z*Filter._match_traceback.<locals>.<genexpr>r���)r|����anyrv���r����)r���r���r>���rA���r���r���r����_match_traceback{��s����� zFilter._match_tracebackc�����������������C���sF���|\}}}}|���|�}|�jd�urB|�jr4|o2||�jkS�|p@||�jkS�|S�r���)r����rj���rv���)r���rQ���rj���r���r���rL����resr���r���r���rx������s���� z Filter._match)NFN)r'���r(���r)���r���rE���r}���r����r����r����rx���� __classcell__r���r���r~���r���ry���a��s����� ry���c�����������������������s0���e�Zd�Z��fdd�Zedd���Zdd��Z���ZS�)�DomainFilterc��������������������s���t����|��||�_d�S�r���)rz���r����_domain)r���rv���rj���r~���r���r���r������s����zDomainFilter.__init__c�����������������C���s���|�j�S�r���)r����r���r���r���r���rj������s����zDomainFilter.domainc�����������������C���s���|\}}}}||�j�k|�j�A�S�r���)rj���rv���)r���rQ���rj���r���r���rL���r���r���r���rx������s����zDomainFilter._match)r'���r(���r)���r���rE���rj���rx���r����r���r���r~���r���r�������s��� r����c�������������������@���sX���e�Zd�ZdZdd��Zdd��Zedd���Zdd ��Zd d��Z dd ��Z ddd�Zddd�ZdS�)�SnapshotzB Snapshot of traces of memory blocks allocated by Python. c�����������������C���s���t�|�|�_||�_d�S�r���)rl���rn����traceback_limit)r���rn���r����r���r���r���r������s���� zSnapshot.__init__c�����������������C���s>���t�|d�� }t�|�|tj��W�d����n1�s00����Y��dS�)z1 Write the snapshot into a file. �wbN)�open�pickle�dump�HIGHEST_PROTOCOL)r���r>����fpr���r���r���r�������s����z Snapshot.dumpc�����������������C���s8���t�|�d��}t�|�W��d����S�1�s*0����Y��dS�)z. Load a snapshot from a file. �rbN)r����r�����load)r>���r����r���r���r���r�������s����z Snapshot.loadc��������������������s@���|rt���fdd�|D���sdS�|r<t���fdd�|D���r<dS�dS�)Nc�����������������3���s���|�]}|�����V��qd�S�r����rx����rP����trace_filter�rQ���r���r���rR������s����z)Snapshot._filter_trace.<locals>.<genexpr>Fc�����������������3���s���|�]}|������V��qd�S�r���r����r����r����r���r���rR������s����T)r����)r����include_filters�exclude_filtersrQ���r���r����r���� _filter_trace���s������zSnapshot._filter_tracec��������������������s����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 %sc��������������������s���g�|�]}������|�r|�qS�r���)r����rO����r����r����r���r���r���� <listcomp>���s �����z*Snapshot.filter_traces.<locals>.<listcomp>)r���r���� TypeError�typer'���rv���r3���rn���rm����copyr����r����)r����filtersr����Z new_tracesr���r����r���� filter_traces���s���� �zSnapshot.filter_tracesc�������������� ���C���s���|dvrt�d|f���|r.|dvr.t�d|���i�}i�}|�s|�jjD�]�}|\}}}} z||�} W�nX�ty����|dkr||}n(|dkr�|d�d��}n|d�d�dff}t|�} | ||<�Y�n0�z(|| �}|�j|7��_|�jd7��_W�qD�t�y���t| |d�|| <�Y�qD0�qDn�|�jjD�]�}|\}}}} |D�]�} z|| �} W�nD�t�y|���|dk�rZ| f}n| d�dff}t|�} | || <�Y�n0�z(|| �}|�j|7��_|�jd7��_W�n$�t�y����t| |d�|| <�Y�n0��q(�q|S�) N)r���r>���rA���zunknown key_type: %r)rA���r>���z/cumulative mode cannot by used with key type %rr���rA���r@���r���)� ValueErrorrn���rm����KeyErrorrF���r���r���r���)r����key_type� cumulativeZstatsZ tracebacksrQ���rj���r���Ztrace_tracebackrL���r���rK���r7���r=���r���r���r���� _group_by���sZ����� zSnapshot._group_byFc�����������������C���s,���|���||�}t|����}|jdtjd��|S�)zd Group statistics by key_type. Return a sorted list of Statistic instances. T��reverse�key)r�����list�values�sortr���r%���)r���r����r����Zgroupedr6���r���r���r���r6�����s����zSnapshot.statisticsc�����������������C���s6���|���||�}|��||�}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����r8���r����r,���r%���)r���Zold_snapshotr����r����r5���r4���r6���r���r���r���� compare_to��s ���� zSnapshot.compare_toN)F)F) r'���r(���r)���r*���r���r�����staticmethodr����r����r����r����r6���r����r���r���r���r���r�������s��� 3 r����c������������������C���s$���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���Zget_traceback_limitr����)rn���r����r���r���r���� take_snapshot'��s ����r����)�collections.abcr���r���� functoolsr���r����r]���Zos.pathrp���r����Z_tracemallocr���r���r���r���r,���r8���r9���rF���re���rf���rl���rt���ru���ry���r����r����r����r���r���r���r����<module>���s2���(2&M'0�