Your IP : 18.117.184.125


Current Path : /opt/alt/python34/lib64/python3.4/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/__pycache__/pstats.cpython-34.pyc

�
e f�f�@s�dZddlZddlZddlZddlZddlZddlmZdgZGdd�d�Z	Gdd�d�Z
dd	�Zd
d�Zdd
�Z
dd�Zdd�Zdd�Zdd�Zedkr�ddlZyddlZWnek
rYnXGdd�dej�Zeej�dkrPejdZndZykee�Zx(ejdd�D]Zeje�qyWeddej�ej �eddej�Wne!k
r�YnXndS)z3Class for printing reports on profiled python code.�N)�
cmp_to_key�Statsc@sweZdZdZdddd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	idOd6dSd6dWd6d[d6d^d6dad6ddd6dgd6djd"6dod$6dsd'6dvd*6dzd-6d~d.6Z
d/d0�Zd1d2�Zd3d4�Z
d5d6�Zd7d8�Zd9d:�Zd;d<�Zd=d>�Zd?d@�ZdAdB�ZdCdD�ZdEdFdG�ZdHdI�ZdJdK�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).  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�)�sys�stdoutr�len�init�add)�selfr�args�arg�r�+/opt/alt/python34/lib64/python3.4/pstats.py�__init__>s	

zStats.__init__cCs�d|_g|_d|_d|_d|_d|_d|_t�|_i|_	i|_
|j|�y|j�WnBt
k
r�td|jr�|jdndd|j��YnXdS)NrzInvalid timing data %sr��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)rr
rrrr	Hs"									

'z
Stats.initcCs�|dkri|_dSt|t�r�t|d��}tj|�|_WdQXy-tj|�}tj	|j
�d|}WnYnX|g|_n1t|d�r�|j
�|j|_i|_n|js�td|j|f��ndS)N�rbz    �create_statsz.Cannot create or construct a %r object from %r)r�
isinstance�str�open�marshal�load�os�stat�timeZctime�st_mtimer�hasattrr$�	TypeError�	__class__)rr
�fZ
file_statsrrrr[s(	
	zStats.load_statscCs�x�|jj�D]�\}\}}}}}|j|7_|j|7_|j|7_d|krw|jj|�ntt|��|j	krtt|��|_	qqWdS)N�jprofiler�profiler)r2rr3)
r�itemsrrrrr
r�func_std_stringr)r�func�cc�nc�tt�ct�callersrrrr qs+zStats.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|jj�D]V\}}||jkr|j|}nddddif}t
||�|j|<q�WqW|S)Nr)�reversed�typerrrrrrr
rrrr4�add_func_stats)r�arg_list�itemr6r+Z
old_func_statrrrr
{s(	z	Stats.addc
Cs/t|d��}tj|j|�WdQXdS)z:Write the profile data to a file we know how to load back.�wbN)r'r(�dumpr)r�filenamer1rrr�
dump_stats�szStats.dump_statsr�
call count�callsZncalls��cumulative timeZcumtime�
cumulative��	file namerrC��line number�line�module��
function name�name�name/file/lineZnflr�primitive call countZpcalls��
standard name�stdname��
internal timer,ZtottimecCs�|js�i|_}i}xn|jj�D]]\}}|}xH|r�|sQPn||krkd||<Pn|||<|dd�}qAWq,Wx|D]
}||=q�Wn|jS)z)Expand all abbreviations that are unique.rNrr)r�sort_arg_dict_defaultr4)r�dictZbad_list�word�tupZfragmentrrr�get_sort_arg_defs�s 	
	


zStats.get_sort_arg_defscGs�|sd|_|St|�dkrht|dt�rhidd6dd6dd6dd6|dg}n|j�}f}d|_d}xA|D]9}|||d}|j|||d7_d	}q�Wg}xY|jj�D]H\}\}}	}
}}|j||	|
|f|t	|�|f�q�W|j
d
tt|�j
��g|_}
x|D]}|
j|d�qbW|S)
NrrrWrFr,rIrXrz, �keyrr)rrr%�intr^�	sort_typerr4�appendr5�sortr�	TupleComp�compare)rZfieldZ
sort_arg_defsZ
sort_tupleZ	connectorr\Z
stats_listr6r7r8r9r:r;r�tuplerrr�
sort_stats�s2	%
	

