Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/
Upload File :
Current File : //usr/lib/python2.7/pstats.pyc


|_c@sdZddlZddlZddlZddlZddlZddlmZdgZdfdYZ	dfdYZ
dZd	Zd
Z
dZdZd
ZdZedkrddlZyddlZWnek
rnXdejfdYZddlZeejdkrFejdZneZy4eeZejdIJejejdIJWnek
rnXndS(s3Class for printing reports on profiled python code.iN(t
cmp_to_keytStatscBs eZdZdZdZdZdZdZdZi
d3d
6d6d
6d9d6d<d6d?d6dBd6dCdDdEfdfd6dHd6dKd6dNd!6Z	d"Z
d#Zd$Zd%Z
d&Zd'Zd(Zd)Zd*Zd+Zd,Zd-d.Zd/Zd0ZRS(Os<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)
    cOstj|_d|kr/|d|_|d=n|r|j}|jdjg|D]}d|||f^qX}td|nt|sd}n|d}|d}|j	||j
|dS(Ntstreams, s%s=%ssunrecognized keyword args: %sii(tsyststdoutRtkeystsorttjoint
ValueErrortlentNonetinittadd(tselftargstkwdsRtktextrastarg((s/usr/lib/python2.7/pstats.pyt__init__>s


0	


cCsd|_g|_d|_d|_d|_d|_d|_i|_i|_	i|_
|j|d}z|jd}Wd|r|j
dI|jr|j
|jdIn|j
JnXdS(NiisInvalid timing datai(R
tall_calleestfilestfcn_listttotal_ttttotal_callst
prim_callstmax_name_lent	top_leveltstatst
sort_arg_dictt
load_statstget_top_level_statsR(R
Rttrouble((s/usr/lib/python2.7/pstats.pyRTs(										



	cCs|si|_nt|trt|d}tj||_|jy-tj|}t	j
|jd|}WnnX|g|_n1t
|dr|j|j|_i|_n|jstd|j|fndS(Ntrbs    tcreate_statss1Cannot create or construct a %r object from '%r''(Rt
isinstancet
basestringtopentmarshaltloadtclosetoststatttimetctimetst_mtimeRthasattrR"t	TypeErrort	__class__(R
Rtft
file_stats((s/usr/lib/python2.7/pstats.pyRjs(

	cCsx|jjD]\}\}}}}}|j|7_|j|7_|j|7_d|krtd|j|<ntt||j	krtt||_	qqWdS(Ntjprofileitprofiler(R3iR4(
RtitemsRRRR
RR	tfunc_std_stringR(R
tfunctcctncttttcttcallers((s/usr/lib/python2.7/pstats.pyRs+cGst|s
|St|dkr0|j|dn|d}t|t|ksd|j|jkrst|}n|j|j7_|j|j7_|j|j7_|j|j7_x|j	D]}d|j	|<qW|j|jkr|j|_nd|_xg|j
jD]V\}}||j
krA|j
|}nddddif}t|||j
|<qW|S(Nii(R	RttypeR0RRRRRRR
RRRt	iteritemstadd_func_stats(R
targ_listtotherR7R*t
old_func_stat((s/usr/lib/python2.7/pstats.pyRs,
*	cCs8t|d}ztj|j|Wd|jXdS(s:Write the profile data to a file we know how to load back.twbN(tfileR&tdumpRR((R
tfilenameR1((s/usr/lib/python2.7/pstats.pyt
dump_statssiis
call counttcallsiscumulative timet
cumulativeis	file nameRDisline numbertlinetmoduleis
function nametnamesname/file/linetnflitpcallsis
standard nametstdnameis
internal timeR+cCs|jsi|_}i}xh|jjD]W\}}|}xB|r|sQPn||krkd||<Pn|||<|d }qAWq,Wx|D]
}||=qWn|jS(s)Expand all abbreviations that are unique.ii(Rtsort_arg_dict_defaultR>(R
tdicttbad_listtwordttuptfragment((s/usr/lib/python2.7/pstats.pytget_sort_arg_defss 	
	


cGs|sd|_|St|dkrnt|dttfrnidd6dd6dd6dd6|dg}n|j}d}d	|_d	}xA|D]9}|||d}|j|||d7_d
}qWg}xY|jjD]H\}\}}	}
}}|j	||	|
|f|t
||fqW|jdtt
|jg|_}
x|D]}|
j	|dqhW|S(
NiiROiRHR+RIits, tkey((RR	R#tinttlongRVt	sort_typeRR>tappendR6RRt	TupleComptcompare(R
tfieldt
sort_arg_defst
sort_tuplet	connectorRSt
stats_listR7R8R9R:R;R<Rttuple((s/usr/lib/python2.7/pstats.pyt
sort_statss2	+
	

+

cCs|jr|jjn|S(N(Rtreverse(R
((s/usr/lib/python2.7/pstats.pyt
reverse_orders	cCsX|j}i|_}d}x|jD]\}\}}}}}	t|}
tt|
|kr}tt|
}ni}x*|	jD]\}}
|
|t|<qW|
|krt||
|||||f||
<q)|||||f||
<q)W|j}i|_}x|D]}d|t|<qW||_d|_	d|_
|S(Ni(RR>tfunc_strip_pathR	R6R?RR
RRR(R
toldstatstnewstatsRR7R8R9R:R;R<tnewfunct
newcallerstfunc2tcallertold_toptnew_top((s/usr/lib/python2.7/pstats.pyt
strip_dirss.	
(	

			c
Cs|jr
dSi|_}x|jjD]x\}\}}}}}||kr^i||<nxA|jD]3\}}	||kri||<n|	|||<qkWq*WdS(N(RRR>(
R
RR7R8R9R:R;R<RmRn((s/usr/lib/python2.7/pstats.pytcalc_calleess	
+

c	Csw|}t|trytj|}Wn)tjk
rS|d|7}||fSXg}x|D]+}|jt|ra|j|qaqaWnt|}t|t	rd|kodknrt
||d}|| }nDt|t
tfr/d|ko|knr/|}|| }nt|t|krm|dt|t||f7}n||fS(Ns#   <Invalid regular expression %r>
gg?g?is6   List reduced from %r to %r due to restriction <%r>
(R#R$tretcompileterrortsearchR6R\R	tfloatRYRZ(R
tseltlisttmsgtnew_listtrexR7tcount((s/usr/lib/python2.7/pstats.pyteval_print_amount!s,
+
1
 cCs|j}|jr0|j}d|jd}n|jj}d}x)|D]!}|j|||\}}qLWt|}|sd|fS|j|IJ|t|jkrd}x>|D]3}tt||krtt|}qqWn|d|fS(Ns   Ordered by: s
s!   Random listing order was used
ii(	RRR[RRR~R	RR6(R
tsel_listtwidtht	stat_listRzt	selectionR}R7((s/usr/lib/python2.7/pstats.pytget_print_list;s$		




cGsx|jD]}|j|IJq
W|jr4|jJnd}x*|jD]}|j|It|IJqDW|j|I|jIdI|j|jkr|jd|jIn|jd|jIJ|jJ|j|\}}|r|jx|D]}|j	|qW|jJ|jJn|S(Nt isfunction callss(%d primitive calls)sin %.3f secondss        (
RRRtfunc_get_function_nameRRRRtprint_titlet
print_line(R
tamountRFtindentR7RRy((s/usr/lib/python2.7/pstats.pytprint_statsSs(	



cGs|j|\}}|r|j|j|dxM|D]E}||jkrn|j|||j|q<|j||iq<W|jJ|jJn|S(Ns	called...(RRrtprint_call_headingRtprint_call_lineR(R
RRRyR7((s/usr/lib/python2.7/pstats.pyt
print_calleesis


c
Gs|j|\}}|r|j|dx@|D]8}|j|\}}}}}	|j|||	dq2W|jJ|jJn|S(Nswas called by...s<-(RRRRR(
R
RRRyR7R8R9R:R;R<((s/usr/lib/python2.7/pstats.pyt
print_callersxs

c
Cs|jdj||IJt}xQ|jjD]@\}}}}}|r0|jj}	t|	t}Pq0q0W|r|jd|dIJndS(Ns	Function Rs    ncalls  tottime  cumtime(RtljusttFalseRt
itervaluestnextR#Rd(
R
t	name_sizetcolumn_titlet	subheaderR8R9R:R;R<tvalue((s/usr/lib/python2.7/pstats.pyRs%s->cCsT|jt|j||I|s1|jJdS|j}|jd}x|D]}t|}||}	t|	tr|	\}
}}}
|
|krd|
|f}n
d|
f}d|jddt|t	|t	|
|f}|d}n.d||	t	|j
|d	f}|d	}|j|||IJd
}qTWdS(NRWs%d/%ds%ds%s %s %s  %siiis	%s(%r) %siR(RR6RRRR#RdtrjustR	tf8R(R
Rtsourcet	call_dicttarrowtclistRR7RLRR9R8R:R;tsubstatst
left_width((s/usr/lib/python2.7/pstats.pyRs, 




$
cCs|jdI|jdIJdS(Ns-   ncalls  tottime  percall  cumtime  percallsfilename:lineno(function)(R(R
((s/usr/lib/python2.7/pstats.pyRs
cCs|j|\}}}}}t|}||krK|dt|}n|j|jdI|jt|I|dkr|jdIn|jtt||I|jt|I|dkr|jdIn|jtt||I|jt|IJdS(Nt/i	iRis        s        (RtstrRRRRwR6(R
R7R8R9R:R;R<tc((s/usr/lib/python2.7/pstats.pyRs(ii((ii(((iis
call count(ii((ii(((iiscumulative time(ii((ii(((iis	file name(ii((ii(((iisline number(ii((ii(((iis	file name(ii((ii(((iis
function name(ii(ii(ii(ii((ii(((iis
call count(ii((ii(((iis
standard name(ii((ii(((iis
internal time(t__name__t
__module__t__doc__RRRRRRGRPRVReRgRqRrR~RRRRRRRR(((s/usr/lib/python2.7/pstats.pyR s@				
		

		 										R]cBs eZdZdZdZRS(sThis 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(tcomp_select_list(R
R((s/usr/lib/python2.7/pstats.pyRscCsSxL|jD]A\}}||}||}||kr;|S||kr
|Sq
WdS(Ni(R(R
tlefttrighttindext	directiontltr((s/usr/lib/python2.7/pstats.pyR^s

(RRRRR^(((s/usr/lib/python2.7/pstats.pyR]s	cCs(|\}}}tjj|||fS(N(R)tpathtbasename(t	func_nameRFRJRL((s/usr/lib/python2.7/pstats.pyRhscCs|dS(Ni((R7((s/usr/lib/python2.7/pstats.pyRscCsZ|d d
krN|d}|jdrG|jdrGd|dd!S|Snd	|SdS(Nit~it<t>s{%s}iis	%s:%d(%s)(Ri(t
startswithtendswith(RRL((s/usr/lib/python2.7/pstats.pyR6s
cCsV|\}}}}}|\}}}	}
}||||||	||
t||fS(s3Add together all the stats for two profile entries.(tadd_callers(ttargetRR8R9R:R;R<tt_cctt_nctt_tttt_ctt	t_callers((s/usr/lib/python2.7/pstats.pyR?scCsi}x$|jD]\}}|||<qWx|jD]\}}||krt|trtgt|||D]}|d|d^qx||<q||c|7<q:|||<q:W|S(s*Combine two caller lists in a single list.ii(R>R#Rdtzip(RRtnew_callersR7Rnti((s/usr/lib/python2.7/pstats.pyRs9cCs+d}x|jD]}||7}qW|S(s@Sum the caller statistics to get total number of calls received.i(R(R<R9RH((s/usr/lib/python2.7/pstats.pytcount_callsscCsd|S(Ns%8.3f((tx((s/usr/lib/python2.7/pstats.pyRst__main__tProfileBrowsercBseZddZdZdZdZdZdZdZ	dZ
dZd	Zd
Z
dZdZd
ZdZdZdZdZdZdZdZdZdZdZdZdZRS(cCsNtjj|d|_d|_tj|_|dk	rJ|j	|ndS(Ns% (
tcmdtCmdRtpromptR
RRRRtdo_read(R
tprofile((s/usr/lib/python2.7/pstats.pyR"s		cCs|j}g}x|D]}y|jt|wWntk
rLnXyKt|}|dkst|dkr|jdIJwn|j|wWntk
rnX|j|qW|jrt|j||n
|jdIJdS(Niis#Fraction argument must be in [0, 1]sNo statistics object is loaded.(tsplitR\RYRRwRRtgetattr(R
tfnRJRt	processedttermtfrac((s/usr/lib/python2.7/pstats.pytgeneric*s,




	
cCsR|jdIJ|jdIJ|jdIJ|jdIJ|jdIJ|jdIJdS(NsArguments may be:s0* An integer maximum number of entries to print.s:* A decimal fractional number between 0 and 1, controllings-  what fraction of selected entries to print.s8* A regular expression; only entries with function namess  that match it are printed.(R(R
((s/usr/lib/python2.7/pstats.pytgeneric_helpBs




cCs-|jr|jj|n
|jdIJdS(NsNo statistics object is loaded.i(RRR(R
RJ((s/usr/lib/python2.7/pstats.pytdo_addJs	
cCs|jdIJdS(Ns>Add profile info from given file to current statistics object.(R(R
((s/usr/lib/python2.7/pstats.pythelp_addPscCs|jd|S(NR(R(R
RJ((s/usr/lib/python2.7/pstats.pyt
do_calleesSscCs|jdIJ|jdS(Ns6Print callees statistics from the current stat object.(RR(R
((s/usr/lib/python2.7/pstats.pythelp_calleesUs
cCs|jd|S(NR(R(R
RJ((s/usr/lib/python2.7/pstats.pyt
do_callersYscCs|jdIJ|jdS(Ns6Print callers statistics from the current stat object.(RR(R
((s/usr/lib/python2.7/pstats.pythelp_callers[s
cCs|jdIJdS(NRWi(R(R
RJ((s/usr/lib/python2.7/pstats.pytdo_EOF_s
cCs|jdIJdS(NsLeave the profile brower.(R(R
((s/usr/lib/python2.7/pstats.pythelp_EOFbscCsdS(Ni((R
RJ((s/usr/lib/python2.7/pstats.pytdo_quitescCs|jdIJdS(NsLeave the profile brower.(R(R
((s/usr/lib/python2.7/pstats.pyt	help_quitgscCs|ryt||_WnUtk
r@}|j|dIJdStk
rp}|j|jjdI|IJdSX|d|_n?t|jdkr|jd }|j	|n
|jdIJdS(Nit:s% iis1No statistics object is current -- cannot reload.i(
RRtIOErrorRt	ExceptionR0RRR	R(R
RJRterr((s/usr/lib/python2.7/pstats.pyRjs

cCs|jdIJ|jdIJdS(Ns+Read in profile data from a specified file.s*Without argument, reload the current file.(R(R
((s/usr/lib/python2.7/pstats.pyt	help_read{s
cCs*|jr|jjn
|jdIJdS(NsNo statistics object is loaded.i(RRgR(R
RJ((s/usr/lib/python2.7/pstats.pyt
do_reverses	
cCs|jdIJdS(Ns/Reverse the sort order of the profiling report.(R(R
((s/usr/lib/python2.7/pstats.pythelp_reversescs|js|jdIJdS|jj|rjtfd|jDrj|jj|jnH|jdIJx8tjjD]'\}}|jd||dfIJqWdS(NsNo statistics object is loaded.c3s|]}|kVqdS(N((t.0R(tabbrevs(s/usr/lib/python2.7/pstats.pys	<genexpr>ss/Valid sort keys (unique prefixes are accepted):s%s -- %sii(	RRRVtallRReRRPR>(R
RJRXR((Rs/usr/lib/python2.7/pstats.pytdo_sorts	
(
cCs|jdIJ|jdIJdS(Ns.Sort profile data according to specified keys.s3(Typing `sort' without arguments lists valid keys.)(R(R
((s/usr/lib/python2.7/pstats.pyt	help_sorts
cGs)gtjD]}|j|r
|^q
S(N(RRPR(R
ttextRta((s/usr/lib/python2.7/pstats.pyt
complete_sortscCs|jd|S(NR(R(R
RJ((s/usr/lib/python2.7/pstats.pytdo_statsscCs|jdIJ|jdS(Ns.Print statistics from the current stat object.(RR(R
((s/usr/lib/python2.7/pstats.pyt
help_statss
cCs*|jr|jjn
|jdIJdS(NsNo statistics object is loaded.(RRqR(R
RJ((s/usr/lib/python2.7/pstats.pytdo_strips	cCs|jdIJdS(Ns<Strip leading path information from filenames in the report.(R(R
((s/usr/lib/python2.7/pstats.pyt
help_stripscCs|jdIJdS(NsShow help for a given command.(R(R
((s/usr/lib/python2.7/pstats.pyt	help_helpscCs|r
|SdS(N(R
(R
tstopRJ((s/usr/lib/python2.7/pstats.pytpostcmdsN(RRR
RRRRRRRRRRRRRRRRRRRRRRRRRR(((s/usr/lib/python2.7/pstats.pyR!s4																								is*Welcome to the profile statistics browser.sGoodbye.( RRR)R+R&Rst	functoolsRt__all__RR]RhRR6R?RRRRRtreadlinetImportErrorRRR	targvtinitprofileR
tbrowserRtcmdlooptKeyboardInterrupt(((s/usr/lib/python2.7/pstats.pyt<module>sF