Enhanced debug.py: made the mark() function indicate file and line number it was called from. Added if debug: conditions around some other function actions.

- Legacy-Id: 15014
This commit is contained in:
Henrik Levkowetz 2018-04-05 13:14:09 +00:00
parent 0ef7382f99
commit 493b8daccd

View file

@ -1,3 +1,4 @@
import os
import sys
import time as timeutils
import inspect
@ -84,17 +85,27 @@ def trace(fn): # renamed from 'report' by henrik 16 Jun 2011
return fn
def mark():
_mark[0] = timeutils.time()
def show_entry(e):
sys.stderr.write(" at %s:L%s %s() %s\n" % e)
if debug:
indent = ' ' * (_report_indent[0])
file, line, func, text = tb.extract_stack(None, 2)[0]
parts = file.split(os.sep)
name = os.sep.join(parts[-2:])
sys.stderr.write("%sMark %s:%s\n" % (indent, name, line))
_mark[0] = timeutils.time()
def lap(s):
clk = timeutils.time()
tau = clk - _mark[0]
ts = timeutils.strftime("%H:%M:%S", timeutils.localtime(clk))
say("%s: %.3fs since mark: %s" % (ts, tau, s))
if debug:
clk = timeutils.time()
tau = clk - _mark[0]
ts = timeutils.strftime("%H:%M:%S", timeutils.localtime(clk))
say("%s: %.3fs since mark: %s" % (ts, tau, s))
def clock(s):
lap(s)
_mark[0] = timeutils.time()
if debug:
lap(s)
_mark[0] = timeutils.time()
def time(fn):
"""Decorator to print timing information about a function call.
@ -205,4 +216,3 @@ def info(name):
vtype = eval("type(%s)"%name, frame.f_globals, frame.f_locals)
indent = ' ' * (_report_indent[0])
sys.stderr.write("%s%s: '%s' (%s)\n" % (indent, name, value, vtype))