+

zStats.sort_statscCs|jr|jj�n|S)N)r�reverse)rrrr�
reverse_order�s	zStats.reverse_ordercCs^|j}i|_}d}x�|j�D]�\}\}}}}}	t|�}
tt|
��|kr}tt|
��}ni}x*|	j�D]\}}
|
|t|�<q�W|
|kr�t||
|||||f�||
<q)|||||f||
<q)W|j}t�|_}x!|D]}|jt|��q"W||_	d|_
d|_|S)Nr)rr4�func_strip_pathrr5r>rrr
rrr)rZoldstatsZnewstatsrr6r7r8r9r:r;ZnewfuncZ
newcallers�func2�callerZold_topZnew_toprrr�
strip_dirs�s.	
(	
			zStats.strip_dirsc
Cs�|jr
dSi|_}x�|jj�D]x\}\}}}}}||kr^i||<nxA|j�D]3\}}	||kr�i||<n|	|||<qkWq*WdS)N)rrr4)
rrr6r7r8r9r:r;rkrlrrr�calc_calleess	
+

zStats.calc_calleesc
Cs�|}t|t�r�ytj|�}Wn-tjk
rW|d|7}||fSYnXg}x�|D]+}|jt|��re|j|�qeqeWn�t|�}t|t	�r�d|ko�dknr�t
||d�}|d|�}nDt|t
�r9d|ko|knr9|}|d|�}nt|�t|�krw|dt|�t|�|f7}n||fS)Nz#   <Invalid regular expression %r>
gg�?g�?rz6   List reduced from %r to %r due to restriction <%r>
)r%r&�re�compile�error�searchr5rbr�floatr`)rZsel�list�msgZnew_listZrexr6�countrrr�eval_print_amounts,
++ zStats.eval_print_amountcCs|j}|jr9|jdd�}d|jd}nt|jj��}d}x)|D]!}|j|||�\}}q[Wt|�}|s�d|fSt|d|j	�|t|j�krd}x>|D]3}tt
|��|kr�tt
|��}q�q�Wn|d|fS)Nz   Ordered by: �
z!   Random listing order was used
rrrX)rrrartr�keysrwrr"rr5)rZsel_list�widthZ	stat_listruZ	selectionrvr6rrr�get_print_list/s$		


zStats.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)	Nr� �zfunction calls�endz(%d primitive calls)zin %.3f secondsz        )rr"rr�func_get_function_namerrrr{�print_title�
print_line)r�amountrC�indentr6rzrtrrr�print_statsGs(	 "#

zStats.print_statscGs�|j|�\}}|r�|j�|j|d�xM|D]E}||jkrn|j|||j|�q<|j||i�q<Wtd|j�td|j�n|S)Nz	called...r)r{rn�print_call_headingr�print_call_liner"r)rr�rzrtr6rrr�
print_callees^s

zStats.print_calleesc
Gs�|j|�\}}|r�|j|d�x@|D]8}|j|\}}}}}	|j|||	d�q2Wtd|j�td|j�n|S)Nzwas called by...z<-r)r{r�rr�r"r)
rr�rzrtr6r7r8r9r:r;rrr�
print_callersms
zStats.print_callersc
Cs�tdj|�|d|j�d}xW|jj�D]F\}}}}}|r6tt|j���}	t|	t�}Pq6q6W|r�td|dd|j�ndS)Nz	Function rFr|z    ncalls  tottime  cumtime)	r"�ljustrr�values�next�iterr%rf)
r�	name_sizeZcolumn_titleZ	subheaderr7r8r9r:r;�valuerrrr�xs %zStats.print_call_headingz->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)
Nr~r|rrz%d/%dz%dz%s %s %s  %srUrXrz	%s(%r) %srG)r"r5r�r�sortedryr%rf�rjustr�f8r)rr��sourceZ	call_dictZarrowZclistr�r6rRr�r8r7r9r:ZsubstatsZ
left_widthrrrr��s*,



$
zStats.print_call_linecCs0tdddd|j�tdd|j�dS)Nz-   ncalls  tottime  percall  cumtime  percallr~r|rzfilename:lineno(function))r"r)rrrrr��szStats.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)
N�/�	r~r|rrr}z        z        )rr&r"r�rr�r5)rr6r7r8r9r:r;�crrrr��s"##zStats.print_liner�rr�r�)r�rEr�rr�r�)r�rEr�rGr�r�)r�rHr�rGr�r�)r�rH�rJr�r�)r�rK�rJr�r�)r�rK�rLr�r�)r�rM�rJr�r�)r�rK�rPr�r�)r�rQ�rPr�rJr�rLr�r�r�r�)r�rSr�rr�r�)r�rT�rUr�r�)r�rVr�rXr�r�)r�rYr�rXr�r�)r�rY)�__name__�
__module__�__qualname__�__doc__rr	rr r
rDrZr^rgrirmrnrwr{r�r�r�r�r�r�r�rrrrr sH


 c@s.eZdZdZdd�Zdd�ZdS)rda�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)rr�rrrr�szTupleComp.__init__cCsSxL|jD]A\}}||}||}||kr;|S||kr
|Sq
WdS)Nr)r�)r�left�right�indexZ	direction�l�rrrrre�s

zTupleComp.compareN)r�r�r�r�rrerrrrrd�srdcCs(|\}}}tjj|�||fS)N)r*�path�basename)�	func_namerCrNrRrrrrj�srjcCs|dS)NrXr)r6rrrr�srcCsc|dd�d	krW|d}|jd�rP|jd�rPd|dd
�S|Snd|SdS)NrX�~r�<�>z{%s}rz	%s:%d(%s))r�rr)�
startswith�endswith)r�rRrrrr5�s
r5cCsV|\}}}}}|\}}}	}
}||||||	||
t||�fS)z3Add together all the stats for two profile entries.)�add_callers)�targetr�r7r8r9r:r;Zt_ccZt_ncZt_ttZt_ctZ	t_callersrrrr>�sr>cCs�i}x$|j�D]\}}|||<qWx}|j�D]o\}}||kr�t|t�r�tdd�t|||�D��||<q�|||7<q:|||<q:W|S)z*Combine two caller lists in a single list.cSs"g|]}|d|d�qS)rrr)�.0�irrr�
<listcomp>�s	zadd_callers.<locals>.<listcomp>)r4r%rf�zip)r�r�Znew_callersr6rlrrrr��s!r�cCs+d}x|j�D]}||7}qW|S)z@Sum the caller statistics to get total number of calls received.r)r�)r;r8rFrrr�count_calls�sr�cCsd|S)Nz%8.3fr)�xrrrr�sr��__main__c@sKeZdZddd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�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)6�ProfileBrowserNcCsNtjj|�d|_d|_tj|_|dk	rJ|j|�ndS)Nz% )	�cmd�Cmdr�promptrrrr�do_read)r�profilerrrrs		zProfileBrowser.__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)Nrrz#Fraction argument must be in [0, 1]rzNo statistics object is loaded.)	�splitrbr`�
ValueErrorrsr"rr�getattr)r�fnrNrZ	processedZtermZfracrrr�generics,



	zProfileBrowser.genericcCsvtdd|j�tdd|j�tdd|j�tdd|j�tdd|j�tdd|j�dS)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)rrrr�generic_help7szProfileBrowser.generic_helpcCs3|jr|jj|�ntdd|j�dS)NzNo statistics object is loaded.rr)rr
