AlkantarClanX12

Your IP : 18.118.154.237


Current Path : /usr/lib64/python2.7/Tools/scripts/
Upload File :
Current File : //usr/lib64/python2.7/Tools/scripts/analyze_dxp.pyc

�
�fc@s�dZddlZddlZddlZddlZddlZeed�s`ed��nej�Z	ej
�ad�Zd�Z
d�Zd�Zd	�Zd
�Zdd�ZdS(s
Some helper functions to analyze the output of sys.getdxp() (which is
only available if Python was built with -DDYNAMIC_EXECUTION_PROFILE).
These will tell you which opcodes have been executed most frequently
in the current process, and, if Python was also built with -DDXPAIRS,
will tell you which instruction _pairs_ were executed most frequently,
which may help in choosing new instructions.

If Python was built without -DDYNAMIC_EXECUTION_PROFILE, importing
this module will raise a RuntimeError.

If you're running a script you want to profile, a simple way to get
the common pairs is:

$ PYTHONPATH=$PYTHONPATH:<python_srcdir>/Tools/scripts ./python -i -O the_script.py --args
...
> from analyze_dxp import *
> s = render_common_pairs()
> open('/tmp/some_file', 'w').write(s)
i����NtgetdxpsKCan't import analyze_dxp: Python built without -DDYNAMIC_EXECUTION_PROFILE.cCs#t|�dko"t|dt�S(s[Returns True if the Python that produced the argument profile
    was built with -DDXPAIRS.i(tlent
isinstancetlist(tprofile((s1/usr/lib64/python2.7/Tools/scripts/analyze_dxp.pyt	has_pairs(scCs't�tj�tj�aWdQXdS(s<Forgets any execution profile that has been gathered so far.N(t
_profile_locktsysRt_cumulative_profile(((s1/usr/lib64/python2.7/Tools/scripts/analyze_dxp.pyt
reset_profile/s
cCs�t��tj�}t|�r|x�ttt��D]C}x:ttt|��D]"}t||c|||7<qOWq2Wn1x.ttt��D]}t|c||7<q�WWdQXdS(s�Reads sys.getdxp() and merges it into this module's cached copy.

    We need this because sys.getdxp() 0s itself every time it's called.N(RRRRtrangeRR(tnew_profilet
first_insttsecond_insttinst((s1/usr/lib64/python2.7/Tools/scripts/analyze_dxp.pyt
merge_profile7scCs%t�t�tjt�SWdQXdS(s9Returns the cumulative execution profile until this call.N(RRtcopytdeepcopyR(((s1/usr/lib64/python2.7/Tools/scripts/analyze_dxp.pytsnapshot_profileHscCs�t|�r|r|d}n|}gt|�D].\}}|dkr2|tj||f^q2}|jdtjd�dt�|S(s�Returns the most common opcodes in order of descending frequency.

    The result is a list of tuples of the form
      (opcode, opname, # of occurrences)

    i����itkeyitreverse(Rt	enumeratetopcodetopnametsorttoperatort
itemgettertTrue(Rt	inst_listtoptcounttresult((s1/usr/lib64/python2.7/Tools/scripts/analyze_dxp.pytcommon_instructionsOs
(cCs�t|�sgSgt|d �D]Z\}}t|�D]A\}}|dkr7||ftj|tj|f|f^q7q!}|jdtjd�dt�|S(s�Returns the most common opcode pairs in order of descending frequency.

    The result is a list of tuples of the form
      ((1st opcode, 2nd opcode),
       (1st opname, 2nd opname),
       # of occurrences of the pair)

    i����iRiR(RRRRRRRR(Rtop1t
op1profiletop2RR((s1/usr/lib64/python2.7/Tools/scripts/analyze_dxp.pytcommon_pairsas	>cs7�dkrt��n�fd�}dj|��S(s�Renders the most common opcode pairs to a string in order of
    descending frequency.

    The result is a series of lines of the form:
      # of occurrences: ('1st opname', '2nd opname')

    c3s3x,t��D]\}}}d||fVq
WdS(Ns%s: %s
(R$(t_topsR(R(s1/usr/lib64/python2.7/Tools/scripts/analyze_dxp.pytseqstN(tNoneRtjoin(RR'((Rs1/usr/lib64/python2.7/Tools/scripts/analyze_dxp.pytrender_common_pairsus(t__doc__RRRRt	threadingthasattrtRuntimeErrortRLockRRRRR	RRR R$R)R+(((s1/usr/lib64/python2.7/Tools/scripts/analyze_dxp.pyt<module>s