AlkantarClanX12

Your IP : 18.117.232.215


Current Path : /proc/self/root/opt/alt/python35/lib64/python3.5/__pycache__/
Upload File :
Current File : //proc/self/root/opt/alt/python35/lib64/python3.5/__pycache__/pstats.cpython-35.opt-1.pyc



��Yf�g�@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�YnXdS)z3Class for printing reports on profiled python code.�N)�
cmp_to_key�Statsc@sieZdZdZdddd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	ddOddSddWdd[dd^ddadddddgd djd#dod%dsd(dvd+dzd.d~iZ
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 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�)�sys�stdoutr�len�init�add)�selfr�args�arg�r�+/opt/alt/python35/lib64/python3.5/pstats.py�__init__As	

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	Ks"									

'z
Stats.initcCs�|dkri|_dSt|t�r�t|d��}tj|�|_WdQRXy-tj|�}tj	|j
�d|}WnYnX|g|_n.t|d�r�|j
�|j|_i|_|js�td|j|f��dS)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|krt|jj|�tt|��|j	krtt|��|_	qWdS)N�jprofiler�profiler)r2rr3)
r�itemsrrrrr
r�func_std_stringr)r�func�cc�nc�tt�ct�callersrrrr ts+zStats.get_top_level_statscGsF|s
|Sx5t|�D]'}t|�t|�krAt|�}|j|j7_|j|j7_|j|j7_|j|j7_x!|jD]}|jj|�q�W|j	|j	kr�|j	|_	d|_
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
Cs0t|d��}tj|j|�WdQRXdS)z:Write the profile data to a file we know how to load back.�wbN)r'r(�dumpr)r�filenamer1rrr�
dump_stats�szStats.dump_stats�callsr�
call countZncallsZcumtime��cumulative time�
cumulativer��	file namerC�line��line number�module�name��
function nameZnfl�name/file/lineZpcallsr�primitive call count�stdname��
standard namer,��
internal timeZtottimecCs�|js�i|_}i}xh|jj�D]W\}}|}xB|r�|sNP||kred||<P|||<|dd�}qAWq,Wx|D]
}||=q�W|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_defscGsz|sd|_|St|�dkrat|dt�raddddddddi|dg}|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�q[W|S)
NrrrUrEr,rXrIrz, �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�|S)N)r�reverse)rrrr�
reverse_order�s	
zStats.reverse_ordercCs[|j}i|_}d}x�|j�D]�\}\}}}}}	t|�}
tt|
��|krztt|
��}i}x*|	j�D]\}}
|
|t|�<q�W|
|kr�t||
|||||f�||
<q)|||||f||
<q)W|j}t�|_}x!|D]}|jt|��qW||_	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]r\}\}}}}}||kr[i||<x>|j�D]0\}}	||kr�i||<|	|||<qhWq*WdS)N)rrr4)
rrr6r7r8r9r:r;rkrlrrr�calc_calleess	
+

zStats.calc_calleesc
Csx|}t|t�r�ytj|�}Wn-tjk
rW|d|7}||fSYnXg}x�|D](}|jt|��re|j|�qeWn�t|�}t|t	�r�d|ko�dknr�t
||d�}|d|�}nAt|t
�r3d|ko|knr3|}|d|�}t|�t|�krn|dt|�t|�|f7}||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}x8|D]0}tt
|��|kr�tt
|��}q�W|d|fS)Nz   Ordered by: �
z!   Random listing order was used
rrrX)rrrartr�keysrwrr"rr5)rZsel_list�widthZ	stat_listruZ	selectionrvr6rrr�get_print_list2s$		


