grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026î ¤ f#=ã@s`ddlmZmZddlmZddlZddlZddlZddl Z ddl Tddl m Z m Z dd„Z Gdd „d ƒZGd d „d ƒZd d „ZeGdd„dƒƒZeGdd„deƒƒZdd„ZGdd„dƒZGdd„deƒZdd„ZGdd„dƒZGdd„dƒZdd„ZdS) é)ÚSequenceÚIterable)Útotal_orderingN)Ú*)Ú_get_object_tracebackÚ _get_tracescCs¥xžd D]–}t|ƒdkrP|dkrP|r?d||fSd||fSnt|ƒdksn|dkr“|r‚d ||fSd ||fSn|d }qWdS)NÚBÚKiBÚMiBÚGiBÚTiBédz%+.1f %sz%.1f %sé iz%+.0f %sz%.0f %s)rr r r r i()Úabs)ÚsizeZsignZunit©rú0/opt/alt/python34/lib64/python3.4/tracemalloc.pyÚ _format_size s rc@sdeZdZdZdZdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dS)Ú StatisticzS Statistic difference on memory allocations between two Snapshot instance. Ú tracebackrÚcountcCs||_||_||_dS)N)rrr)ÚselfrrrrrrÚ__init__%s  zStatistic.__init__cCst|j|j|jfƒS)N)Úhashrrr)rrrrÚ__hash__*szStatistic.__hash__cCs4|j|jko3|j|jko3|j|jkS)N)rrr)rÚotherrrrÚ__eq__-szStatistic.__eq__cCs\d|jt|jdƒ|jf}|jrX|j|j}|dt|dƒ7}n|S)Nz%s: size=%s, count=%iFz , average=%s)rrrr)rÚtextÚaveragerrrÚ__str__2s  zStatistic.__str__cCsd|j|j|jfS)Nz))rrr)rrrrÚ__repr__<szStatistic.__repr__cCs|j|j|jfS)N)rrr)rrrrÚ _sort_key@szStatistic._sort_keyN)z tracebackzsizezcount) Ú__name__Ú __module__Ú __qualname__Ú__doc__Ú __slots__rrrrr r!rrrrrs     rc@sdeZdZdZdZdd„Zd d „Zd d „Zd d„Zdd„Z dd„Z dS)Ú StatisticDiffzd Statistic difference on memory allocations between an old and a new Snapshot instance. rrÚ size_diffrÚ count_diffcCs1||_||_||_||_||_dS)N)rrr(rr))rrrr(rr)rrrrKs     zStatisticDiff.__init__cCs(t|j|j|j|j|jfƒS)N)rrrr(rr))rrrrrRszStatisticDiff.__hash__cCsX|j|jkoW|j|jkoW|j|jkoW|j|jkoW|j|jkS)N)rrr(rr))rrrrrrVs zStatisticDiff.__eq__cCsqd|jt|jdƒt|jdƒ|j|jf}|jrm|j|j}|dt|dƒ7}n|S)Nz %s: size=%s (%s), count=%i (%+i)FTz , average=%s)rrrr(rr))rrrrrrr]s  zStatisticDiff.__str__cCs&d|j|j|j|j|jfS)Nz9)rrr(rr))rrrrr iszStatisticDiff.__repr__cCs.t|jƒ|jt|jƒ|j|jfS)N)rr(rr)rr)rrrrr!nszStatisticDiff._sort_keyN)z tracebackzsizez size_diffzcountz count_diff) r"r#r$r%r&rrrrr r!rrrrr'Ds     r'cCsõg}xž|jƒD]�\}}|j|dƒ}|dk rrt||j|j|j|j|j|jƒ}n$t||j|j|j|jƒ}|j|ƒqWxG|jƒD]9\}}t|d|j d|j ƒ}|j|ƒq´W|S)Nr)ÚitemsÚpopr'rrÚappend)Ú old_groupÚ new_groupÚ statisticsrÚstatZpreviousrrrÚ_compare_grouped_statsts   r1c@sˆeZdZdZdZdd„Zedd„ƒZedd„ƒZd d „Z d d „Z d d„Z dd„Z dd„Z dS)ÚFramez Frame of a traceback. Ú_framecCs ||_dS)N)r3)rÚframerrrr�szFrame.__init__cCs |jdS)Nr)r3)rrrrÚfilename“szFrame.filenamecCs |jdS)Né)r3)rrrrÚlineno—sz Frame.linenocCs|j|jkS)N)r3)rrrrrr›sz Frame.__eq__cCs|j|jkS)N)r3)rrrrrÚ__lt__žsz Frame.__lt__cCs t|jƒS)N)rr3)rrrrr¡szFrame.__hash__cCsd|j|jfS)Nz%s:%s)r5r7)rrrrr¤sz Frame.__str__cCsd|j|jfS)Nz)r5r7)rrrrr §szFrame.__repr__N)z_frame)r"r#r$r%r&rÚpropertyr5r7rr8rrr rrrrr2ˆs      r2c@s—eZdZdZdZdd„Zdd„Zdd„Zd d „Zd d „Z d d„Z dd„Z dd„Z dd„Z ddd„ZdS)Ú Tracebackz` Sequence of Frame instances sorted from the most recent frame to the oldest frame. Ú_framescCstj|ƒ||_dS)N)rrr;)rÚframesrrrr³s zTraceback.__init__cCs t|jƒS)N)Úlenr;)rrrrÚ__len__¹szTraceback.__len__cCsBt|tƒr-tdd„|j|DƒƒSt|j|ƒSdS)Ncss|]}t|ƒVqdS)N)r2)Ú.0Útracerrrú ¾sz(Traceback.__getitem__..)Ú isinstanceÚsliceÚtupler;r2)rÚindexrrrÚ __getitem__¼szTraceback.__getitem__cCs|j|jkS)N)r3r;)rr4rrrÚ __contains__ÂszTraceback.__contains__cCs t|jƒS)N)rr;)rrrrrÅszTraceback.__hash__cCs|j|jkS)N)r;)rrrrrrÈszTraceback.__eq__cCs|j|jkS)N)r;)rrrrrr8ËszTraceback.__lt__cCst|dƒS)Nr)Ústr)rrrrrÎszTraceback.__str__cCsdt|ƒfS)Nz)rD)rrrrr ÑszTraceback.__repr__NcCs–g}|dk r"|dkr"|Sxm|d|…D][}|jd|j|jfƒtj|j|jƒjƒ}|r3|jd|ƒq3q3W|S)Nrz File "%s", line %sz %s)r,r5r7Ú linecacheÚgetlineÚstrip)rÚlimitÚlinesr4ÚlinerrrÚformatÔs zTraceback.format)z_frames)r"r#r$r%r&rr>rFrGrrr8rr rOrrrrr:«s          r:cCs*t|ƒ}|dk r"t|ƒ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)rr:)Úobjr<rrrÚget_object_tracebackás   rQc@s|eZdZdZdZdd„Zedd„ƒZedd„ƒZd d „Z d d „Z d d„Z dd„Z dS)ÚTracez" Trace of a memory block. Ú_tracecCs ||_dS)N)rS)rr@rrrröszTrace.__init__cCs |jdS)Nr)rS)rrrrrûsz Trace.sizecCst|jdƒS)Nr6)r:rS)rrrrrÿszTrace.tracebackcCs|j|jkS)N)rS)rrrrrrsz Trace.__eq__cCs t|jƒS)N)rrS)rrrrrszTrace.__hash__cCsd|jt|jdƒfS)Nz%s: %sF)rrr)rrrrr sz Trace.__str__cCsdt|jdƒ|jfS)NzF)rrr)rrrrr szTrace.__repr__N)z_trace) r"r#r$r%r&rr9rrrrrr rrrrrRðs     rRc@sXeZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd S)Ú_TracescCstj|ƒ||_dS)N)rrÚ_traces)rÚtracesrrrrs z_Traces.__init__cCs t|jƒS)N)r=rU)rrrrr>sz_Traces.__len__cCsBt|tƒr-tdd„|j|DƒƒSt|j|ƒSdS)Ncss|]}t|ƒVqdS)N)rR)r?r@rrrrAsz&_Traces.__getitem__..)rBrCrDrUrR)rrErrrrFsz_Traces.__getitem__cCs|j|jkS)N)rSrU)rr@rrrrG sz_Traces.__contains__cCs|j|jkS)N)rU)rrrrrr#sz_Traces.__eq__cCsdt|ƒS)Nz)r=)rrrrr &sz_Traces.__repr__N) r"r#r$rr>rFrGrr rrrrrTs      rTcCs8tjj|ƒ}|jdƒr4|dd…}n|S)Nú.pycú.pyor6)rWrXéÿÿÿÿ)ÚosÚpathÚnormcaseÚendswith)r5rrrÚ_normalize_filename*sr^c@sXeZdZdddd„Zedd„ƒZdd„Zd d „Zd d „ZdS) ÚFilterNFcCs.||_t|ƒ|_||_||_dS)N)Ú inclusiver^Ú_filename_patternr7Ú all_frames)rr`Úfilename_patternr7rbrrrr2s  zFilter.__init__cCs|jS)N)ra)rrrrrc9szFilter.filename_patterncCsIt|ƒ}tj||jƒs%dS|jdkr8dS||jkSdS)NFT)r^Úfnmatchrar7)rr5r7rrrZ __match_frame=s  zFilter.__match_framecCs|j||ƒ|j AS)N)Ú_Filter__match_framer`)rr5r7rrrÚ _match_frameFszFilter._match_framecs^ˆjr:t‡fdd†|Dƒƒr/ˆjSˆj Sn |d\}}ˆj||ƒSdS)Nc3s'|]\}}ˆj||ƒVqdS)N)re)r?r5r7)rrrrAKsz*Filter._match_traceback..r)rbÚanyr`rf)rrr5r7r)rrÚ_match_tracebackIs   zFilter._match_traceback) r"r#r$rr9rcrerfrhrrrrr_1s  r_c@s‚eZdZdZdd„Zdd„Zedd„ƒZdd „Zd d „Z d d „Z ddd„Z ddd„Z dS)ÚSnapshotzB Snapshot of traces of memory blocks allocated by Python. cCst|ƒ|_||_dS)N)rTrVÚtraceback_limit)rrVrjrrrrZszSnapshot.__init__c Cs2t|dƒ�}tj||tjƒWdQXdS)z1 Write the snapshot into a file. ÚwbN)ÚopenÚpickleÚdumpZHIGHEST_PROTOCOL)rr5Úfprrrrn`sz Snapshot.dumpc Cs)t|dƒ�}tj|ƒSWdQXdS)z. Load a snapshot from a file. ÚrbN)rlrmÚload)r5rorrrrqgsz Snapshot.loadcsf|d‰|r6t‡fdd†|Dƒƒs6dSn|rbt‡fdd†|DƒƒrbdSndS)Nr6c3s|]}|jˆƒVqdS)N)rh)r?Ú trace_filter)rrrrArsz)Snapshot._filter_trace..Fc3s|]}|jˆƒ VqdS)N)rh)r?rr)rrrrAvsT)rg)rÚinclude_filtersÚexclude_filtersr@r)rrÚ _filter_traceos   zSnapshot._filter_tracecs¾t|tƒs+tdt|ƒjƒ‚n|rœg‰g‰x4|D],}|jrcˆj|ƒqDˆj|ƒqDW‡‡‡fdd†ˆjjDƒ}nˆjjj ƒ}t |ˆj ƒS)zà Create a new Snapshot instance with a filtered traces sequence, filters is a list of Filter 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 %scs+g|]!}ˆjˆˆ|ƒr|‘qSr)ru)r?r@)rtrsrrrú Œs  z*Snapshot.filter_traces..) rBrÚ TypeErrorÚtyper"r`r,rVrUÚcopyrirj)rÚfiltersrrZ new_tracesr)rtrsrrÚ filter_traces{s  (zSnapshot.filter_tracesc CsM|dkr"td|fƒ‚n|rG|d krGtd|ƒ‚ni}i}|sZxí|jjD]í}|\}}y||}Wnstk rû|dkr«|} n6|dkrÊ|dd…} n|dddff} t| ƒ}|||s*      &0 # 5 ! $‰