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:
parent
0ef7382f99
commit
493b8daccd
26
debug.py
26
debug.py
|
@ -1,3 +1,4 @@
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
import time as timeutils
|
import time as timeutils
|
||||||
import inspect
|
import inspect
|
||||||
|
@ -84,17 +85,27 @@ def trace(fn): # renamed from 'report' by henrik 16 Jun 2011
|
||||||
return fn
|
return fn
|
||||||
|
|
||||||
def mark():
|
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):
|
def lap(s):
|
||||||
clk = timeutils.time()
|
if debug:
|
||||||
tau = clk - _mark[0]
|
clk = timeutils.time()
|
||||||
ts = timeutils.strftime("%H:%M:%S", timeutils.localtime(clk))
|
tau = clk - _mark[0]
|
||||||
say("%s: %.3fs since mark: %s" % (ts, tau, s))
|
ts = timeutils.strftime("%H:%M:%S", timeutils.localtime(clk))
|
||||||
|
say("%s: %.3fs since mark: %s" % (ts, tau, s))
|
||||||
|
|
||||||
def clock(s):
|
def clock(s):
|
||||||
lap(s)
|
if debug:
|
||||||
_mark[0] = timeutils.time()
|
lap(s)
|
||||||
|
_mark[0] = timeutils.time()
|
||||||
|
|
||||||
def time(fn):
|
def time(fn):
|
||||||
"""Decorator to print timing information about a function call.
|
"""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)
|
vtype = eval("type(%s)"%name, frame.f_globals, frame.f_locals)
|
||||||
indent = ' ' * (_report_indent[0])
|
indent = ' ' * (_report_indent[0])
|
||||||
sys.stderr.write("%s%s: '%s' (%s)\n" % (indent, name, value, vtype))
|
sys.stderr.write("%s%s: '%s' (%s)\n" % (indent, name, value, vtype))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue