diff options
Diffstat (limited to 'Lib/trace.py')
-rw-r--r-- | Lib/trace.py | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/Lib/trace.py b/Lib/trace.py index 850369b9ff..317b5fd6c8 100644 --- a/Lib/trace.py +++ b/Lib/trace.py @@ -39,8 +39,8 @@ Sample use, programmatically # 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) + tracer = trace.Trace(ignoredirs=[sys.base_prefix, sys.base_exec_prefix,], + trace=0, count=1) # run the new command using the given tracer tracer.run('main()') # make a report, placing output in /tmp @@ -48,19 +48,20 @@ Sample use, programmatically r.write_results(show_missing=True, coverdir="/tmp") """ __all__ = ['Trace', 'CoverageResults'] -import io import linecache import os import re import sys -import time import token import tokenize import inspect import gc import dis import pickle -from warnings import warn as _warn +try: + from time import monotonic as _time +except ImportError: + from time import time as _time try: import threading @@ -244,8 +245,7 @@ class CoverageResults: """Return True if the filename does not refer to a file we want to have reported. """ - return (filename == "<string>" or - filename.startswith("<doctest ")) + return filename.startswith('<') and filename.endswith('>') def update(self, other): """Merge in the data from another CoverageResults""" @@ -477,7 +477,7 @@ class Trace: self._caller_cache = {} self.start_time = None if timing: - self.start_time = time.time() + self.start_time = _time() if countcallers: self.globaltrace = self.globaltrace_trackcallers elif countfuncs: @@ -615,7 +615,7 @@ class Trace: self.counts[key] = self.counts.get(key, 0) + 1 if self.start_time: - print('%.2f' % (time.time() - self.start_time), end=' ') + print('%.2f' % (_time() - self.start_time), end=' ') bname = os.path.basename(filename) print("%s(%d): %s" % (bname, lineno, linecache.getline(filename, lineno)), end='') @@ -628,7 +628,7 @@ class Trace: lineno = frame.f_lineno if self.start_time: - print('%.2f' % (time.time() - self.start_time), end=' ') + print('%.2f' % (_time() - self.start_time), end=' ') bname = os.path.basename(filename) print("%s(%d): %s" % (bname, lineno, linecache.getline(filename, lineno)), end='') @@ -750,10 +750,10 @@ def main(argv=None): # should I also call expanduser? (after all, could use $HOME) s = s.replace("$prefix", - os.path.join(sys.prefix, "lib", + os.path.join(sys.base_prefix, "lib", "python" + sys.version[:3])) s = s.replace("$exec_prefix", - os.path.join(sys.exec_prefix, "lib", + os.path.join(sys.base_exec_prefix, "lib", "python" + sys.version[:3])) s = os.path.normpath(s) ignore_dirs.append(s) |