ó RÑÕfc@s¾dZddlZddlZddlZddlZddlZeedƒs`edƒ‚nejƒZ ej ƒa d„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:/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'ttjƒ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 c Cs·t«tjƒ}t|ƒr|x‹tttƒƒD]C}x:ttt|ƒƒD]"}t||c|||7cs7ˆ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.pyts