�9�c@s�dZy ddlZddlmZWnek
rEd \ZZnXddlZddlZddlZddlZddl m
Z
ddlmZej
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(ttolistsnose.pluginstProfilecBsneZdZd ZeZd�Zd�Ze e�Zd�Z
d�Zd�Zd�Z
d�Zd�ZRS(
sC
Use this plugin to run tests using the hotshot profiler.
cCs�|j�sdStj|||�|jdddddd|jdd �d
ddd
�|jdddddd
dd|jd�dd�|jdddddd
dd|jd�dd�dS(s&Register commandline options.
Ns--profile-sorttactiontstoretdesttprofile_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.pytprepareTestVs
cCs�tjd�|jj�tj|j�}|j|j�t |d�}|rf|j
}||_
ntj}|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+tprint_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 �Wq�tk
r�q�XndS(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'RRtclassmethodR"R%R2R>RCR(((s5/sys/lib/python2.7/site-packages/nose/plugins/prof.pyRs (NN(RHRRtImportErrorRtloggingR@R8RDtnose.plugins.baseRt nose.utilRt getLoggerR0R(((s5/sys/lib/python2.7/site-packages/nose/plugins/prof.pyt<module>s
|