summaryrefslogtreecommitdiff
path: root/Lib/trace.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2012-05-30 13:30:32 +0200
committerVictor Stinner <victor.stinner@gmail.com>2012-05-30 13:30:32 +0200
commit949d8c986ec8792fbe63d8bd2bb5332406c5af9a (patch)
tree192ad8ee5138f23b37b295272c245f568bf0d9b8 /Lib/trace.py
parent5e92a1ef5a906cd34f122cf0ee54e0303ae07a5f (diff)
downloadcpython-git-949d8c986ec8792fbe63d8bd2bb5332406c5af9a.tar.gz
Close #14690: Use monotonic clock instead of system clock in the sched,
subprocess and trace modules.
Diffstat (limited to 'Lib/trace.py')
-rw-r--r--Lib/trace.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/Lib/trace.py b/Lib/trace.py
index c0ea090645..41c2f5f69a 100644
--- a/Lib/trace.py
+++ b/Lib/trace.py
@@ -61,6 +61,10 @@ 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
@@ -476,7 +480,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:
@@ -614,7 +618,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='')
@@ -627,7 +631,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='')