ž Ś˙fgc@sÝdZddlZddlZddlZddlZddlZddlmZdgZGdd„dƒZ Gdd„dƒZ dd „Z d d „Z d d „Z dd„Zdd„Zdd„Zdd„ZedkrŮddlZyddlZWnek rYnXGdd„dejƒZeejƒdkrPejdZneZykeeƒZx(ejdd…D]ZejeƒqyWeddej ƒej!ƒeddej ƒWne"k rŐYnXndS(u3Class for printing reports on profiled python code.iN(u cmp_to_keyuStatscBs{|EeZdZdZddKdd„Zdd„Zdd„Zd d „Zd d „Z d d„Z idOd6dSd6dWd6d[d6d^d6dad6ddd6dgd6djd!6dod#6dsd&6dvd)6dzd,6d~d-6Z d.d/„Z d0d1„Z d2d3„Zd4d5„Zd6d7„Zd8d9„Zd:d;„Zd<d=„Zd>d?„Zd@dA„ZdBdC„ZdDdEdF„ZdGdH„ZdIdJ„ZdKS(uStatsu<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). 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) ustreamcGs_|p tj|_t|ƒs'd}n|d}|dd…}|j|ƒ|j|ŒdS(Nii(usysustdoutustreamulenuNoneuinituadd(uselfustreamuargsuarg((u+/opt/alt/python33/lib64/python3.3/pstats.pyu__init__>s    uStats.__init__c CsÁd|_g|_d|_d|_d|_d|_d|_tƒ|_ i|_ i|_ |j |ƒy|j ƒWnBtk rźtd|jr¤|jdndd|jƒ‚YnXdS(NiuInvalid timing data %siuufilei˙˙˙˙(uNoneu all_calleesufilesufcn_listutotal_ttu total_callsu prim_callsu max_name_lenusetu top_levelustatsu sort_arg_dictu load_statsuget_top_level_statsu Exceptionuprintustream(uselfuarg((u+/opt/alt/python33/lib64/python3.3/pstats.pyuinitHs"            'u Stats.initc Csô|dkri|_dSt|tƒršt|dƒ}tj|ƒ|_|jƒy-tj |ƒ}t j |j ƒd|}WnYnX|g|_ n1t|dƒrË|jƒ|j|_i|_n|jsđtd|j|fƒ‚ndS(Nurbu u create_statsu.Cannot create or construct a %r object from %r(uNoneustatsu isinstanceustruopenumarshaluloaducloseuosustatutimeuctimeust_mtimeufilesuhasattru create_statsu TypeErroru __class__(uselfuargufu file_stats((u+/opt/alt/python33/lib64/python3.3/pstats.pyu load_stats[s*       uStats.load_statscCs˛xŤ|jjƒD]š\}\}}}}}|j|7_|j|7_|j|7_d|krw|jj|ƒntt|ƒƒ|j krtt|ƒƒ|_ qqWdS(Nujprofileiuprofiler(ujprofileiuprofiler( ustatsuitemsu total_callsu prim_callsutotal_ttu top_leveluaddulenufunc_std_stringu max_name_len(uselfufuncuccuncuttuctucallers((u+/opt/alt/python33/lib64/python3.3/pstats.pyuget_top_level_statsrs+ uStats.get_top_level_statscGsL|s |Sx;t|ƒD]-}t|ƒt|ƒkrDt|ƒ}n|j|j7_|j|j7_|j|j7_|j|j7_x!|jD]}|jj|ƒq–W|j |j krŃ|j |_ nd|_ xg|j j ƒD]V\}}||j kr|j |}nddddif}t||ƒ|j | ggđ?gŕ?iu6 List reduced from %r to %r due to restriction <%r> ( u isinstanceustrureucompileuerrorusearchufunc_std_stringuappendulenufloatuint(uselfuselulistumsgunew_listurexufuncucount((u+/opt/alt/python33/lib64/python3.3/pstats.pyueval_print_amounts,  ++ uStats.eval_print_amountcCs|j}|jr9|jdd…}d|jd}nt|jjƒƒ}d}x)|D]!}|j|||ƒ\}}q[Wt|ƒ}|sœd|fSt|d|j ƒ|t|jƒkr d}x>|D]3}tt |ƒƒ|krŃtt |ƒƒ}qŃqŃWn|d|fS(Nu Ordered by: u u! Random listing order was used iufilei( u max_name_lenufcn_listu sort_typeulistustatsukeysueval_print_amountulenuprintustreamufunc_std_string(uselfusel_listuwidthu stat_listumsgu selectionucountufunc((u+/opt/alt/python33/lib64/python3.3/pstats.pyuget_print_list3s$      uStats.get_print_listcGsdx$|jD]}t|d|jƒq W|jrCtd|jƒnd}x-|jD]"}t|t|ƒd|jƒqSWt||jdddd|jƒ|j|jkrĐtd|jddd|jƒntd|jd|jƒtd|jƒ|j|ƒ\}}|r`|j ƒx|D]}|j |ƒq&Wtd|jƒtd|jƒn|S( Nufileu iufunction callsuendu(%d primitive calls)uin %.3f secondsu ( ufilesuprintustreamu top_levelufunc_get_function_nameu total_callsu prim_callsutotal_ttuget_print_listu print_titleu print_line(uselfuamountufilenameuindentufuncuwidthulist((u+/opt/alt/python33/lib64/python3.3/pstats.pyu print_statsKs(  "#  uStats.print_statscGsŹ|j|ƒ\}}|r¨|jƒ|j|dƒxM|D]E}||jkrn|j|||j|ƒq<|j||iƒq<Wtd|jƒtd|jƒn|S(Nu called...ufile(uget_print_listu calc_calleesuprint_call_headingu all_calleesuprint_call_lineuprintustream(uselfuamountuwidthulistufunc((u+/opt/alt/python33/lib64/python3.3/pstats.pyu print_calleesbs  uStats.print_calleesc Gs•|j|ƒ\}}|r‘|j|dƒx@|D]8}|j|\}}}}} |j||| dƒq2Wtd|jƒtd|jƒn|S(Nuwas called by...u<-ufile(uget_print_listuprint_call_headingustatsuprint_call_lineuprintustream( uselfuamountuwidthulistufuncuccuncuttuctucallers((u+/opt/alt/python33/lib64/python3.3/pstats.pyu print_callersqs uStats.print_callersc Cs¨tdj|ƒ|d|jƒd}xW|jjƒD]F\}}}}}|r6tt|jƒƒƒ} t| t ƒ}Pq6q6W|r¤td|dd|jƒndS(Nu Function ufileu u ncalls tottime cumtimeF( uprintuljustustreamuFalseustatsuvaluesunextuiteru isinstanceutuple( uselfu name_sizeu column_titleu subheaderuccuncuttuctucallersuvalue((u+/opt/alt/python33/lib64/python3.3/pstats.pyuprint_call_heading|s %uStats.print_call_headingu->cCsktt|ƒj|ƒ|ddd|jƒ|sFtd|jƒdSt|jƒƒ}d}x|D]ţ}t|ƒ}||} t| tƒr| \} } } } | | krÁd| | f}n d| f}d|jdd t |ƒƒt | ƒt | ƒ|f}|d }n.d || t |j |d ƒf}|d }t|||d|jƒd}qeWdS( Nuendu ufileuu%d/%du%du %s %s %s %siiiu %s(%r) %si( uprintufunc_std_stringuljustustreamusortedukeysu isinstanceutupleurjustulenuf8ustats(uselfu name_sizeusourceu call_dictuarrowuclistuindentufuncunameuvalueuncuccuttuctusubstatsu left_width((u+/opt/alt/python33/lib64/python3.3/pstats.pyuprint_call_lineˆs*,      $ uStats.print_call_linecCs0tdddd|jƒtdd|jƒdS(Nu- ncalls tottime percall cumtime percalluendu ufileufilename:lineno(function)(uprintustream(uself((u+/opt/alt/python33/lib64/python3.3/pstats.pyu print_titleĄsuStats.print_titlecCs^|j|\}}}}}t|ƒ}||krK|dt|ƒ}nt|jdƒddd|jƒtt|ƒddd|jƒ|dkr´tdddd|jƒn#tt||ƒddd|jƒtt|ƒddd|jƒ|dkrtd ddd|jƒn#tt||ƒddd|jƒtt|ƒd|jƒdS( Nu/i uendu ufileiiu u (ustatsustruprinturjustustreamuf8ufunc_std_string(uselfufuncuccuncuttuctucallersuc((u+/opt/alt/python33/lib64/python3.3/pstats.pyu print_lineĽs  " # #uStats.print_lineNi˙˙˙˙(ii˙˙˙˙((ii˙˙˙˙(((ii˙˙˙˙u call counti˙˙˙˙(ii˙˙˙˙((ii˙˙˙˙(((ii˙˙˙˙u call counti˙˙˙˙(ii˙˙˙˙((ii˙˙˙˙(((ii˙˙˙˙ucumulative timei˙˙˙˙(ii˙˙˙˙((ii˙˙˙˙(((ii˙˙˙˙ucumulative time(ii((ii(((iiu file name(ii((ii(((iiu file name(ii((ii(((iiu line number(ii((ii(((iiu file name(ii((ii(((iiu function name(ii(ii(ii((ii(ii(ii(((ii(ii(iiuname/file/linei˙˙˙˙(ii˙˙˙˙((ii˙˙˙˙(((ii˙˙˙˙uprimitive call count(ii((ii(((iiu standard namei˙˙˙˙(ii˙˙˙˙((ii˙˙˙˙(((ii˙˙˙˙u internal timei˙˙˙˙(ii˙˙˙˙((ii˙˙˙˙(((ii˙˙˙˙u internal time(u__name__u __module__u __qualname__u__doc__uNoneu__init__uinitu load_statsuget_top_level_statsuaddu dump_statsusort_arg_dict_defaultuget_sort_arg_defsu sort_statsu reverse_orderu strip_dirsu calc_calleesueval_print_amountuget_print_listu print_statsu print_calleesu print_callersuprint_call_headinguprint_call_lineu print_titleu print_line(u __locals__((u+/opt/alt/python33/lib64/python3.3/pstats.pyuStats sH               cBs2|EeZdZdZdd„Zdd„ZdS(u TupleCompu•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(ucomp_select_list(uselfucomp_select_list((u+/opt/alt/python33/lib64/python3.3/pstats.pyu__init__żsuTupleComp.__init__cCsSxL|jD]A\}}||}||}||kr;| S||kr |Sq WdS(Ni(ucomp_select_list(uselfulefturightuindexu directionulur((u+/opt/alt/python33/lib64/python3.3/pstats.pyucompareÂs    uTupleComp.compareN(u__name__u __module__u __qualname__u__doc__u__init__ucompare(u __locals__((u+/opt/alt/python33/lib64/python3.3/pstats.pyu TupleCompˇs u TupleCompcCs(|\}}}tjj|ƒ||fS(N(uosupathubasename(u func_nameufilenameulineuname((u+/opt/alt/python33/lib64/python3.3/pstats.pyufunc_strip_pathĐsufunc_strip_pathcCs|dS(Ni((ufunc((u+/opt/alt/python33/lib64/python3.3/pstats.pyufunc_get_function_nameÔsufunc_get_function_namecCsc|dd…d krW|d}|jdƒrP|jdƒrPd|dd …S|Snd|SdS( Niu~iuu{%s}iu %s:%d(%s)(u~ii˙˙˙˙(u startswithuendswith(u func_nameuname((u+/opt/alt/python33/lib64/python3.3/pstats.pyufunc_std_string×s  ufunc_std_stringc CsV|\}}}}}|\}}} } } |||||| || t| |ƒfS(u3Add together all the stats for two profile entries.(u add_callers( utargetusourceuccuncuttuctucallersut_ccut_ncut_ttut_ctu t_callers((u+/opt/alt/python33/lib64/python3.3/pstats.pyuadd_func_statsčsuadd_func_statscCsąi}x$|jƒD]\}}|||řs uadd_callers..(uitemsu isinstanceutupleuzip(utargetusourceu new_callersufuncucaller((u+/opt/alt/python33/lib64/python3.3/pstats.pyu add_callersďs  !u add_callerscCs+d}x|jƒD]}||7}qW|S(u@Sum the caller statistics to get total number of calls received.i(uvalues(ucallersuncucalls((u+/opt/alt/python33/lib64/python3.3/pstats.pyu count_callssu count_callscCsd|S(Nu%8.3f((ux((u+/opt/alt/python33/lib64/python3.3/pstats.pyuf8 suf8u__main__cBsO|EeZdZd5dd„Zdd„Zdd„Zdd„Zd d „Zd d „Z d d„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd„Zdd „Zd!d"„Zd#d$„Zd%d&„Zd'd(„Zd)d*„Zd+d,„Zd-d.„Zd/d0„Zd1d2„Zd3d4„Zd5S(6uProfileBrowsercCsNtjj|ƒd|_d|_tj|_|dk rJ|j |ƒndS(Nu% ( ucmduCmdu__init__upromptuNoneustatsusysustdoutustreamudo_read(uselfuprofile((u+/opt/alt/python33/lib64/python3.3/pstats.pyu__init__s     uProfileBrowser.__init__cCsţ|jƒ}g}x°|D]¨}y|jt|ƒƒwWntk rMYnXyQt|ƒ}|dksu|dkrŽtdd|jƒwn|j|ƒwWntk rłYnX|j|ƒqW|jrçt|j|ƒ|Œntdd|jƒdS(Niiu#Fraction argument must be in [0, 1]ufileuNo statistics object is loaded.( usplituappenduintu ValueErrorufloatuprintustreamustatsugetattr(uselfufnulineuargsu processedutermufrac((u+/opt/alt/python33/lib64/python3.3/pstats.pyugeneric#s,       uProfileBrowser.genericcCsvtdd|jƒtdd|jƒtdd|jƒtdd|jƒtdd|jƒtdd|jƒdS(NuArguments may be:ufileu0* An integer maximum number of entries to print.u:* A decimal fractional number between 0 and 1, controllingu- what fraction of selected entries to print.u8* A regular expression; only entries with function namesu that match it are printed.(uprintustream(uself((u+/opt/alt/python33/lib64/python3.3/pstats.pyu generic_help;s uProfileBrowser.generic_helpcCs3|jr|jj|ƒntdd|jƒdS(NuNo statistics object is loaded.ufilei(ustatsuadduprintustream(uselfuline((u+/opt/alt/python33/lib64/python3.3/pstats.pyudo_addCs uProfileBrowser.do_addcCstdd|jƒdS(Nu>Add profile info from given file to current statistics object.ufile(uprintustream(uself((u+/opt/alt/python33/lib64/python3.3/pstats.pyuhelp_addIsuProfileBrowser.help_addcCs|jd|ƒS(Nu print_callees(ugeneric(uselfuline((u+/opt/alt/python33/lib64/python3.3/pstats.pyu do_calleesLsuProfileBrowser.do_calleescCs!tdd|jƒ|jƒdS(Nu6Print callees statistics from the current stat object.ufile(uprintustreamu generic_help(uself((u+/opt/alt/python33/lib64/python3.3/pstats.pyu help_calleesNsuProfileBrowser.help_calleescCs|jd|ƒS(Nu print_callers(ugeneric(uselfuline((u+/opt/alt/python33/lib64/python3.3/pstats.pyu do_callersRsuProfileBrowser.do_callerscCs!tdd|jƒ|jƒdS(Nu6Print callers statistics from the current stat object.ufile(uprintustreamu generic_help(uself((u+/opt/alt/python33/lib64/python3.3/pstats.pyu help_callersTsuProfileBrowser.help_callerscCstdd|jƒdS(Nuufilei(uprintustream(uselfuline((u+/opt/alt/python33/lib64/python3.3/pstats.pyudo_EOFXsuProfileBrowser.do_EOFcCstdd|jƒdS(NuLeave the profile brower.ufile(uprintustream(uself((u+/opt/alt/python33/lib64/python3.3/pstats.pyuhelp_EOF[suProfileBrowser.help_EOFcCsdS(Ni((uselfuline((u+/opt/alt/python33/lib64/python3.3/pstats.pyudo_quit^suProfileBrowser.do_quitcCstdd|jƒdS(NuLeave the profile brower.ufile(uprintustream(uself((u+/opt/alt/python33/lib64/python3.3/pstats.pyu help_quit`suProfileBrowser.help_quitcCs|rˇyt|ƒ|_Wn‹tk r^}z#t|jdd|jƒdSWYdd}~XnItk rŚ}z)t|jjd|d|jƒdSWYdd}~XnX|d|_ nKt |j ƒdkrď|j dd…}|j |ƒntdd|jƒdS( Niufileu:u% iu1No statistics object is current -- cannot reload.iiţ˙˙˙( uStatsustatsuIOErroruprintuargsustreamu Exceptionu __class__u__name__upromptulenudo_read(uselfulineuerr((u+/opt/alt/python33/lib64/python3.3/pstats.pyudo_readcs uProfileBrowser.do_readcCs*tdd|jƒtdd|jƒdS(Nu+Read in profile data from a specified file.ufileu*Without argument, reload the current file.(uprintustream(uself((u+/opt/alt/python33/lib64/python3.3/pstats.pyu help_readtsuProfileBrowser.help_readcCs0|jr|jjƒntdd|jƒdS(NuNo statistics object is loaded.ufilei(ustatsu reverse_orderuprintustream(uselfuline((u+/opt/alt/python33/lib64/python3.3/pstats.pyu do_reversexs uProfileBrowser.do_reversecCstdd|jƒdS(Nu/Reverse the sort order of the profiling report.ufile(uprintustream(uself((u+/opt/alt/python33/lib64/python3.3/pstats.pyu help_reverse~suProfileBrowser.help_reversecsË|js tdd|jƒdS|jjƒ‰|rst‡fdd†|jƒDƒƒrs|jj|jƒŒnTtdd|jƒx>tjj ƒD]-\}}td||dfd|jƒq–WdS( NuNo statistics object is loaded.ufilec3s|]}|ˆkVqdS(N((u.0ux(uabbrevs(u+/opt/alt/python33/lib64/python3.3/pstats.pyu †su)ProfileBrowser.do_sort..u/Valid sort keys (unique prefixes are accepted):u%s -- %sii( ustatsuprintustreamuget_sort_arg_defsuallusplitu sort_statsuStatsusort_arg_dict_defaultuitems(uselfulineukeyuvalue((uabbrevsu+/opt/alt/python33/lib64/python3.3/pstats.pyudo_sorts +%uProfileBrowser.do_sortcCs*tdd|jƒtdd|jƒdS(Nu.Sort profile data according to specified keys.ufileu3(Typing `sort' without arguments lists valid keys.)(uprintustream(uself((u+/opt/alt/python33/lib64/python3.3/pstats.pyu help_sortsuProfileBrowser.help_sortcs‡fdd†tjDƒS(Ncs%g|]}|jˆƒr|‘qS((u startswith(u.0ua(utext(u+/opt/alt/python33/lib64/python3.3/pstats.pyu ‘s u0ProfileBrowser.complete_sort..(uStatsusort_arg_dict_default(uselfutextuargs((utextu+/opt/alt/python33/lib64/python3.3/pstats.pyu complete_sortsuProfileBrowser.complete_sortcCs|jd|ƒS(Nu print_stats(ugeneric(uselfuline((u+/opt/alt/python33/lib64/python3.3/pstats.pyudo_stats“suProfileBrowser.do_statscCs!tdd|jƒ|jƒdS(Nu.Print statistics from the current stat object.ufile(uprintustreamu generic_help(uself((u+/opt/alt/python33/lib64/python3.3/pstats.pyu help_stats•suProfileBrowser.help_statscCs0|jr|jjƒntdd|jƒdS(NuNo statistics object is loaded.ufile(ustatsu strip_dirsuprintustream(uselfuline((u+/opt/alt/python33/lib64/python3.3/pstats.pyudo_strip™s uProfileBrowser.do_stripcCstdd|jƒdS(Nu<Strip leading path information from filenames in the report.ufile(uprintustream(uself((u+/opt/alt/python33/lib64/python3.3/pstats.pyu help_stripžsuProfileBrowser.help_stripcCstdd|jƒdS(NuShow help for a given command.ufile(uprintustream(uself((u+/opt/alt/python33/lib64/python3.3/pstats.pyu help_helpĄsuProfileBrowser.help_helpcCs|r |SdS(N(uNone(uselfustopuline((u+/opt/alt/python33/lib64/python3.3/pstats.pyupostcmd¤suProfileBrowser.postcmdN(u__name__u __module__u __qualname__uNoneu__init__ugenericu generic_helpudo_adduhelp_addu do_calleesu help_calleesu do_callersu help_callersudo_EOFuhelp_EOFudo_quitu help_quitudo_readu help_readu do_reverseu help_reverseudo_sortu help_sortu complete_sortudo_statsu help_statsudo_stripu help_stripu help_helpupostcmd(u __locals__((u+/opt/alt/python33/lib64/python3.3/pstats.pyuProfileBrowsers4                       uProfileBrowseriiu*Welcome to the profile statistics browser.ufileuGoodbye.(#u__doc__usysuosutimeumarshalureu functoolsu cmp_to_keyu__all__uStatsu TupleCompufunc_strip_pathufunc_get_function_nameufunc_std_stringuadd_func_statsu add_callersu count_callsuf8u__name__ucmdureadlineu ImportErroruCmduProfileBrowserulenuargvu initprofileuNoneubrowseruprofileudo_adduprintustreamucmdloopuKeyboardInterrupt(((u+/opt/alt/python33/lib64/python3.3/pstats.pyusH      ˙˜         