zStats.get_print_listcGs[x$|jD]}t|d|j�q
W|jr@td|j�d}x-|jD]"}t|t|�d|j�qPWt||jdddd|j�|j|jkr�td|jddd|j�td|jd|j�td|j�|j|�\}}|rW|j	�x|D]}|j
|�q Wtd|j�td|j�|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_statsJs(	 " 

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

zStats.print_calleesc
Gs�|j|�\}}|r�|j|d�x@|D]8}|j|\}}}}}	|j|||	d�q2Wtd|j�td|j�|S)Nzwas called by...z<-r)r{r�rr�r"r)
rr�rzrtr6r7r8r9r:r;rrr�
print_callersps
zStats.print_callersc
Cs�tdj|�|d|j�d}xT|jj�D]C\}}}}}|r6tt|j���}	t|	t�}Pq6W|r�td|dd|j�dS)Nz	Function rFr|z    ncalls  tottime  cumtime)	r"�ljustrr�values�next�iterr%rf)
r�	name_sizeZcolumn_titleZ	subheaderr7r8r9r:r;�valuerrrr�{s %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  %srVrXrz	%s(%r) %srG)r"r5r�r�sortedryr%rf�rjustr�f8r)rr��sourceZ	call_dictZarrowZclistr�r6rPr�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|�}||krH|dt|�}t|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�rFr�rr�r�)r�rFr�rGr�r�)r�rHr�rGr�r�)r�rH�rJr�r�)r�rK�rJr�r�)r�rK�rMr�r�)r�rN�rJr�r�)r�rK�rQr�r�)r�rR�rQr�rJr�rMr�r�r�r�)r�rSr�rr�r�)r�rT�rVr�r�)r�rWr�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 sF

 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�index�	direction�l�rrrrre�s

zTupleComp.compareN)r�r�r�r�rrerrrrrd�srdcCs(|\}}}tjj|�||fS)N)r*�path�basename)�	func_namerCrLrPrrrrj�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�rPrrrr5�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;r8rErrr�count_callssr�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�ProfileBrowserNcCsKtjj|�d|_d|_tj|_|dk	rG|j|�dS)Nz% )	�cmd�Cmdr�promptrrrr�do_read)r�profilerrrrs		zProfileBrowser.__init__cCs�|j�}g}x�|D]�}y|jt|��wWntk
rMYnXyNt|�}|dksu|dkr�tdd|j�w|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�fnrLrZ	processedZtermZfracrrr�generic"s,



	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_help:szProfileBrowser.generic_helpcCs||jrey|jj|�Wqxtk
ra}z"td||fd|j�WYdd}~XqxXntdd|j�dS)Nz$Failed to load statistics for %s: %srzNo statistics object is loaded.r)rr
�IOErrorr"r)rrL�errr�do_addBs	3zProfileBrowser.do_addcCstdd|j�dS)Nz>Add profile info from given file to current statistics object.r)r"r)rrrr�help_addKszProfileBrowser.help_addcCs|jd|�S)Nr�)r�)rrLrrr�
do_calleesNszProfileBrowser.do_calleescCs!tdd|j�|j�dS)Nz6Print callees statistics from the current stat object.r)r"rr�)rrrr�help_calleesPszProfileBrowser.help_calleescCs|jd|�S)Nr�)r�)rrLrrr�
do_callersTszProfileBrowser.do_callerscCs!tdd|j�|j�dS)Nz6Print callers statistics from the current stat object.r)r"rr�)rrrr�help_callersVszProfileBrowser.help_callerscCstdd|j�dS)Nrrr)r"r)rrLrrr�do_EOFZszProfileBrowser.do_EOFcCstdd|j�dS)NzLeave the profile brower.r)r"r)rrrr�help_EOF]szProfileBrowser.help_EOFcCsdS)Nrr)rrLrrr�do_quit`szProfileBrowser.do_quitcCstdd|j�dS)NzLeave the profile brower.r)r"r)rrrr�	help_quitbszProfileBrowser.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�)rrL�errrrrr�es 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_readvszProfileBrowser.help_readcCs0|jr|jj�ntdd|j�dS)NzNo statistics object is loaded.rr)rrir"r)rrLrrr�
do_reversezs	zProfileBrowser.do_reversecCstdd|j�dS)Nz/Reverse the sort order of the profiling report.r)r"r)rrrr�help_reverse�szProfileBrowser.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)rrLr_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�)rrLrrr�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)rrLrrr�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�stoprLrrr�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	��
