AlkantarClanX12

Your IP : 18.117.105.40


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

�
e fV�@s�dZddlZddlZddlZddlZddlmZdddgZGdd�d�Zdd	d
d�Z	dd	dd�Z
Gdd�d�Zd
d�Ze
dkr�e�ndS)z Class for profiling Python code.�N)�OptionParser�run�runctx�Profilec@sFeZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�_Utilsz�Support class for utility functions which are shared by
    profile.py and cProfile.py modules.
    Not supposed to be used directly.
    cCs
||_dS)N)�profiler)�selfr�r	�,/opt/alt/python34/lib64/python3.4/profile.py�__init__1sz_Utils.__init__cCsQ|j�}z*y|j|�Wntk
r4YnXWd|j|||�XdS)N)rr�
SystemExit�_show)r�	statement�filename�sort�profr	r	r
r4s
	z
_Utils.runcCsW|j�}z0y|j|||�Wntk
r:YnXWd|j|||�XdS)N)rrrr
)rr�globals�localsrrrr	r	r
r=s
	z
_Utils.runctxcCs-|dk	r|j|�n
|j|�dS)N)�
dump_stats�print_stats)rrrrr	r	r
r
Fsz_Utils._showN)�__name__�
__module__�__qualname__�__doc__rrrr
r	r	r	r
r+s
		r�cCstt�j|||�S)aRun statement under profiler optionally saving results in filename

    This function takes a single argument that can be passed to the
    "exec" statement, and an optional file name.  In all cases this
    routine attempts to "exec" its first argument and gather profiling
    statistics from the execution. If no file name is present, then this
    function automatically prints a simple profiling report, sorted by the
    standard name string (file/line/function-name) that is presented in
    each line.
    )rrr)rrrr	r	r
rRscCstt�j|||||�S)z�Run statement under profiler, supplying your own globals and locals,
    optionally saving results in filename.

    statement and filename have the same semantics as profile.run
    )rrr)rrrrrr	r	r
r_sc@szeZdZdZdZdddd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
ied6e
d6e
d6ed6e
d6e
d6Zdd�ZGdd�d�ZGd d!�d!�Zd"d#�Zd$d%�Zd9d'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zdd5d6�Zd7d8�ZdS):raProfiler class.

    self.cur is always a tuple.  Each such tuple corresponds to a stack
    frame that is currently active (self.cur[-2]).  The following are the
    definitions of its members.  We use this external "parallel stack" to
    avoid contaminating the program that we are profiling. (old profiler
    used to write into the frames local dictionary!!) Derived classes
    can change the definition of some entries, as long as they leave
    [-2:] intact (frame and previous tuple).  In case an internal error is
    detected, the -3 element is used as the function name.

    [ 0] = Time that needs to be charged to the parent frame's function.
           It is used so that a function call will not have to access the
           timing data for the parent frame.
    [ 1] = Total time spent in this frame's function, excluding time in
           subfunctions (this latter is tallied in cur[2]).
    [ 2] = Total time spent in subfunctions, excluding time executing the
           frame's function (this latter is tallied in cur[1]).
    [-3] = Name of the function that corresponds to this frame.
    [-2] = Actual frame that we correspond to (used to sync exception handling).
    [-1] = Our parent 6-tuple (corresponds to frame.f_back).

    Timing data for each function is stored as a 5-tuple in the dictionary
    self.timings[].  The index is always the name stored in self.cur[-3].
    The following are the definitions of the members:

    [0] = The number of times this function was called, not counting direct
          or indirect recursion,
    [1] = Number of times this function appears on the stack, minus one
    [2] = Total time spent internal to this function
    [3] = Cumulative time that this function was present on the stack.  In
          non-recursive functions, this is the total execution time from start
          to finish of each invocation of a function, including time spent in
          all subfunctions.
    [4] = A dictionary indicating for each function name, the number of times
          it was called by us.
    rNcCsi|_d|_d|_d|_|dkr<|j}n||_|smtj|_|_|j	|_
