import os
import string
import sys
+import time
# Recipe 14.10 from the Python Cookbook.
try:
else:
TraceDefault = '/dev/tty'
-def Trace(msg, file=None, mode='w'):
+TimeStampDefault = None
+StartTime = time.time()
+PreviousTime = StartTime
+
+def Trace(msg, file=None, mode='w', tstamp=None):
"""Write a trace message to a file. Whenever a file is specified,
it becomes the default for the next call to Trace()."""
global TraceDefault
+ global TimeStamp
+ global PreviousTime
if file is None:
file = TraceDefault
else:
TraceDefault = file
+ if tstamp is None:
+ tstamp = TimeStampDefault
+ else:
+ TimeStampDefault = tstamp
try:
fp = TraceFP[file]
except KeyError:
except TypeError:
# Assume we were passed an open file pointer.
fp = file
+ if tstamp:
+ now = time.time()
+ fp.write('%8.4f %8.4f: ' % (now - StartTime, now - PreviousTime))
+ PreviousTime = now
fp.write(msg)
fp.flush()