grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026o ®û|jŽrã@sÄdZddlZddlZddlZddlZddlZddlmZddlm Z ddl m Z ddl m Z gd¢ZGdd „d eeƒZe d d �Gd d „d ƒƒZe d d �Gdd„dƒƒZGdd„dƒZGdd„dƒZdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zd d!„Zed"kràddlZzddlZWn ey”YnwGd#d$„d$ej ƒZ!e"ej#ƒd%kr«ej#d%Z$ndZ$z(e!e$ƒZ%ej#d&d…D]Z&e% 'e&¡q¹e(d'e%j)d(�e% *¡e(d)e%j)d(�WdSe+yßYdSwdS)*z3Class for printing reports on profiled python code.éN)ÚEnum)Ú cmp_to_key)Ú dataclass)ÚDict)ÚStatsÚSortKeyÚFunctionProfileÚ StatsProfilec@s8eZdZdZdZdZdZdZdZdZ dZ d Z d d „Z d S) r)ÚcallsÚncalls)Ú cumulativeÚcumtime)ÚfilenameÚmoduleÚlineÚnameÚnflÚpcallsÚstdname)ÚtimeÚtottimecGs@|d}t ||¡}||_|dd…D]}||j|<q||_|S©Nré)ÚstrÚ__new__Ú_value_Ú_value2member_map_Z _all_values)ÚclsÚvaluesÚvalueÚobjZ other_value©r!ú-/opt/alt/python310/lib64/python3.10/pstats.pyr/s  zSortKey.__new__N) Ú__name__Ú __module__Ú __qualname__ZCALLSZ CUMULATIVEZFILENAMEZLINEÚNAMEZNFLZPCALLSZSTDNAMEZTIMErr!r!r!r"r$s rT)Z unsafe_hashc@sFeZdZUeed<eed<eed<eed<eed<eed<eed<dS) rr rÚpercall_tottimer Úpercall_cumtimeÚ file_nameÚ line_numberN)r#r$r%rÚ__annotations__ÚfloatÚintr!r!r!r"r9s  rc@s*eZdZUdZeed<eeefed<dS)r z0Class for keeping track of an item in inventory.Útotal_ttÚ func_profilesN) r#r$r%Ú__doc__r,r+rrrr!r!r!r"r Cs r c@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/„Zd0d1„Zd9d3d4„Zd5d6„Zd7d8„ZdS):raÛ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|ƒs d}n |d}|dd…}| |¡|j|ŽdSr)ÚsysÚstdoutr1ÚlenÚinitÚadd)Úselfr1ÚargsÚargr!r!r"Ú__init__ks   zStats.__init__cCsŠd|_g|_d|_d|_d|_d|_d|_tƒ|_i|_ i|_ |  |¡z|  ¡WdSt yDtd|jr<|jdnd|jd�‚w)NrzInvalid timing data %séÿÿÿÿÚ©Úfile)Ú all_calleesÚfilesÚfcn_listr.Ú total_callsÚ prim_callsÚ max_name_lenÚsetÚ top_levelÚstatsÚ sort_arg_dictÚ load_statsÚget_top_level_statsÚ ExceptionÚprintr1)r7r9r!r!r"r5us*  ÿÿýz Stats.initcCsÄ|dur i|_dSt|tƒrDt|dƒ�}t |¡|_Wdƒn1s$wYzt |¡}t  |j ¡d|}WnY|g|_ nt |dƒrT|  ¡|j|_i|_|js`td|j|fƒ‚dS)NÚrbz Ú create_statsz.Cannot create or construct a %r object from %r)rGÚ isinstancerÚopenÚmarshalÚloadÚosÚstatrÚctimeÚst_mtimer@ÚhasattrrNÚ TypeErrorÚ __class__)r7r9ÚfZ file_statsr!r!r"rIˆs,  ÿ   ÿzStats.load_statscCs€|j ¡D]8\}\}}}}}|j|7_|j|7_|j|7_d|vr-|j |¡tt|ƒƒ|j kr=tt|ƒƒ|_ qdS)N)ZjprofilerZprofiler) rGÚitemsrBrCr.rFr6r4Úfunc_std_stringrD)r7ÚfuncÚccÚncÚttÚctÚcallersr!r!r"rJžs €ùzStats.get_top_level_statscGsì|s|St|ƒD]k}t|ƒt|ƒkrt|ƒ}|j|j7_|j|j7_|j|j7_|j|j7_|jD]}|j |¡q9|j |j krL|j |_ d|_ |j   ¡D]\}}||j vrc|j |}nddddif}t ||ƒ|j |<qTq|S©Nr)ÚreversedÚtyperr@rBrCr.rFr6rDrArGr[Úadd_func_stats)r7Úarg_listÚitemr]rTZ old_func_statr!r!r"r6¨s*     ûz Stats.addcCs>t|dƒ�}t |j|¡WdƒdS1swYdS)z:Write the profile data to a file we know how to load back.ÚwbN)rPrQÚdumprG)r7rrZr!r!r"Ú dump_statsÂs "ÿzStats.dump_stats)))rr;z call count)))ér;zcumulative time))©érz file name))©érz line number))©érz function name))rqrmrozname/file/line)))rr;zprimitive call count)))érz standard name)))ér;z internal time) r r r r rrrrrrrrrcCsv|js8i|_}i}|j ¡D] \}}|}|r/|sn||vr#d||<n |||<|dd…}|sq|D]}||=q2|jS)z)Expand all abbreviations that are unique.rNr;)rHÚsort_arg_dict_defaultr[)r7ÚdictZbad_listÚwordÚtupZfragmentr!r!r"Úget_sort_arg_defsÙs$  ù€zStats.get_sort_arg_defscGsZ|sd|_|St|ƒdkr!t|dtƒr!dddddœ|dg}nt|ƒdkr>|dd…D]}t|ƒt|dƒkr=td ƒ‚q-| ¡}d }d |_d }|D]!}t|tƒrU|j }|||d}|j|||d7_d }qKg}|j   ¡D]\}\} } } } } |  | | | | f|t |ƒ|f¡qt|jtt|ƒjƒd �g|_}|D] }|  |d¡q¡|S)Nrrrr rr )r;rrrtrtzCan't have mixed argument typer!r<z, )Úkeyr;)rAr4rOr-rerXryÚ sort_typerrrGr[Úappendr\ÚsortrÚ TupleCompÚcompare)r7Zfieldr9Z sort_arg_defsZ sort_tupleZ connectorrwZ stats_listr]r^r_r`rarbrAÚtupler!r!r"Ú sort_statsìsHýý ÿ  ÿ zStats.sort_statscCs|jr|j ¡|S©N)rAÚreverse©r7r!r!r"Ú reverse_orders zStats.reverse_ordercCsî|j}i|_}d}| ¡D]H\}\}}}}} t|ƒ} tt| ƒƒ|kr)tt| ƒƒ}i} |  ¡D] \} } | | t| ƒ<q/| |vrMt|| ||||| fƒ|| <q||||| f|| <q|j}tƒ|_}|D] }| t|ƒ¡qb||_ d|_ d|_ |Src) rGr[Úfunc_strip_pathr4r\rfrFrEr6rDrAr?)r7ZoldstatsZnewstatsrDr]r^r_r`rarbZnewfuncZ newcallersÚfunc2ÚcallerZold_topZnew_topr!r!r"Ú strip_dirss0    þ zStats.strip_dirsc Cst|jrdSi|_}|j ¡D](\}\}}}}}||vr i||<| ¡D]\}} ||vr0i||<| |||<q$qdSr‚)r?rGr[) r7r?r]r^r_r`rarbr‡rˆr!r!r"Ú calc_callees5s ýzStats.calc_calleescCs|}t|tƒr7zt |¡}Wntjy"|d|7}||fYSwg}|D]}| t|ƒ¡r5| |¡q'n=t|ƒ}t|t ƒr[d|krJdkr[nnt ||dƒ}|d|…}nt|t ƒrtd|krj|krtnn|}|d|…}t|ƒt|ƒkr‰|dt|ƒt|ƒ|f7}||fS)Nz# ggð?gà?rz6 List reduced from %r to %r due to restriction <%r> ) rOrÚreÚcompileÚerrorÚsearchr\r|r4r,r-)r7ZselÚlistÚmsgZnew_listZrexr]Úcountr!r!r"Úeval_print_amountHs4   þ €þ"" ÿzStats.eval_print_amountc Cs|jr |jdd…nt|j ¡ƒ}|stdiƒStt|jƒƒ}i}t||ƒ}|D]Y}|j|\}}}} } |\} } } ||krAt|ƒn t|ƒdt|ƒ}tt|ƒƒ}|dkrWdntt||ƒƒ}tt| ƒƒ}|dkrkdntt| |ƒƒ}t |||||| | ƒ}||| <q(|S)a?This method returns an instance of StatsProfile, which contains a mapping of function names to instances of FunctionProfile. Each FunctionProfile instance holds information related to the function's profile such as how long the function took to run, how many times it was called, etc... Nrú/r;) rAr�rGÚkeysr r,Úf8r.rr)r7Z func_listr.r/Z stats_profiler]r^r_r`rarbr)r*Ú func_namer rr'r r(Z func_profiler!r!r"Úget_stats_profilebs2"   $  ù zStats.get_stats_profilecCs¾|j}|jr|jdd…}d|jd}n t|j ¡ƒ}d}|D] }| |||¡\}}q t|ƒ}|s6d|fSt||j d�|t|jƒkrYd}|D]}tt |ƒƒ|krXtt |ƒƒ}qH|d|fS)Nz Ordered by: Ú z! Random listing order was used rr=rt) rDrAr{r�rGr”r’r4rLr1r\)r7Zsel_listÚwidthZ stat_listr�Z selectionr‘r]r!r!r"Úget_print_list…s& € zStats.get_print_listcGsò|jD] }t||jd�q|jrt|jd�d}|jD] }t|t|ƒ|jd�qt||jdd|jd�|j|jkrDtd|jd|jd�td|j|jd�t|jd�| |¡\}}|rw|  ¡|D]}|  |¡qct|jd�t|jd�|S)Nr=ú zfunction callsú ©Úendr>z(%d primitive calls)zin %.3f seconds) r@rLr1rFÚfunc_get_function_namerBrCr.ršÚ print_titleÚ print_line)r7ÚamountrÚindentr]r™r�r!r!r"Ú print_stats�s(        zStats.print_statscGsz| |¡\}}|r;| ¡| |d¡|D]}||jvr'| |||j|¡q| ||i¡qt|jd�t|jd�|S)Nz called...r=)ršrŠÚprint_call_headingr?Úprint_call_linerLr1)r7r¢r™r�r]r!r!r"Ú print_callees´s    zStats.print_calleesc Gsh| |¡\}}|r2| |d¡|D]}|j|\}}}}} | ||| d¡qt|jd�t|jd�|S)Nzwas called by...z<-r=)ršr¥rGr¦rLr1) r7r¢r™r�r]r^r_r`rarbr!r!r"Ú print_callersÃs   zStats.print_callersc Csztd |¡||jd�d}|j ¡D]\}}}}}|r+tt| ¡ƒƒ} t| tƒ}nq|r;td|d|jd�dSdS)Nz Function r=Frœz ncalls tottime cumtime) rLÚljustr1rGrÚnextÚiterrOr€) r7Ú name_sizeZ column_titleZ subheaderr^r_r`rarbrr!r!r"r¥Îs ýÿzStats.print_call_headingú->cCstt|ƒ |¡|d|jd�|st|jd�dSt| ¡ƒ}d}|D]^}t|ƒ}||} t| tƒrb| \} } } } | | krCd| | f}nd| f}d| dd t |ƒ¡t | ƒt | ƒ|f}|d }nd || t |j |d ƒf}|d }t||||jd�d}q#dS) Nrœr�r=r<z%d/%dz%dz %s %s %s %srsrtrz %s(%r) %srl) rLr\r©r1Úsortedr”rOr€Úrjustr4r•rG)r7r¬ÚsourceZ call_dictZarrowZclistr£r]rrr_r^r`raZsubstatsZ left_widthr!r!r"r¦Ús.     ÿ ðzStats.print_call_linecCs"tdd|jd�td|jd�dS)Nz- ncalls tottime percall cumtime percallrœr�zfilename:lineno(function)r=©rLr1r„r!r!r"r ószStats.print_titlecCsì|j|\}}}}}t|ƒ}||kr|dt|ƒ}t| d¡d|jd�tt|ƒd|jd�|dkrz{%s}rr;z %s:%d(%s))Ú startswithÚendswith)r–rr!r!r"r\)s r\c Cs@|\}}}}}|\}}} } } |||||| || t| |ƒfS)z3Add together all the stats for two profile entries.)Ú add_callers) Útargetr°r^r_r`rarbZt_ccZt_ncZt_ttZt_ctZ t_callersr!r!r"rf:s ÿrfcCs‚i}| ¡D]\}}|||<q| ¡D]+\}}||vr:t|tƒr1tdd„t|||ƒDƒƒ||<q|||7<q|||<q|S)z*Combine two caller lists in a single list.css�|] \}}||VqdSr‚r!)Ú.0ÚiÚjr!r!r"Ú Js€zadd_callers..)r[rOr€Úzip)rÄr°Z new_callersr]rˆr!r!r"rÃAs  " rÃcCsd}| ¡D]}||7}q|S)z@Sum the caller statistics to get total number of calls received.r)r)rbr_r r!r!r"Ú count_callsRs  rÊcCsd|S)Nz%8.3fr!)Úxr!r!r"r•]r½r•Ú__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ÚProfileBrowserNcCs:tj |¡d|_d|_tj|_|dur| |¡dSdS)Nú% ) ÚcmdÚCmdr:ÚpromptrGr2r3r1Údo_read)r7Úprofiler!r!r"r:ls ÿzProfileBrowser.__init__c Cs¾| ¡}g}|D]@}z | t|ƒ¡WqtyYnwzt|ƒ}|dks*|dkr3td|jd�Wq| |¡WqtyBYnw| |¡q|jrVt|j|ƒ|ŽdStd|jd�dS)Nrrz#Fraction argument must be in [0, 1]r=úNo statistics object is loaded.) Úsplitr|r-Ú ValueErrorr,rLr1rGÚgetattr)r7Úfnrr8Z processedZtermZfracr!r!r"Úgenericts2 ÿ  ÿ ÿ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!r!r"Ú generic_helpŒs zProfileBrowser.generic_helpc Csh|jr+z |j |¡WdSty*}ztd||f|jd�WYd}~dSd}~wwtd|jd�dS)Nz$Failed to load statistics for %s: %sr=rÔr)rGr6ÚOSErrorrLr1)r7rÚer!r!r"Údo_add”sü €üzProfileBrowser.do_addcCótd|jd�dS)Nz>Add profile info from given file to current statistics object.r=r±r„r!r!r"Úhelp_add�ózProfileBrowser.help_addcCó | d|¡S)Nr§©rÙ©r7rr!r!r"Ú do_callees ó zProfileBrowser.do_calleescCótd|jd�| ¡dS)Nz6Print callees statistics from the current stat object.r=©rLr1rÚr„r!r!r"Ú help_callees¢ó zProfileBrowser.help_calleescCrá)Nr¨rârãr!r!r"Ú do_callers¦råzProfileBrowser.do_callerscCræ)Nz6Print callers statistics from the current stat object.r=rçr„r!r!r"Ú help_callers¨rézProfileBrowser.help_callerscCstd|jd�dS)Nr<r=rr±rãr!r!r"Údo_EOF¬szProfileBrowser.do_EOFcCrÞ©NzLeave the profile browser.r=r±r„r!r!r"Úhelp_EOF¯ràzProfileBrowser.help_EOFcCsdS)Nrr!rãr!r!r"Údo_quit²szProfileBrowser.do_quitcCrÞrír±r„r!r!r"Ú help_quit´ràzProfileBrowser.help_quitc CsÔ|rLzt|ƒ|_Wn;ty&}zt|jd|jd�WYd}~dSd}~wtyD}zt|jjd||jd�WYd}~dSd}~ww|d|_ dSt |j ƒdkra|j dd…}|  |¡dStd|jd�dS) Nrr=ú:rÎrtéþÿÿÿz1No statistics object is current -- cannot reload.r) rrGrÛrLr8r1rKrYr#rÑr4rÒ)r7rÚerrr!r!r"rÒ·s(€€þ û ÿzProfileBrowser.do_readcCó 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!r!r"Ú help_readÈózProfileBrowser.help_readcCs&|jr |j ¡dStd|jd�dS)NrÔr=r)rGr…rLr1rãr!r!r"Ú do_reverseÌs  ÿzProfileBrowser.do_reversecCrÞ)Nz/Reverse the sort order of the profiling report.r=r±r„r!r!r"Ú help_reverseÒràzProfileBrowser.help_reversecs”|js td|jd�dS|j ¡‰|r*t‡fdd„| ¡Dƒƒr*|jj| ¡ŽdStd|jd�tj  ¡D]\}}td||df|jd�q6dS) NrÔr=c3s�|]}|ˆvVqdSr‚r!)rÅrË©Zabbrevsr!r"rÈÚs€z)ProfileBrowser.do_sort..z/Valid sort keys (unique prefixes are accepted):z%s -- %srr) rGrLr1ryÚallrÕr�rrur[)r7rrzrr!rùr"Údo_sortÕs ýzProfileBrowser.do_sortcCrô)Nz.Sort profile data according to specified keys.r=z3(Typing `sort' without arguments lists valid keys.)r±r„r!r!r"Ú help_sortárözProfileBrowser.help_sortcs‡fdd„tjDƒS)Ncsg|] }| ˆ¡r|‘qSr!)rÁ)rÅÚa©Útextr!r"Ú åsz0ProfileBrowser.complete_sort..)rru)r7rÿr8r!rþr"Ú complete_sortäszProfileBrowser.complete_sortcCrá)Nr¤rârãr!r!r"Údo_statsçråzProfileBrowser.do_statscCræ)Nz.Print statistics from the current stat object.r=rçr„r!r!r"Ú help_statsérézProfileBrowser.help_statscCs&|jr |j ¡dStd|jd�dS)NrÔr=)rGr‰rLr1rãr!r!r"Údo_stripíszProfileBrowser.do_stripcCrÞ)Nzsh     C   ÿ   ÿ�Û