ó J9•Qc@s¿dZy ddlZddlmZWnek rEd \ZZnXddlZddlZddlZddlZddl m Z ddl m Z ej dƒZde fd„ƒYZdS( s/This plugin will run tests using the hotshot profiler, which is part of the standard library. To turn it on, use the ``--with-profile`` option or set the NOSE_WITH_PROFILE environment variable. Profiler output can be controlled with the ``--profile-sort`` and ``--profile-restrict`` options, and the profiler output file may be changed with ``--profile-stats-file``. See the `hotshot documentation`_ in the standard library documentation for more details on the various output options. .. _hotshot documentation: http://docs.python.org/library/hotshot.html iÿÿÿÿN(tstats(tPlugin(ttolists nose.pluginstProfilecBsneZdZd ZeZd„Zd„Ze eƒZd„Z d„Z d„Z d„Z d„Zd„ZRS( sC Use this plugin to run tests using the hotshot profiler. c CsÆ|jƒsdStj|||ƒ|jdddddd|jdd ƒd d d d ƒ|jdddddd dd|jdƒd dƒ|jdddddd dd|jdƒd dƒdS(s&Register commandline options. Ns--profile-sorttactiontstoretdestt profile_sorttdefaulttNOSE_PROFILE_SORTt cumulativetmetavartSORTthelps"Set sort order for profiler outputs--profile-stats-filetprofile_stats_filetFILEtNOSE_PROFILE_STATS_FILEs;Profiler stats file; default is a new temp file on each runs--profile-restricttappendtprofile_restricttRESTRICTtNOSE_PROFILE_RESTRICTs?Restrict profiler output. See help for pstats.Stats for details(t availableRtoptionst add_optiontget(tselftparsertenv((s5/sys/lib/python2.7/site-packages/nose/plugins/prof.pyR!s" cCs tdk S(N(thotshottNone(tcls((s5/sys/lib/python2.7/site-packages/nose/plugins/prof.pyR8scCs3|jƒsdS|jƒtj|jƒ|_dS(s5Create profile stats file and load profiler. N(Rt _create_pfileRRtpfiletprof(R((s5/sys/lib/python2.7/site-packages/nose/plugins/prof.pytbegin<s  cCs“|jƒst|_dStj|||ƒ||_|jrV|j|_t|_nd|_t |_d|_ |j |_ t|jƒ|_dS(sConfigure plugin. N(RtFalsetenabledRt configuretconfRR tclean_stats_fileRtTruetfilenoRtsortRRtrestrict(RRR&((s5/sys/lib/python2.7/site-packages/nose/plugins/prof.pyR%Ds          cs=ˆjƒsdStjd|ƒˆj|‡fd†}|S(s6Wrap entire test run in :func:`prof.runcall`. Nspreparing test %scsˆjƒ|j||ƒdS(N(Rtruncall(tresultR!ttest(R(s5/sys/lib/python2.7/site-packages/nose/plugins/prof.pytrun_and_profile\s (RtlogtdebugR!(RR.R/((Rs5/sys/lib/python2.7/site-packages/nose/plugins/prof.pyt prepareTestVs  cCsØtjdƒ|jjƒtj|jƒ}|j|jƒt |dƒ}|rf|j }||_ nt j }|t _ z=|j rªtjd|j ƒ|j|j Œn |jƒWd|rÊ||_ n |t _ XdS(s Output profiler report. sprinting profiler reporttstreams"setting profiler restriction to %sN(R0R1R!tcloseRtloadR t sort_statsR*thasattrR3tsyststdoutR+t print_stats(RR3t prof_statst compat_25ttmp((s5/sys/lib/python2.7/site-packages/nose/plugins/prof.pytreportas$        cCs¡|jƒsdSy|jjƒWntk r4nX|jr|jrrytj|jƒWqrtk rnqrXnytj|j ƒWqtk r™qXndS(s5Clean up stats file, if configured to do so. N( RR!R4tAttributeErrorR'R)tostOSErrortunlinkR R(RR-((s5/sys/lib/python2.7/site-packages/nose/plugins/prof.pytfinalizes"      cCs1|js-tjƒ\|_|_t|_ndS(N(R ttempfiletmkstempR)R(R'(R((s5/sys/lib/python2.7/site-packages/nose/plugins/prof.pyR—s N(t__name__t __module__t__doc__RR R#R'RRt classmethodR"R%R2R>RCR(((s5/sys/lib/python2.7/site-packages/nose/plugins/prof.pyRs       (NN(RHRRt ImportErrorRtloggingR@R8RDtnose.plugins.baseRt nose.utilRt getLoggerR0R(((s5/sys/lib/python2.7/site-packages/nose/plugins/prof.pyt s