Your IP : 216.73.216.213


Current Path : /opt/alt/python33/lib64/python3.3/Tools/scripts/__pycache__/
Upload File :
Current File : //opt/alt/python33/lib64/python3.3/Tools/scripts/__pycache__/analyze_dxp.cpython-33.pyc

�
��fWc@s�dZddlZddlZddlZddlZddlZeed�s`ed��nej�Z	ej
�add�Zdd�Z
d	d
�Zdd�Zd
d�Zdd�Zddd�ZdS(u
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)
iNugetdxpuKCan't import analyze_dxp: Python built without -DDYNAMIC_EXECUTION_PROFILE.cCs#t|�dko"t|dt�S(u[Returns True if the Python that produced the argument profile
    was built with -DDXPAIRS.i(ulenu
isinstanceulist(uprofile((u>/opt/alt/python33/lib64/python3.3/Tools/scripts/analyze_dxp.pyu	has_pairs'su	has_pairscCs't�tj�tj�aWdQXdS(u<Forgets any execution profile that has been gathered so far.N(u
_profile_lockusysugetdxpu_cumulative_profile(((u>/opt/alt/python33/lib64/python3.3/Tools/scripts/analyze_dxp.pyu
reset_profile.s
u
reset_profilecCs�t��tj�}t|�rzx�ttt��D]A}x8ttt|��D] }t|||||7<qOWq2Wn/x,ttt��D]}t|||7<q�WWdQXdS(u�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(u
_profile_lockusysugetdxpu	has_pairsurangeulenu_cumulative_profile(unew_profileu
first_instusecond_instuinst((u>/opt/alt/python33/lib64/python3.3/Tools/scripts/analyze_dxp.pyu
merge_profile6su
merge_profilec	Cs%t�t�tjt�SWdQXdS(u9Returns the cumulative execution profile until this call.N(u
_profile_locku
merge_profileucopyudeepcopyu_cumulative_profile(((u>/opt/alt/python33/lib64/python3.3/Tools/scripts/analyze_dxp.pyusnapshot_profileGsusnapshot_profilecCsat|�r|r|d}n|}dd�t|�D�}|jdtjd�dd�|S(	u�Returns the most common opcodes in order of descending frequency.

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

    icSs8g|].\}}|dkr|tj||f�qS(i(uopcodeuopname(u.0uopucount((u>/opt/alt/python33/lib64/python3.3/Tools/scripts/analyze_dxp.pyu
<listcomp>Ys		u'common_instructions.<locals>.<listcomp>ukeyiureversei����T(u	has_pairsu	enumerateusortuoperatoru
itemgetteruTrue(uprofileu	inst_listuresult((u>/opt/alt/python33/lib64/python3.3/Tools/scripts/analyze_dxp.pyucommon_instructionsNs
	ucommon_instructionscCsVt|�sgSdd�t|dd��D�}|jdtjd�dd	�|S(
u�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)

    cSsdg|]Z\}}t|�D]A\}}|dkr||ftj|tj|f|f�qqS(i(u	enumerateuopcodeuopname(u.0uop1u
op1profileuop2ucount((u>/opt/alt/python33/lib64/python3.3/Tools/scripts/analyze_dxp.pyu
<listcomp>ks		u common_pairs.<locals>.<listcomp>Niukeyiureversei����T(u	has_pairsu	enumerateusortuoperatoru
itemgetteruTrue(uprofileuresult((u>/opt/alt/python33/lib64/python3.3/Tools/scripts/analyze_dxp.pyucommon_pairs`s		ucommon_pairscs:�dkrt��n�fdd�}dj|��S(u�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(Nu%s: %s
(ucommon_pairs(u_uopsucount(uprofile(u>/opt/alt/python33/lib64/python3.3/Tools/scripts/analyze_dxp.pyuseq~su render_common_pairs.<locals>.sequN(uNoneusnapshot_profileujoin(uprofileuseq((uprofileu>/opt/alt/python33/lib64/python3.3/Tools/scripts/analyze_dxp.pyurender_common_pairstsurender_common_pairs(u__doc__ucopyuopcodeuoperatorusysu	threadinguhasattruRuntimeErroruRLocku
_profile_lockugetdxpu_cumulative_profileu	has_pairsu
reset_profileu
merge_profileusnapshot_profileucommon_instructionsucommon_pairsuNoneurender_common_pairs(((u>/opt/alt/python33/lib64/python3.3/Tools/scripts/analyze_dxp.pyu<module>s