r"r)rrNrrr�do_add?s	zProfileBrowser.do_addcCstdd|j�dS)Nz>Add profile info from given file to current statistics object.r)r"r)rrrr�help_addEszProfileBrowser.help_addcCs|jd|�S)Nr�)r�)rrNrrr�
do_calleesHszProfileBrowser.do_calleescCs!tdd|j�|j�dS)Nz6Print callees statistics from the current stat object.r)r"rr�)rrrr�help_calleesJszProfileBrowser.help_calleescCs|jd|�S)Nr�)r�)rrNrrr�
do_callersNszProfileBrowser.do_callerscCs!tdd|j�|j�dS)Nz6Print callers statistics from the current stat object.r)r"rr�)rrrr�help_callersPszProfileBrowser.help_callerscCstdd|j�dS)Nrrr)r"r)rrNrrr�do_EOFTszProfileBrowser.do_EOFcCstdd|j�dS)NzLeave the profile brower.r)r"r)rrrr�help_EOFWszProfileBrowser.help_EOFcCsdS)Nrr)rrNrrr�do_quitZszProfileBrowser.do_quitcCstdd|j�dS)NzLeave the profile brower.r)r"r)rrrr�	help_quit\szProfileBrowser.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)	Nrr�:z% rXz1No statistics object is current -- cannot reload.r���)rr�OSErrorr"rrr!r0r�r�rr�)rrN�errrrrr�_s zProfileBrowser.do_readcCs*tdd|j�tdd|j�dS)Nz+Read in profile data from a specified file.rz*Without argument, reload the current file.)r"r)rrrr�	help_readpszProfileBrowser.help_readcCs0|jr|jj�ntdd|j�dS)NzNo statistics object is loaded.rr)rrir"r)rrNrrr�
do_reversets	zProfileBrowser.do_reversecCstdd|j�dS)Nz/Reverse the sort order of the profiling report.r)r"r)rrrr�help_reversezszProfileBrowser.help_reversecs�|js tdd|j�dS|jj��|rst�fdd�|j�D��rs|jj|j��nTtdd|j�x>tjj	�D]-\}}td||dfd|j�q�WdS)	NzNo statistics object is loaded.rc3s|]}|�kVqdS)Nr)r�r�)�abbrevsrr�	<genexpr>�sz)ProfileBrowser.do_sort.<locals>.<genexpr>z/Valid sort keys (unique prefixes are accepted):z%s -- %srr)
rr"rr^�allr�rgrrZr4)rrNr_r�r)r�r�do_sort}s	+%zProfileBrowser.do_sortcCs*tdd|j�tdd|j�dS)Nz.Sort profile data according to specified keys.rz3(Typing `sort' without arguments lists valid keys.))r"r)rrrr�	help_sort�szProfileBrowser.help_sortcs�fdd�tjD�S)Ncs%g|]}|j��r|�qSr)r�)r��a)�textrrr��s	z0ProfileBrowser.complete_sort.<locals>.<listcomp>)rrZ)rr�rr)r�r�
complete_sort�szProfileBrowser.complete_sortcCs|jd|�S)Nr�)r�)rrNrrr�do_stats�szProfileBrowser.do_statscCs!tdd|j�|j�dS)Nz.Print statistics from the current stat object.r)r"rr�)rrrr�
help_stats�szProfileBrowser.help_statscCs0|jr|jj�ntdd|j�dS)NzNo statistics object is loaded.r)rrmr"r)rrNrrr�do_strip�s	zProfileBrowser.do_stripcCstdd|j�dS)Nz<Strip leading path information from filenames in the report.r)r"r)rrrr�
help_strip�szProfileBrowser.help_stripcCstdd|j�dS)NzShow help for a given command.r)r"r)rrrr�	help_help�szProfileBrowser.help_helpcCs|r
|SdS)Nr)r�stoprNrrr�postcmd�szProfileBrowser.postcmd)r�r�r�rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr�s4r�rrXz*Welcome to the profile statistics browser.rzGoodbye.)"r�rr*r,r(ro�	functoolsr�__all__rrdrjrr5r>r�r�r�r�r��readline�ImportErrorr�r�r�argvZinitprofileZbrowserr�r�r"rZcmdloop�KeyboardInterruptrrrr�<module>sH	��
�



?>