In scripts, adopted aggresive width-finding for unbounded recursion
This makes it easier to read the output, at a cost of these scripts not terminating if the underlying call sctucture contains loops. Previously these scripts would not terminate, but at least output the call tree as they visit each function. This was hard to read, and wasn't really that useful? If you hit a case with infinite recursion, you can limit the output size explicitly with -Z. Note this also drops --tree in stack.py. Since we get more readable output, this flag is less useful. This simplifies the script a bit.
This commit is contained in:
+26
-7
@@ -800,10 +800,31 @@ def table(Result, results, diff_results=None, *,
|
||||
it.chain([23], it.repeat(7)),
|
||||
range(len(lines[0])-1))]
|
||||
|
||||
# adjust the name width based on the expected call depth, though
|
||||
# note this doesn't really work with unbounded recursion
|
||||
if not summary and not m.isinf(depth):
|
||||
widths[0] += 4*(depth-1)
|
||||
# adjust the name width based on the call depth
|
||||
if not summary:
|
||||
depth_ = depth
|
||||
if m.isinf(depth_):
|
||||
# find the actual depth, this may not terminate! in which
|
||||
# case it's up to the user to provide an explicit depth
|
||||
def rec_depth(results_):
|
||||
# rebuild our tables at each layer
|
||||
table_ = {
|
||||
','.join(str(getattr(r, k) or '') for k in by): r
|
||||
for r in results_}
|
||||
names_ = list(table_.keys())
|
||||
|
||||
return max((
|
||||
rec_depth(table_[name].children)
|
||||
for name in names_),
|
||||
default=-1) + 1
|
||||
|
||||
depth_ = max((
|
||||
rec_depth(table[name].children)
|
||||
for name in names
|
||||
if name in table),
|
||||
default=-1) + 1
|
||||
|
||||
widths[0] += 4*max(depth_-1, 0)
|
||||
|
||||
# print the tree recursively
|
||||
print('%-*s %s%s' % (
|
||||
@@ -840,9 +861,7 @@ def table(Result, results, diff_results=None, *,
|
||||
|
||||
print('%s%-*s %s' % (
|
||||
prefixes[0+is_last],
|
||||
widths[0] - (
|
||||
len(prefixes[0+is_last])
|
||||
if not m.isinf(depth) else 0),
|
||||
widths[0] - len(prefixes[0+is_last]),
|
||||
name,
|
||||
' '.join('%*s' % (w, x)
|
||||
for w, x in zip(
|
||||
|
||||
Reference in New Issue
Block a user