grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026B ¨§ßù&}½|ã@sˆdZddlZddlZddlZddlZddlZddlmZddlm Z ddgZ Gdd„de eƒZ Gdd„dƒZ Gd d „d ƒZd d „Zd d„Zdd„Zdd„Zdd„Zdd„Zdd„Zedk�r„ddlZy ddlZWnek räYnXGdd„dejƒZeejƒdk�rejdZndZyTeeƒZx"ejdd…D]Z e !e ¡�q2We"dej#d�e $¡e"d ej#d�Wne%k �r‚YnXdS)!z3Class for printing reports on profiled python code.éN)ÚEnum)Ú cmp_to_keyÚStatsÚSortKeyc@s8eZdZdZdZdZdZdZdZdZ dZ d Z d d „Z d S) r)ÚcallsÚncalls)Ú cumulativeÚcumtime)ÚfilenameÚmoduleÚlineÚnameÚnflÚpcallsÚstdname)ÚtimeÚtottimecGs>t |¡}|d|_x|dd…D]}||j|<q"W||_|S)Nré)ÚstrÚ__new__Ú_value_Ú_value2member_map_Z _all_values)ÚclsÚvaluesÚobjZ other_value©rú+/opt/alt/python37/lib64/python3.7/pstats.pyr-s   zSortKey.__new__N) Ú__name__Ú __module__Ú __qualname__ZCALLSZ CUMULATIVEZFILENAMEZLINEÚNAMEZNFLZPCALLSZSTDNAMEZTIMErrrrrr"sc@sØeZdZdZddœdd„Zdd„Zdd „Zd d „Zd d „Zdd„Z ddddddddddddddœ Z dd„Z dd„Z dd„Z d d!„Zd"d#„Zd$d%„Zd&d'„Zd(d)„Zd*d+„Zd,d-„Zd.d/„Zd7d1d2„Zd3d4„Zd5d6„ZdS)8raÛThis class is used for creating reports from data generated by the Profile class. It is a "friend" of that class, and imports data either by direct access to members of Profile class, or by reading in a dictionary that was emitted (via marshal) from the Profile class. The big change from the previous Profiler (in terms of raw functionality) is that an "add()" method has been provided to combine Stats from several distinct profile runs. Both the constructor and the add() method now take arbitrarily many file names as arguments. All the print methods now take an argument that indicates how many lines to print. If the arg is a floating point number between 0 and 1.0, then it is taken as a decimal percentage of the available lines to be printed (e.g., .1 means print 10% of all available lines). If it is an integer, it is taken to mean the number of lines of data that you wish to have printed. The sort_stats() method now processes some additional options (i.e., in addition to the old -1, 0, 1, or 2 that are respectively interpreted as 'stdname', 'calls', 'time', and 'cumulative'). It takes either an arbitrary number of quoted strings or SortKey enum to select the sort order. For example sort_stats('time', 'name') or sort_stats(SortKey.TIME, SortKey.NAME) sorts on the major key of 'internal function time', and on the minor key of 'the name of the function'. Look at the two tables in sort_stats() and get_sort_arg_defs(self) for more examples. All methods return self, so you can string together commands like: Stats('foo', 'goo').strip_dirs().sort_stats('calls'). print_stats(5).print_callers(5) N)ÚstreamcGsF|ptj|_t|ƒsd}n|d}|dd…}| |¡|j|ŽdS)Nrr)ÚsysÚstdoutr!ÚlenÚinitÚadd)Úselfr!ÚargsÚargrrrÚ__init__Ys   zStats.__init__cCs’d|_g|_d|_d|_d|_d|_d|_tƒ|_i|_ i|_ |  |¡y |  ¡Wn8t k rŒtd|jrx|jdnd|jd�‚YnXdS)NrzInvalid timing data %séÿÿÿÿÚ)Úfile)Ú all_calleesÚfilesÚfcn_listÚtotal_ttÚ total_callsÚ prim_callsÚ max_name_lenÚsetÚ top_levelÚstatsÚ sort_arg_dictÚ load_statsÚget_top_level_statsÚ ExceptionÚprintr!)r'r)rrrr%cs"  z Stats.initc Cs´|dkri|_dSt|tƒrxt|dƒ�}t |¡|_WdQRXy"t |¡}t  |j ¡d|}Wn YnX|g|_ n t |dƒr˜|  ¡|j|_i|_|js°td|j|fƒ‚dS)NÚrbz Ú create_statsz.Cannot create or construct a %r object from %r)r7Ú isinstancerÚopenÚmarshalÚloadÚosÚstatrZctimeÚst_mtimer/Úhasattrr>Ú TypeErrorÚ __class__)r'r)ÚfZ file_statsrrrr9vs(     zStats.load_statscCs„x~|j ¡D]p\}\}}}}}|j|7_|j|7_|j|7_d|kr\|j |¡tt|ƒƒ|j kr tt|ƒƒ|_ q WdS)N)ZjprofilerZprofiler) r7Úitemsr2r3r1r6r&r$Úfunc_std_stringr4)r'ÚfuncÚccÚncÚttÚctÚcallersrrrr:Œs zStats.get_top_level_statscGsø|s|Sxêt|ƒD]Þ}t|ƒt|ƒkr.t|ƒ}|j|j7_|j|j7_|j|j7_|j|j7_x|jD]}|j |¡qvW|j |j krž|j |_ d|_ xJ|j   ¡D]<\}}||j krÎ|j |}nddddif}t ||ƒ|j |<q°WqW|S)Nr)ÚreversedÚtyperr/r2r3r1r6r&r4r0r7rJÚadd_func_stats)r'Úarg_listÚitemrLrDZ old_func_statrrrr&–s(    z Stats.addc Cs(t|dƒ�}t |j|¡WdQRXdS)z:Write the profile data to a file we know how to load back.ÚwbN)r@rAÚdumpr7)r'r rIrrrÚ dump_stats°s zStats.dump_stats)))rr+z call count)))ér+zcumulative time)))érz file name)))érz line number)))érz function name)))r]r)r[r)r\rzname/file/line)))rr+zprimitive call count)))érz standard name)))ér+z internal time) rrr rr r r r rrrrrcCs€|jszi|_}i}xP|j ¡D]B\}}|}x4|r`|s8P||krJd||<P|||<|dd…}q.Wq Wx|D] }||=qlW|jS)z)Expand all abbreviations that are unique.rNr+)r8Úsort_arg_dict_defaultrJ)r'ÚdictZbad_listÚwordÚtupZfragmentrrrÚget_sort_arg_defsÇs    zStats.get_sort_arg_defscGsl|sd|_|St|ƒdkrBt|dtƒrBdddddœ|dg}n>t|ƒdkr€x0|dd…D] }t|ƒt|dƒkr\td ƒ‚q\W| ¡}d }d |_d }xJ|D]B}t|tƒr°|j }|||d}|j|||d7_d }qœWg}xB|j   ¡D]4\}\} } } } } |  | | | | f|t |ƒ|f¡qòW|jtt|ƒjƒd �g|_}x|D]}|  |d¡�qPW|S)Nrrrrrr)r+rrr_r_zCan't have mixed argument typerr,z, )Úkeyr+)r0r$r?ÚintrSrGrdÚ sort_typerÚvaluer7rJÚappendrKÚsortrÚ TupleCompÚcompare)r'Zfieldr)Z sort_arg_defsZ sort_tupleZ connectorrbZ stats_listrLrMrNrOrPrQr0ÚtuplerrrÚ sort_statsÚs>      zStats.sort_statscCs|jr|j ¡|S)N)r0Úreverse)r'rrrÚ reverse_orders zStats.reverse_ordercCsú|j}i|_}d}x | ¡D]”\}\}}}}} t|ƒ} tt| ƒƒ|krTtt| ƒƒ}i} x |  ¡D]\} } | | t| ƒ<qbW| |kr t|| ||||| fƒ|| <q||||| f|| <qW|j}tƒ|_}x|D]}| t|ƒ¡qÎW||_ d|_ d|_ |S)Nr) r7rJÚfunc_strip_pathr$rKrTr6r5r&r4r0r.)r'ZoldstatsZnewstatsr4rLrMrNrOrPrQZnewfuncZ newcallersÚfunc2ÚcallerZold_topZnew_toprrrÚ strip_dirss.    zStats.strip_dirsc Cs||jr dSi|_}xb|j ¡D]T\}\}}}}}||krBi||<x0| ¡D]$\}} ||krdi||<| |||<qLWq WdS)N)r.r7rJ) r'r.rLrMrNrOrPrQrrrsrrrÚ calc_callees#s zStats.calc_calleescCs|}t|tƒrpyt |¡}Wn&tjk rB|d|7}||fSXg}x |D]}| t|ƒ¡rN| |¡qNWnzt|ƒ}t|t ƒr¸d|kr–dkr¸nnt ||dƒ}|d|…}n2t|t ƒrêd|krÖ|krênn|}|d|…}t|ƒt|ƒk�r|dt|ƒt|ƒ|f7}||fS)Nz# ggð?gà?rz6 List reduced from %r to %r due to restriction <%r> ) r?rÚreÚcompileÚerrorÚsearchrKrir$Úfloatrf)r'ZselÚlistÚmsgZnew_listZrexrLÚcountrrrÚeval_print_amount6s,    "" zStats.eval_print_amountcCsÆ|j}|jr*|jdd…}d|jd}nt|j ¡ƒ}d}x|D]}| |||¡\}}qBWt|ƒ}|spd|fSt||j d�|t|jƒkrºd}x(|D] }tt |ƒƒ|kr–tt |ƒƒ}q–W|d|fS)Nz Ordered by: Ú z! Random listing order was used r)r-r_) r4r0rgr{r7Úkeysr~r$r<r!rK)r'Zsel_listÚwidthZ stat_listr|Z selectionr}rLrrrÚget_print_listPs$  zStats.get_print_listcGsþx|jD]}t||jd�qW|jr0t|jd�d}x"|jD]}t|t|ƒ|jd�qcCs tt|ƒ |¡|d|jd�|s2t|jd�dSt| ¡ƒ}d}xÄ|D]¼}t|ƒ}||} t| tƒrÆ| \} } } } | | krˆd| | f}n d| f}d| dd t |ƒ¡t | ƒt | ƒ|f}|d }n$d || t |j |d ƒf}|d }t||||jd�d}qHWdS) Nrƒ)r„r-)r-r,z%d/%dz%dz %s %s %s %sr^r_rz %s(%r) %srZ) r<rKr�r!Úsortedr€r?rmÚrjustr$Úf8r7)r'r’ÚsourceZ call_dictZarrowZclistr‰rLr rhrNrMrOrPZsubstatsZ left_widthrrrrŒ¥s*       zStats.print_call_linecCs"tdd|jd�td|jd�dS)Nz- ncalls tottime percall cumtime percallrƒ)r„r-zfilename:lineno(function))r-)r<r!)r'rrrr†¾szStats.print_titlecCsì|j|\}}}}}t|ƒ}||kr4|dt|ƒ}t| d¡d|jd�tt|ƒd|jd�|dkrxtdd|jd�ntt||ƒd|jd�tt|ƒd|jd�|dkr¾tdd|jd�ntt||ƒd|jd�tt|ƒ|jd�dS)Nú/é rƒ)r„r-rz )r-)r7rr<r•r!r–rK)r'rLrMrNrOrPrQÚcrrrr‡ÂszStats.print_line)r“)rrrÚ__doc__r*r%r9r:r&rYr`rdrnrprtrur~r‚rŠr�rŽr‹rŒr†r‡rrrrr7sD   '  c@s eZdZdZdd„Zdd„ZdS)rka•This class provides a generic function for comparing any two tuples. Each instance records a list of tuple-indices (from most significant to least significant), and sort direction (ascending or decending) for each tuple-index. The compare functions can then be used as the function argument to the system sort() function when a list of tuples need to be sorted in the instances order.cCs ||_dS)N)Úcomp_select_list)r'rœrrrr*ÜszTupleComp.__init__cCsBx<|jD]2\}}||}||}||kr.| S||kr|SqWdS)Nr)rœ)r'ÚleftÚrightÚindexÚ directionÚlÚrrrrrlßszTupleComp.compareN)rrrr›r*rlrrrrrkÔsrkcCs|\}}}tj |¡||fS)N)rCÚpathÚbasename)Ú func_namer r r rrrrqís rqcCs|dS)Nr_r)rLrrrr…ñsr…cCsN|dd…dkrB|d}| d¡r<| d¡rz{%s}rr+z %s:%d(%s))Ú startswithÚendswith)r¥r rrrrKôs rKc Cs@|\}}}}}|\}}} } } |||||| || t| |ƒfS)z3Add together all the stats for two profile entries.)Ú add_callers) Útargetr—rMrNrOrPrQZt_ccZt_ncZt_ttZt_ctZ t_callersrrrrTsrTcCsŠi}x| ¡D]\}}|||<qWxb| ¡D]V\}}||krzt|tƒrhtdd„t|||ƒDƒƒ||<q‚|||7<q,|||<q,W|S)z*Combine two caller lists in a single list.css|]\}}||VqdS)Nr)Ú.0ÚiÚjrrrú szadd_callers..)rJr?rmÚzip)r¬r—Z new_callersrLrsrrrr« s  " r«cCs"d}x| ¡D] }||7}qW|S)z@Sum the caller statistics to get total number of calls received.r)r)rQrNrrrrÚ count_callss r²cCsd|S)Nz%8.3fr)Úxrrrr–(sr–Ú__main__c@sÞeZdZd6dd„Zdd„Zdd„Zdd „Zd d „Zd d „Zdd„Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zd d!„Zd"d#„Zd$d%„Zd&d'„Zd(d)„Zd*d+„Zd,d-„Zd.d/„Zd0d1„Zd2d3„Zd4d5„ZdS)7ÚProfileBrowserNcCs6tj |¡d|_d|_tj|_|dk r2| |¡dS)Nz% ) ÚcmdÚCmdr*Úpromptr7r"r#r!Údo_read)r'Úprofilerrrr*7s  zProfileBrowser.__init__c CsÆ| ¡}g}xŽ|D]†}y| t|ƒ¡wWntk r>YnXy8t|ƒ}|dksZ|dkrjtd|jd�w| |¡wWntk rŒYnX| |¡qW|jr´t|j|ƒ|Žntd|jd�dS)Nrrz#Fraction argument must be in [0, 1])r-zNo statistics object is loaded.) ÚsplitrirfÚ ValueErrorrzr<r!r7Úgetattr)r'Úfnr r(Z processedZtermZfracrrrÚgeneric?s,  zProfileBrowser.genericcCsXtd|jd�td|jd�td|jd�td|jd�td|jd�td|jd�dS)NzArguments may be:)r-z0* An integer maximum number of entries to print.z:* A decimal fractional number between 0 and 1, controllingz- what fraction of selected entries to print.z8* A regular expression; only entries with function namesz that match it are printed.)r<r!)r'rrrÚ generic_helpWs zProfileBrowser.generic_helpc Csd|jrRy|j |¡Wq`tk rN}ztd||f|jd�Wdd}~XYq`Xntd|jd�dS)Nz$Failed to load statistics for %s: %s)r-zNo statistics object is loaded.r)r7r&ÚOSErrorr<r!)r'r ÚerrrÚdo_add_s*zProfileBrowser.do_addcCstd|jd�dS)Nz>Add profile info from given file to current statistics object.)r-)r<r!)r'rrrÚhelp_addhszProfileBrowser.help_addcCs | d|¡S)Nr�)r¿)r'r rrrÚ do_calleeskszProfileBrowser.do_calleescCstd|jd�| ¡dS)Nz6Print callees statistics from the current stat object.)r-)r<r!rÀ)r'rrrÚ help_calleesmszProfileBrowser.help_calleescCs | d|¡S)NrŽ)r¿)r'r rrrÚ do_callersqszProfileBrowser.do_callerscCstd|jd�| ¡dS)Nz6Print callers statistics from the current stat object.)r-)r<r!rÀ)r'rrrÚ help_callerssszProfileBrowser.help_callerscCstd|jd�dS)Nr,)r-r)r<r!)r'r rrrÚdo_EOFwszProfileBrowser.do_EOFcCstd|jd�dS)NzLeave the profile brower.)r-)r<r!)r'rrrÚhelp_EOFzszProfileBrowser.help_EOFcCsdS)Nrr)r'r rrrÚdo_quit}szProfileBrowser.do_quitcCstd|jd�dS)NzLeave the profile brower.)r-)r<r!)r'rrrÚ help_quitszProfileBrowser.help_quitc CsÈ|rŽyt|ƒ|_Wnntk rH}zt|jd|jd�dSd}~XYn:tk r€}zt|jjd||jd�dSd}~XYnX|d|_ n6t |j ƒdkr¶|j dd…}|  |¡ntd|jd�dS) Nr)r-ú:z% r_éþÿÿÿz1No statistics object is current -- cannot reload.r) rr7rÁr<r(r!r;rHrr¸r$r¹)r'r Úerrrrrr¹‚s  zProfileBrowser.do_readcCs td|jd�td|jd�dS)Nz+Read in profile data from a specified file.)r-z*Without argument, reload the current file.)r<r!)r'rrrÚ help_read“szProfileBrowser.help_readcCs$|jr|j ¡ntd|jd�dS)NzNo statistics object is loaded.)r-r)r7rpr<r!)r'r rrrÚ do_reverse—s zProfileBrowser.do_reversecCstd|jd�dS)Nz/Reverse the sort order of the profiling report.)r-)r<r!)r'rrrÚ help_reverse�szProfileBrowser.help_reversecs–|jstd|jd�dS|j ¡‰|rRt‡fdd„| ¡DƒƒrR|jj| ¡Žn@td|jd�x0tj  ¡D]"\}}td||df|jd�qlWdS) NzNo statistics object is loaded.)r-c3s|]}|ˆkVqdS)Nr)r­r³)Úabbrevsrrr°¥sz)ProfileBrowser.do_sort..z/Valid sort keys (unique prefixes are accepted):z%s -- %srr) r7r<r!rdÚallr»rnrr`rJ)r'r rerhr)rÓrÚdo_sort s zProfileBrowser.do_sortcCs td|jd�td|jd�dS)Nz.Sort profile data according to specified keys.)r-z3(Typing `sort' without arguments lists valid keys.))r<r!)r'rrrÚ help_sort¬szProfileBrowser.help_sortcs‡fdd„tjDƒS)Ncsg|]}| ˆ¡r|‘qSr)r©)r­Úa)Útextrrú °sz0ProfileBrowser.complete_sort..)rr`)r'rØr(r)rØrÚ complete_sort¯szProfileBrowser.complete_sortcCs | d|¡S)NrŠ)r¿)r'r rrrÚdo_stats²szProfileBrowser.do_statscCstd|jd�| ¡dS)Nz.Print statistics from the current stat object.)r-)r<r!rÀ)r'rrrÚ help_stats´szProfileBrowser.help_statscCs$|jr|j ¡ntd|jd�dS)NzNo statistics object is loaded.)r-)r7rtr<r!)r'r rrrÚdo_strip¸s zProfileBrowser.do_stripcCstd|jd�dS)NzsR