��
a��Rc@stdZddkZddkZddkZddkZddkZddkZddkZddkZddk Z ddk
Z
yddkZeZWne
j
oddkZnXd�ZdZeid�Zddd��YZd�Zd �Zd
dd��YZd�Zd
�Zd�Zd�Zddd��YZd�Zdd�Zedjoe�ndS(s�program/module to trace Python program or function execution
Sample use, command line:
trace.py -c -f counts --ignore-dir '$prefix' spam.py eggs
trace.py -t --ignore-dir '$prefix' spam.py eggs
trace.py --trackcalls spam.py eggs
Sample use, programmatically
import sys
# create a Trace object, telling it what to ignore, and whether to
# do tracing or line-counting or both.
tracer = trace.Trace(ignoredirs=[sys.prefix, sys.exec_prefix,], trace=0,
count=1)
# run the new command using the given tracer
tracer.run('main()')
# make a report, placing output in /tmp
r = tracer.results()
r.write_results(show_missing=True, coverdir="/tmp")
i����NcCs|idtid�dS(Ns Usage: %s [OPTIONS] <file> [ARGS]
Meta-options:
--help Display this help then exit.
--version Output version information then exit.
Otherwise, exactly one of the following three options must be given:
-t, --trace Print each line to sys.stdout before it is executed.
-c, --count Count the number of times each line is executed
and write the counts to <module>.cover for each
module executed, in the module's directory.
See also `--coverdir', `--file', `--no-report' below.
-l, --listfuncs Keep track of which functions are executed at least
once and write the results to sys.stdout after the
program exits.
-T, --trackcalls Keep track of caller/called pairs and write the
results to sys.stdout after the program exits.
-r, --report Generate a report from a counts file; do not execute
any code. `--file' must specify the results file to
read, which must have been created in a previous run
with `--count --file=FILE'.
Modifiers:
-f, --file=<file> File to accumulate counts over several runs.
-R, --no-report Do not generate the coverage report files.
Useful if you want to accumulate over several runs.
-C, --coverdir=<dir> Directory where the report files. The coverage
report for <package>.<module> is written to file
<dir>/<package>/<module>.cover.
-m, --missing Annotate executable lines that were not executed
with '>>>>>> '.
-s, --summary Write a brief summary on stdout for each file.
(Can only be used with --count or --report.)
-g, --timing Prefix each line with the time since the program started.
Only used while tracing.
Filters, may be repeated multiple times:
--ignore-module=<mod> Ignore the given module(s) and its submodules
(if it is a package). Accepts comma separated
list of module names
--ignore-dir=<dir> Ignore files in the given directory (multiple
directories can be joined by os.pathsep).
i(twritetsystargv(toutfile((s/usr/lib/python2.6/trace.pytusageCs*s#pragma NO COVERs^\s*(#.*)?$tIgnorecBs eZddd�Zd�ZRS(cCsO|pg|_|pg|_ttii|i�|_hdd6|_dS(Nis<string>(t_modst_dirstmaptostpathtnormpatht_ignore(tselftmodulestdirs((s/usr/lib/python2.6/trace.pyt__init__vscCs�|ii|�o|i|Sxp|iD]e}||jod|i|<dSt|�}||| jo#||djod|i|<dSq)W|djod|i|<dSx:|iD]/}|i|ti�od|i|<dSq�Wd|i|<dS(Nit.i( Rthas_keyRtlentNoneRt
startswithR tsep(R
tfilenamet
modulenametmodtntd((s/usr/lib/python2.6/trace.pytnames}s*
"
N(t__name__t
__module__RRR(((s/usr/lib/python2.6/trace.pyRuscCs.tii|�}tii|�\}}|S(s-Return a plausible module name for the patch.(R R
tbasenametsplitext(R
tbaseRtext((s/usr/lib/python2.6/trace.pytmodname�scCs)tii|�}d}xttiD]i}tii|�}|i|�oA|t|�tijo't|�t|�jo
|}q�q"q"W|o|t|�d}n|}tii|�\}}|itid�}ti o|iti d�}ntii
|�\}}|id�S(s,Return a plausible module name for the path.tiR(R R
tnormcaseRRRRt
splitdrivetreplacetaltsepR tlstrip(R
tcomparepathtlongesttdirR!tdriveRR"((s/usr/lib/python2.6/trace.pytfullmodname�s"
*
tCoverageResultscBsDeZdddddd�Zd�Zeedd�Zd�ZRS(cCsK||_|idjo
h|_n|ii�|_||_|idjo
h|_n|ii�|_||_|idjo
h|_n|ii�|_||_||_|io�yDti t
|id��\}}}|i|i|||��WqGt
ttfj
o#}tid|i|fIJqGXndS(NtrbsSkipping counts file %r: %s(tcountsRtcopytcountertcalledfuncstcallerstinfileRtpickletloadtopentupdatet __class__tIOErrortEOFErrort
ValueErrorRtstderr(R
R1R4R6R5Rterr((s/usr/lib/python2.6/trace.pyR�s*
$
c Cs�|i}|i}|i}|i}|i}|i}x2|i�D]$}|i|d�||||<qCWx|i�D]}d||<qxWx|i�D]}d||<q�WdS(s.Merge in the data from another CoverageResultsiiN(R1R4R5tkeystget( R
totherR1R4R5tother_countstother_calledfuncst
other_callerstkey((s/usr/lib/python2.6/trace.pyR:�s
"
cCs�|ioOHdGH|ii�}|i�x-|D]!\}}}d|||fGHq0Wn|io�HdGH|ii�}|i�d}} x�|D]�\\}
}}\}
}}|
|joHdG|
GdGH|
}d} n|
|
jo | |
jodG|
GH|
} nd||||fGHq�Wnh}xN|ii�D]=\}}|i|h�}||<|i||f||<q<Wh}xs|i�D]e\}}|djoq�n|id �oq�n|id�o|d }n|djo.t
iit
ii
|��}t|�}n7|}t
ii|�pt
i|�nt|�}|ot|�}nh}ti|�}t
ii||d
�}|i||||�\}}|o5|o.td||�}||||f||<q�q�W|oZ|oS|i�}|i�dGHx5|D])}||\}}}}d||GHq)Wn|ioby5ti|i|i|ift|id�d�Wq�tj
o}tid|IJq�XndS(s!
@param coverdir
sfunctions called:s*filename: %s, modulename: %s, funcname: %sscalling relationships:R$s***s -->s %s.%s -> %s.%ss<string>s <doctest s.pycs.pyoi����s.coveridslines cov% module (path)s%5d %3d%% %s (%s)twbis"Can't save counts files because %sN(s.pycs.pyo(R4RAtsortR5R1RBt iteritemsRtendswithRR R
tdirnametabspathR#texiststmakedirsR.tfind_executable_linenost linecachetgetlinestjointwrite_results_filetintRR7tdumpR9R<RR?(R
tshow_missingtsummarytcoverdirtcallsRRtfuncnametlastfilet lastcfiletpfiletpmodtpfunctcfiletcmodtcfunctper_filetlinenot lines_hittsumstcountR,tlnotabtsourcet coverpathtn_hitstn_linestpercenttmodstmR@((s/usr/lib/python2.6/trace.pyt
write_results�s�
cCsEyt|d�}Wn-tj
o!}tid||fIJd SXd}d}x�t|�D]�\} }
| d}||jo-|id||�|d7}|d7}nhti|
�o|id�nG||jo,t|| jo|id�|d7}n|id�|i|| i d��q\W|i
�||fS(
s'Return a coverage results file in path.tws2trace: Could not open %r for writing: %s- skippingiis%5d: s s>>>>>> i(ii(R9R<RR?t enumerateRtrx_blanktmatchtPRAGMA_NOCOVERt
expandtabstclose(R
R
tlinesRiRfRR@RmRltitlineRe((s/usr/lib/python2.6/trace.pyRTUs0
N( RRRRR:tTruetFalseRqRT(((s/usr/lib/python2.6/trace.pyR/�s
[c
Cs�h}g}|iddd�D]}|t|�q!~}t|�}t}|i}x3|D]+} || 7}||jod||<q_q_W|S(s:Return dict where keys are lines in the line number table.iNi(t co_lnotabtordRR}tco_firstlineno(
tcodetstrstlinenost_[1]tctline_incrementsttable_lengtht docstringRetli((s/usr/lib/python2.6/trace.pytfind_lines_from_codeys7
cCsTt||�}x>|iD]3}t|ti�o|it||��qqW|S(s<Return lineno dict for all code objects reachable from code.(R�t co_constst
isinstancettypestCodeTypeR:t
find_lines(R�R�R�R�((s/usr/lib/python2.6/trace.pyR��s
cCs�h}ti}t|�}x�ti|i�D]�\}}}}}|tijoX|tijoD|\} }
|\}}x)t| |d�D]}
d||
<q�Wq�n|}q.W|i�|S(s�Return a dict of possible docstring positions.
The dict maps line numbers to strings. There is an entry for
line that contains only a string or a part of a triple-quoted
string.
i( ttokentINDENTR9ttokenizetgenerate_tokenstreadlinetSTRINGtrangeRx(RRt
prev_ttypetftttypettstrtstarttendR{tslinetscoltelinetecolRz((s/usr/lib/python2.6/trace.pytfind_strings�s
cCstyt|d�i�}Wn-tj
o!}tid||fIJhSXt||d�}t|�}t||�S(sAReturn dict where keys are line numbers in the line number table.trUs%Not printing coverage data for %r: %stexec(R9treadR<RR?tcompileR�R�(RtprogR@R�R�((s/usr/lib/python2.6/trace.pyRP�s
tTracec
Bs�eZdddddddded� Zd�Zddd�Zd�Zd�Zd�Z d�Z
d �Zd
�Zd�Z
d�Zd
�ZRS(iic
Cs:||_||_t||�|_h|_h|_h|_d|_||_h|_ h|_
h|_d|_
| oti�|_
n|o|i|_n�|o|i|_nz|o#|o|i|_|i|_nP|o|i|_|i|_n-|o|i|_|i|_n
d|_dS(sx
@param count true iff it should count number of times each
line is executed
@param trace true iff it should print out each line that is
being counted
@param countfuncs true iff it should just output a list of
(filename, modulename, funcname,) for functions
that were called at least once; This overrides
`count' and `trace'
@param ignoremods a list of the names of modules to ignore
@param ignoredirs a list of the names of directories to ignore
all of the (recursive) contents of
@param infile file from which to read stored counts to be
added into the results
@param outfile file in which to write the results
@param timing true iff timing information be displayed
iiN(R6RRtignoreR1tblabbedtpathtobasenamet donothingttracet_calledfuncst_callerst
_caller_cacheRt
start_timettimetglobaltrace_trackcallerstglobaltracetglobaltrace_countfuncstglobaltrace_lttlocaltrace_trace_and_countt
localtracetlocaltrace_tracetlocaltrace_count(
R
RhR�t
countfuncstcountcallerst
ignoremodst
ignoredirsR6Rttiming((s/usr/lib/python2.6/trace.pyR�s8 cBs�ddk}|i}|ip$ei|i�ei|i�nz|||UWd|ipeid�eid�nXdS(Ni����(t__main__t__dict__R�RtsettraceR�t threadingR(R
tcmdR�tdict((s/usr/lib/python2.6/trace.pytrun�s
cBs�|djo
h}n|djo
h}n|ip$ei|i�ei|i�nz|||UWd|ipeid�eid�nXdS(N(RR�RR�R�R�(R
R�tglobalstlocals((s/usr/lib/python2.6/trace.pytrunctx�s
cOsZd}|ipti|i�nz|||�}Wd|iptid�nX|S(N(RR�RR�R�(R
tfunctargstkwtresult((s/usr/lib/python2.6/trace.pytrunfuncs
c
Cs�|i}|i}|ot|�}nd}|i}d}||ijo)|i|dj o|i|}q�n2d|i|<g}ti|�D]!}t|d�o||q�q�~} t | �djo�g}
ti| d�D]!}t
|t�o|
|q�q�~
}t |�djozg}
ti|d�D]!}t|d�o|
|qBqB~
}t |�djo!t|d�}||i|<q�q�n|dj o6|i
d�d}di|�}d||f}n|||fS(Ntfunc_dociit __bases__Rs%s.%s(tf_codetco_filenameR#Rtco_nameR�tgct
get_referrersthasattrRR�R�tstrtsplitRS(R
tframeR�RRR[tclsnameR�R�tfuncst_[2]Rtdictst_[3]R�tclasses((s/usr/lib/python2.6/trace.pytfile_module_function_ofs6
$$$
cCsI|djo8|i|�}|i|i�}d|i||f<ndS(skHandler for call events.
Adds information about who called who to the self._callers dict.
tcalliN(R�tf_backR�(R
R�twhytargt this_functparent_func((s/usr/lib/python2.6/trace.pyR�>s
cCs1|djo |i|�}d|i|<ndS(soHandler for call events.
Adds (filename, modulename, funcname) to the self._calledfuncs dict.
R�iN(R�R�(R
R�R�R�R�((s/usr/lib/python2.6/trace.pyR�Is
cCs�|djo�|i}|iidd�}|oet|�}|dj oH|ii||�}|p(|iod||ifGHn|i Sq�q�dSndS(s�Handler for call events.
If the code block being entered is to be ignored, returns `None',
else returns self.localtrace.
R�t__file__s! --- modulename: %s, funcname: %sN(
R�t f_globalsRBRR#R�RR�R�R�(R
R�R�R�R�RRt ignore_it((s/usr/lib/python2.6/trace.pyR�Rs
cCs�|djo�|ii}|i}||f}|ii|d�d|i|<|iodti�|iGntii |�}d||t
i||�fGn|iS(NR{iis%.2fs
%s(%d): %s(
R�R�tf_linenoR1RBR�R�R R
RRQtgetlineR�(R
R�R�R�RReRGtbname((s/usr/lib/python2.6/trace.pyR�is
cCs|djok|ii}|i}|iodti�|iGntii|�}d||ti ||�fGn|i
S(NR{s%.2fs
%s(%d): %s(R�R�R�R�R�R R
RRQR�R�(R
R�R�R�RReR�((s/usr/lib/python2.6/trace.pyR�xs
cCsY|djoE|ii}|i}||f}|ii|d�d|i|<n|iS(NR{ii(R�R�R�R1RBR�(R
R�R�R�RReRG((s/usr/lib/python2.6/trace.pyR��s
$c
Cs1t|id|id|id|id|i�S(NR6RR4R5(R/R1R6RR�R�(R
((s/usr/lib/python2.6/trace.pytresults�s ((N(RRRR}RR�R�R�R�R�R�R�R�R�R�R�(((s/usr/lib/python2.6/trace.pyR��s1
-
cCs2tiidtid|f�tid�dS(Ns%s: %s
ii(RR?RRtexit(tmsg((s/usr/lib/python2.6/trace.pyt _err_exit�s!cCs�ddk}|djo
ti}nyP|i|dddddddd d
ddd
dddddg�\}}Wna|ij
oR}tiidtid|f�tiidtid�tid�nXd}d}d}d}d} d}
g}g}d}
d}t}t}t}x!|D]\}}|djot ti
�tid�n|djo!ti
id�tid�n|djp
|djo
t}q/n|djp
|djo
t}q/n|djp
|djo
t}q/n|djp
|d jo
d}q/n|d!jp
|d"jo
d}q/n|d#jp
|d$jo
d}q/n|d%jp
|d&jo
d}q/n|d'jp
|d(jo
|} q/n|d)jp
|d*jo
d}
q/n|d+jp
|d,jo
|}
q/n|d-jp
|d.jo
d}q/n|d/jo4x*|id0�D]}|i
|i��q^Wq/n|d1jo�x�|iti�D]�}tii|�}|id2tiitid3d4tid5 ��}|id6tiitid3d4tid5 ��}tii|�}|i
|�q�Wq/q/q/W|o|p|otd7�n|p|p|p|p|ptd8�n|o|otd9�n|o| otd:�n|o!t|�djotd;�n|o2td<| d=| �}|i|
d
|d>|
�nY|t_|d}tii|�dtid<t||d?|d@|dA|dB|d<| d=| d|�}yzt|�ii �}z%|~}t!|i"�|dC�}WdQXh|dD6dEdF6ddG6ddH6}|i#|||�WnBt$j
o$}tdItid|f�nt%j
onX|i&�}|p|i|
d
|d>|
�ndS(JNi����istcrRf:d:msC:lTgthelptversionR�Rhtreports no-reportRXsfile=tmissingsignore-module=signore-dir=s coverdir=t listfuncst
trackcallsR�s%s: %s
is%Try `%s --help' for more information
s--helps --versions
trace 2.0
s-Ts--trackcallss-ls--listfuncss-gs--timings-ts--traces-cs--counts-rs--reports-Rs--no-reports-fs--files-ms --missings-Cs
--coverdirs-ss --summarys--ignore-modulet,s--ignore-dirs$prefixtlibtpythonis$exec_prefixs8cannot specify both --listfuncs and (--trace or --count)sLmust specify one of --trace, --count, --report, --listfuncs, or --trackcallss,cannot specify both --report and --no-reports--report requires a --filesmissing name of file to runR6RRYR�R�R�R�R�R�R�Rt__package__t
__cached__sCannot run file %r because: %s('tgetoptRRRterrorR?RR�R}RtstdoutR|R�tappendtstripR tpathsepR
t
expandvarsR'RStprefixR�texec_prefixRR�RR/RqR�R9t__exit__t __enter__R�R�R�R<t
SystemExitR�(RR�toptst prog_argvR�R�RhR�t no_reporttcounts_fileR�tignore_modulestignore_dirsRYRXR�R�R�topttvalRtsR�tprognamettR�tfpR�tglobsR@((s/usr/lib/python2.6/trace.pytmain�s�
!
#
#
R�((((t__doc__RQR treRR�R�R�R�R�R�tcPickleR7tImportErrorRRvR�RtRR#R.R/R�R�R�RPR�R�RRR(((s/usr/lib/python2.6/trace.pyt<module>0s>
-5 � � �