n�||_|j�}yt|�}Wn'tk
r�||_|j	|_
YnCX|dkr�|j
|_
n|j|_
|tdd�}||_|j�|_|jd�dS)N��cSs
||��S)Nr	)�timer�sumr	r	r
�get_time_timer�sz(Profile.__init__.<locals>.get_time_timerr)�timings�cur�cmd�c_func_name�bias�timeZprocess_timer�get_time�trace_dispatch_i�
dispatcher�len�	TypeError�trace_dispatch�trace_dispatch_lr�t�
simulate_call)rrr$r-Zlengthrr	r	r
r�s0						
		zProfile.__init__cCs�|j}|�}|d|d|j|j}|dkrM|j|_n|j||||�r�|�}|d|d|_n"|�}|d|d||_dS)Nrr�c_call)rr-r$rr#�dispatch)r�frame�event�argrr-�rr	r	r
r+�s		 		zProfile.trace_dispatchcCsw|j}|�|j|j}|dkr;|j|_n|j||||�rc|�|_n|�||_dS)Nr/)rr-r$rr#r0)rr1r2r3rr-r	r	r
r'�s	zProfile.trace_dispatch_icCs�|j}|�d|j|j}|dkr?|j|_n|j||||�rk|�d|_n|�d||_dS)NgN@r/)rr-r$rr#r0)rr1r2r3rr-r	r	r
�trace_dispatch_mac�s	zProfile.trace_dispatch_maccCsw|j}|�|j|j}|dkr;|j|_n|j||||�rc|�|_n|�||_dS)Nr/)r&r-r$rr#r0)rr1r2r3r&r-r	r	r
r,�s	zProfile.trace_dispatch_lc	Cs`|j\}}}}}}||k	r=|r=|j||�S|||||||f|_dS)Nr)r!�trace_dispatch_return)	rr1r-�rpt�rit�ret�rfn�rframe�rcurr	r	r
�trace_dispatch_exception�s
z Profile.trace_dispatch_exceptioncCs�|jr�|j|jdk	r�|j\}}}}}}t|tj�s�|j|jks�td|||j||jf��|j|d�|jdks�|j|jdks�td|jdf��q�n|j}	|	j|	j	|	j
f}
|dd|
||jf|_|j}|
|krc||
\}}
}}}||
d|||f||
<nddddif||
<dS)	NrzBad callr�r���r?���)r!�f_back�
isinstancer�
fake_frame�AssertionErrorr6�f_code�co_filename�co_firstlineno�co_namer )rr1r-r7r8r9r:r;r<Zfcode�fnr �cc�ns�tt�ct�callersr	r	r
�trace_dispatch_calls&			 zProfile.trace_dispatch_callc
Cs�dd|jf}|dd|||jf|_|j}||kr~||\}}}}}	||d|||	f||<nddddif||<dS)Nrrr)r#r!r )
rr1r-rIr rJrKrLrMrNr	r	r
�trace_dispatch_c_calls	 zProfile.trace_dispatch_c_callcCsU||jdk	r\||jdjksBtd|jdf��|j|jd	d�n|j\}}}}}}||}||}|\}	}
}}}
}|	|
|||||
|f|_|j}||\}}}}}|s||}|d}n||kr&||d||<n
d||<||d||||f||<dS)
Nrz
Bad returnr>rrr?r?r@r?)r!rArDr6r )rr1r-r7r8r9r:r<Zframe_totalZpptZpitZpetZpfn�pframeZpcurr rJrKrLrMrNr	r	r
r6#s$/

#	


!zProfile.trace_dispatch_return�callZ	exception�returnr/Zc_exceptionZc_returncCs+|jdrdS||_|j|�dS)Nr���)r!r"r.)rr"r	r	r
�set_cmdYs
	zProfile.set_cmdc@s(eZdZdd�Zdd�ZdS)zProfile.fake_codecCs(||_||_||_d|_dS)Nr)rF�co_linerHrG)rr�line�namer	r	r
r_s			zProfile.fake_code.__init__cCst|j|j|jf�S)N)�reprrFrVrH)rr	r	r
�__repr__eszProfile.fake_code.__repr__N)rrrrrZr	r	r	r
�	fake_code^sr[c@seZdZdd�ZdS)zProfile.fake_framecCs||_||_dS)N)rErA)r�codeZpriorr	r	r
ris	zProfile.fake_frame.__init__N)rrrrr	r	r	r
rChsrCcCsa|jdd|�}|jr.|jd}nd}|j||�}|jd||d�dS)NZprofilerrrRr?)r[r!rCr0)rrXr\rQr1r	r	r
r.ms	zProfile.simulate_callcCse|j}|�|j}x5|jdrP|jd||jd|�d}qW|�||_dS)NrrSrrrTr?)r&r-r!r0)rr&r-r	r	r
�simulate_cmd_completeys	
zProfile.simulate_cmd_completercCs2ddl}|j|�j�j|�j�dS)Nr)�pstatsZStatsZ
strip_dirsZ
sort_statsr)rrr^r	r	r
r�szProfile.print_statsc
Cs9t|d��$}|j�tj|j|�WdQXdS)N�wb)�open�create_stats�marshal�dump�stats)r�file�fr	r	r
r�s
zProfile.dump_statscCs|j�|j�dS)N)r]�snapshot_stats)rr	r	r
ra�s
zProfile.create_statsc	Cs�i|_x{|jj�D]j\}\}}}}}|j�}d}x|j�D]}||7}qSW|||||f|j|<qWdS)Nr)rdr �items�copy�values)	r�funcrJrKrLrMrNZncZcallcntr	r	r
rg�s	+zProfile.snapshot_statscCs(ddl}|j}|j|||�S)Nr)�__main__�__dict__r)rr"rl�dictr	r	r
r�s	zProfile.runcCsF|j|�tj|j�zt|||�Wdtjd�X|S)N)rU�sys�
setprofiler(�exec)rr"rrr	r	r
r�s
zProfile.runctxcOsI|jt|��tj|j�z|||�SWdtjd�XdS)N)rUrYrorpr()rrk�args�kwr	r	r
�runcall�s
zProfile.runcallcCsU|jtk	rtd��n|j}d|_z|j||�SWd||_XdS)Nz&Subclasses must override .calibrate().r)�	__class__rr*r$�_calibrate_inner)r�m�verboseZ
saved_biasr	r	r
�	calibrate�s		zProfile.calibratecCs�|j}dd�}|dd�}||�|�}||�|�}||}|rjtd|�nt�}	|�}|	jdt�t��|�}||}
|r�td|
�nd}d}xX|	jj�D]G\\}
}}\}}}}}|dkr�||7}||7}q�q�W|rHtd|�td|�n||d
krktd|��n||d|}|r�td|�n|S)NcSs!xt|�D]}d}q
WdS)Nr)�range)�n�i�xr	r	r
�f1�sz$Profile._calibrate_inner.<locals>.f1cSs%xt|�D]}|d�q
WdS)N�d)rz)rwr~r|r	r	r
rf�sz#Profile._calibrate_inner.<locals>.fz elapsed time without profiling =zf(m)zelapsed time with profiling =grfr~z!'CPU seconds' profiler reported =ztotal # calls =rz internal error: total calls = %dg@z+mean stopwatch overhead per profile event =)rfzf1)	r&�printrrrrr rh�
ValueError)rrwrxr&r~rfZt0Zt1Zelapsed_noprofile�pZelapsed_profileZtotal_callsZ
reported_timerrWZfuncnamerJrKrLrMrNZmeanr	r	r
rv�sB	
	
	
			
1

zProfile._calibrate_innerrT)rrrrr$rr+r'r5r,r=rOrPr6r0rUr[rCr.r]rrrargrrrtryrvr	r	r	r
rhs@%'&




1cCsnd}td|�}d|_|jdddddd	d
d�|jdddd
ddd
d�tjdd�s�|j�tjd�n|j�\}}|tjdd�<t|�dkr`|d}tj	j
dtj	j|��t
|d��}t|j�|d�}WdQXi|d6dd6dd6dd6}t||d|j|j�n
|j�|S)Nz?profile.py [-o output_file_path] [-s sort] scriptfile [arg] ...�usageFz-oz	--outfile�dest�outfile�helpzSave stats to <outfile>�defaultz-sz--sortrz?Sort order when printing to stdout, based on pstats.Stats classrrr�rbrq�__file__rlr�__package__�
__cached__rT)rZallow_interspersed_argsZ
add_optionro�argvZprint_usage�exit�
parse_argsr)�path�insert�os�dirnamer`�compile�readrr�r)r��parserZoptionsrrZprogname�fpr\Zglobsr	r	r
�main*s4	




r�rl)rror�r%rbZoptparser�__all__rrrrr�rr	r	r	r
�<module>	s
'
	��"