PNG  IHDR;IDATxܻn0K )(pA 7LeG{ §㻢|ذaÆ 6lذaÆ 6lذaÆ 6lom$^yذag5bÆ 6lذaÆ 6lذa{ 6lذaÆ `}HFkm,mӪôô! x|'ܢ˟;E:9&ᶒ}{v]n&6 h_tڠ͵-ҫZ;Z$.Pkž)!o>}leQfJTu іچ\X=8Rن4`Vwl>nG^is"ms$ui?wbs[m6K4O.4%/bC%t Mז -lG6mrz2s%9s@-k9=)kB5\+͂Zsٲ Rn~GRC wIcIn7jJhۛNCS|j08yiHKֶۛkɈ+;SzL/F*\Ԕ#"5m2[S=gnaPeғL lذaÆ 6l^ḵaÆ 6lذaÆ 6lذa; _ذaÆ 6lذaÆ 6lذaÆ RIENDB`  lYg@sdZddlZddlZddlZddlZddlZddlmZdgZGdddZ GdddZ dd Z d d Z d d Z ddZddZddZddZedkrddlZyddlZWnek rYnXGdddejZeejdkrPejdZndZykeeZx(ejddD]ZejeqyWeddejej eddejWne!k rYnXdS)z3Class for printing reports on profiled python code.N) cmp_to_keyStatsc@sieZdZdZddddZddZdd Zd d Zd d ZddZ ddOddSddWdd[dd^ddadddddgd djd#dod%dsd(dvd+dzd.d~iZ d/d0Z d1d2Z d3d4Z d5d6Zd7d8Zd9d:Zd;d<Zd=d>Zd?d@ZdAdBZdCdDZdEdFdGZdHdIZdJdKZdS)raThis 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 an arbitrary number of quoted strings to select the sort order. For example sort_stats('time', '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) streamNcGs_|p tj|_t|s'd}n|d}|dd}|j||j|dS)Nr)sysstdoutrleninitadd)selfrargsargr%/opt/python35/lib/python3.5/pstats.py__init__As    zStats.__init__c Csd|_g|_d|_d|_d|_d|_d|_t|_i|_ i|_ |j |y|j WnBt k rtd|jr|jdndd|jYnXdS)NrzInvalid timing data %srfile) all_calleesfilesfcn_listtotal_tt total_calls prim_calls max_name_lenset top_levelstats sort_arg_dict load_statsget_top_level_stats Exceptionprintr)r r rrrr Ks"            'z Stats.initcCs|dkri|_dSt|trt|d}tj||_WdQRXy-tj|}tj |j d|}WnYnX|g|_ n.t |dr|j |j|_i|_|jstd|j|fdS)Nrbz create_statsz.Cannot create or construct a %r object from %r)r isinstancestropenmarshalloadosstattimectimest_mtimerhasattrr$ TypeError __class__)r r fZ file_statsrrrr^s(      zStats.load_statscCsx|jjD]\}\}}}}}|j|7_|j|7_|j|7_d|krt|jj|tt||j krtt||_ qWdS)Njprofilerprofiler)r3rr4) ritemsrrrrr rfunc_std_stringr)r funcccncttctcallersrrrr ts+ zStats.get_top_level_statscGsF|s |Sx5t|D]'}t|t|krAt|}|j|j7_|j|j7_|j|j7_|j|j7_x!|jD]}|jj|qW|j |j kr|j |_ d|_ xg|j j D]V\}}||j kr|j |}nddddif}t |||j ||jD]0\}} ||kri||<| ||| gg?g?rz6 List reduced from %r to %r due to restriction <%r> ) r%r&recompileerrorsearchr6rcrfloatra)r ZsellistmsgZnew_listZrexr7countrrreval_print_amounts,  ++zStats.eval_print_amountcCs|j}|jr9|jdd}d|jd}nt|jj}d}x)|D]!}|j|||\}}q[Wt|}|sd|fSt|d|j |t|jkrd}x8|D]0}tt ||krtt |}qW|d|fS)Nz Ordered by:  z! Random listing order was used rrrY) rrrbrurkeysrxrr"rr6)r Zsel_listwidthZ stat_listrvZ selectionrwr7rrrget_print_list2s$      zStats.get_print_listcGs[x$|jD]}t|d|jq W|jr@td|jd}x-|jD]"}t|t|d|jqPWt||jdddd|j|j|jkrtd|jddd|jtd|jd|jtd|j|j|\}}|rW|j x|D]}|j |q Wtd|jtd|j|S) Nr zfunction callsendz(%d primitive calls)zin %.3f secondsz ) rr"rrfunc_get_function_namerrrr| print_title print_line)r amountrDindentr7r{rurrr print_statsJs(  "   zStats.print_statscGs|j|\}}|r|j|j|dxM|D]E}||jkrn|j|||j|q<|j||iq<Wtd|jtd|j|S)Nz called...r)r|roprint_call_headingrprint_call_liner"r)r rr{rur7rrr print_calleesas  zStats.print_calleesc Gs|j|\}}|r|j|dx@|D]8}|j|\}}}}} |j||| dq2Wtd|jtd|j|S)Nzwas called by...z<-r)r|rrrr"r) r rr{rur7r8r9r:r;r<rrr print_callersps zStats.print_callersc Cstdj||d|jd}xT|jjD]C\}}}}}|r6tt|j} t| t}Pq6W|rtd|dd|jdS)Nz Function rFr}z ncalls tottime cumtime) r"ljustrrvaluesnextiterr%rg) r name_sizeZ column_titleZ subheaderr8r9r:r;r<valuerrrr{s %zStats.print_call_headingz->cCsktt|j||ddd|j|sFtd|jdSt|j}d}x|D]}t|}||} t| tr| \} } } } | | krd| | f}n d| f}d|jdd t |t | t | |f}|d }n.d || t |j |d f}|d }t|||d|jd}qeWdS) Nrr}rrz%d/%dz%dz %s %s %s %srWrYrz %s(%r) %srH) r"r6rrsortedrzr%rgrjustrf8r)r rsourceZ call_dictZarrowZclistrr7rQrr9r8r:r;ZsubstatsZ left_widthrrrrs*,      $ zStats.print_call_linecCs0tdddd|jtdd|jdS)Nz- ncalls tottime percall cumtime percallrr}rzfilename:lineno(function))r"r)r rrrrszStats.print_titlecCs[|j|\}}}}}t|}||krH|dt|}t|jdddd|jtt|ddd|j|dkrtdddd|jn#tt||ddd|jtt|ddd|j|dkrtd ddd|jn#tt||ddd|jtt|d|jdS) N/ rr}rrr~z z )rr&r"rrrr6)r r7r8r9r:r;r<crrrrs  " # #zStats.print_linerrrr)rrGrrrr)rrGrrHrr)rrIrrHrr)rrIrKrr)rrLrKrr)rrLrNrr)rrOrKrr)rrLrRrr)rrSrRrrKrrNrrrr)rrTrrrr)rrUrWrr)rrXrrYrr)rrZrrYrr)rrZ)__name__ __module__ __qualname____doc__rr rr r rEr[r_rhrjrnrorxr|rrrrrrrrrrrr sF                c@s.eZdZdZddZddZdS)reaThis 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 rrrrrszTupleComp.__init__cCsSxL|jD]A\}}||}||}||kr;| S||kr |Sq WdS)Nr)r)r leftrightindex directionlrrrrrfs    zTupleComp.compareN)rrrrrrfrrrrres  recCs(|\}}}tjj|||fS)N)r*pathbasename) func_namerDrMrQrrrrksrkcCs|dS)NrYr)r7rrrrsrcCsc|ddd krW|d}|jdrP|jdrPd|dd S|Snd|SdS) NrY~r<>z{%s}rz %s:%d(%s))rrr) startswithendswith)rrQrrrr6s  r6c CsV|\}}}}}|\}}} } } |||||| || t| |fS)z3Add together all the stats for two profile entries.) add_callers) targetrr8r9r:r;r<Zt_ccZt_ncZt_ttZt_ctZ t_callersrrrr?sr?cCsi}x$|jD]\}}|||s zadd_callers..)r5r%rgzip)rrZ new_callersr7rmrrrrs  !rcCs+d}x|jD]}||7}qW|S)z@Sum the caller statistics to get total number of calls received.r)r)r<r9rFrrr count_callssrcCsd|S)Nz%8.3fr)xrrrr sr__main__c@sKeZdZdddZddZddZdd Zd d Zd d ZddZ ddZ ddZ ddZ ddZ ddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd0d1Zd2d3Zd4d5ZdS)6ProfileBrowserNcCsKtjj|d|_d|_tj|_|dk rG|j|dS)Nz% ) cmdCmdrpromptrrrrdo_read)r profilerrrrs     zProfileBrowser.__init__cCs|j}g}x|D]}y|jt|wWntk rMYnXyNt|}|dksu|dkrtdd|jw|j|wWntk rYnX|j|qW|jrt|j||ntdd|jdS)Nrrz#Fraction argument must be in [0, 1]rzNo statistics object is loaded.) splitrcra ValueErrorrtr"rrgetattr)r fnrMr Z processedZtermZfracrrrgeneric"s,       zProfileBrowser.genericcCsvtdd|jtdd|jtdd|jtdd|jtdd|jtdd|jdS)NzArguments may be:rz0* 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_help:s zProfileBrowser.generic_helpcCs||jrey|jj|Wqxtk ra}z"td||fd|jWYdd}~XqxXntdd|jdS)Nz$Failed to load statistics for %s: %srzNo statistics object is loaded.r)rr IOErrorr"r)r rMerrrdo_addBs 3zProfileBrowser.do_addcCstdd|jdS)Nz>Add profile info from given file to current statistics object.r)r"r)r rrrhelp_addKszProfileBrowser.help_addcCs|jd|S)Nr)r)r rMrrr do_calleesNszProfileBrowser.do_calleescCs!tdd|j|jdS)Nz6Print callees statistics from the current stat object.r)r"rr)r rrr help_calleesPszProfileBrowser.help_calleescCs|jd|S)Nr)r)r rMrrr do_callersTszProfileBrowser.do_callerscCs!tdd|j|jdS)Nz6Print callers statistics from the current stat object.r)r"rr)r rrr help_callersVszProfileBrowser.help_callerscCstdd|jdS)Nrrr)r"r)r rMrrrdo_EOFZszProfileBrowser.do_EOFcCstdd|jdS)NzLeave the profile brower.r)r"r)r rrrhelp_EOF]szProfileBrowser.help_EOFcCsdS)Nrr)r rMrrrdo_quit`szProfileBrowser.do_quitcCstdd|jdS)NzLeave the profile brower.r)r"r)r rrr help_quitbszProfileBrowser.help_quitcCs|ryt||_Wntk r^}z#t|jdd|jdSWYdd}~XnItk r}z)t|jjd|d|jdSWYdd}~XnX|d|_ nKt |j dkr|j dd}|j |ntdd|jdS) Nrr:z% rYz1No statistics object is current -- cannot reload.r) rrOSErrorr"r rr!r1rrrr)r rMerrrrrres zProfileBrowser.do_readcCs*tdd|jtdd|jdS)Nz+Read in profile data from a specified file.rz*Without argument, reload the current file.)r"r)r rrr help_readvszProfileBrowser.help_readcCs0|jr|jjntdd|jdS)NzNo statistics object is loaded.rr)rrjr"r)r rMrrr do_reversezs zProfileBrowser.do_reversecCstdd|jdS)Nz/Reverse the sort order of the profiling report.r)r"r)r rrr help_reverseszProfileBrowser.help_reversecs|js tdd|jdS|jj|rstfdd|jDrs|jj|jnTtdd|jx>tjj D]-\}}td||dfd|jqWdS) NzNo statistics object is loaded.rc3s|]}|kVqdS)Nr)rr)abbrevsrr sz)ProfileBrowser.do_sort..z/Valid sort keys (unique prefixes are accepted):z%s -- %srr) rr"rr_allrrhrr[r5)r rMr`rr)rrdo_sorts +%zProfileBrowser.do_sortcCs*tdd|jtdd|jdS)Nz.Sort profile data according to specified keys.rz3(Typing `sort' without arguments lists valid keys.))r"r)r rrr help_sortszProfileBrowser.help_sortcsfddtjDS)Ncs%g|]}|jr|qSr)r)ra)textrrrs z0ProfileBrowser.complete_sort..)rr[)r rr r)rr complete_sortszProfileBrowser.complete_sortcCs|jd|S)Nr)r)r rMrrrdo_statsszProfileBrowser.do_statscCs!tdd|j|jdS)Nz.Print statistics from the current stat object.r)r"rr)r rrr help_statsszProfileBrowser.help_statscCs0|jr|jjntdd|jdS)NzNo statistics object is loaded.r)rrnr"r)r rMrrrdo_strips zProfileBrowser.do_stripcCstdd|jdS)NzsH