forked from OpenSDV/Linux_Kernel_map4vehicle
*digraph_print +dst
This commit is contained in:
parent
5bebe62d3e
commit
cdbcc35efc
33
srcxray.py
33
srcxray.py
|
@ -52,12 +52,13 @@ limit = 100000
|
||||||
n = 0
|
n = 0
|
||||||
|
|
||||||
|
|
||||||
def print_limited(a):
|
def print_limited(a, out=None):
|
||||||
print(a)
|
out = out if out else sys.stdout
|
||||||
|
out.write(str(a) + '\n')
|
||||||
global n
|
global n
|
||||||
n += 1
|
n += 1
|
||||||
if n > limit + 1:
|
if n > limit + 1:
|
||||||
print('...')
|
out.write('...')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
# raise(Exception('Reached limit'))
|
# raise(Exception('Reached limit'))
|
||||||
|
|
||||||
|
@ -442,17 +443,21 @@ def digraph_tree(dg, starts=None):
|
||||||
return tree
|
return tree
|
||||||
|
|
||||||
|
|
||||||
def digraph_print(dg, starts=None, sort=False):
|
def digraph_print(dg, starts=None, dst_fn=None, sort=False):
|
||||||
def digraph_print_sub(node=None, printed=None, level=0):
|
dst = open(dst_fn, 'w') if dst_fn else None
|
||||||
|
|
||||||
|
def digraph_print_sub(path='', node=None, printed=None, level=0):
|
||||||
outs = {_: dg.out_degree(_) for _ in dg.successors(node)}
|
outs = {_: dg.out_degree(_) for _ in dg.successors(node)}
|
||||||
if sort:
|
if sort:
|
||||||
outs = {a: b for a, b in sorted(outs.items(), key=lambda k: k[1], reverse=True)}
|
outs = {a: b for a, b in sorted(outs.items(), key=lambda k: k[1], reverse=True)}
|
||||||
if node in printed:
|
if node in printed:
|
||||||
print_limited(level*'\t' + str(node) + ' ^')
|
print_limited(level*'\t' + str(node) + ' ^', dst)
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
s = ' ...' if level > level_limit - 2 and outs else ''
|
s = ''
|
||||||
print_limited(level*'\t' + str(node) + s)
|
if outs:
|
||||||
|
s = ' ...' if level > level_limit - 2 else ' @' + path
|
||||||
|
print_limited(level*'\t' + str(node) + s, dst)
|
||||||
printed.add(node)
|
printed.add(node)
|
||||||
if level > level_limit - 2:
|
if level > level_limit - 2:
|
||||||
return ''
|
return ''
|
||||||
|
@ -461,7 +466,7 @@ def digraph_print(dg, starts=None, sort=False):
|
||||||
if o in passed or o in black_list:
|
if o in passed or o in black_list:
|
||||||
continue
|
continue
|
||||||
passed.add(o)
|
passed.add(o)
|
||||||
digraph_print_sub(o, printed, level + 1)
|
digraph_print_sub(path + ' ' + str(node), o, printed, level + 1)
|
||||||
|
|
||||||
printed = set()
|
printed = set()
|
||||||
if not starts:
|
if not starts:
|
||||||
|
@ -470,15 +475,19 @@ def digraph_print(dg, starts=None, sort=False):
|
||||||
starts[i] = dg.out_degree(i)
|
starts[i] = dg.out_degree(i)
|
||||||
starts = [a[0] for a in sorted(starts.items(), key=lambda k: k[1], reverse=True)]
|
starts = [a[0] for a in sorted(starts.items(), key=lambda k: k[1], reverse=True)]
|
||||||
if len(starts) > 1:
|
if len(starts) > 1:
|
||||||
print_limited(default_root)
|
print_limited(default_root, dst)
|
||||||
for s in starts:
|
for s in starts:
|
||||||
print_limited('\t' + s + ' ->')
|
print_limited('\t' + s + ' ->', dst)
|
||||||
passed = set()
|
passed = set()
|
||||||
for o in starts:
|
for o in starts:
|
||||||
if o in passed or o in black_list:
|
if o in passed or o in black_list:
|
||||||
continue
|
continue
|
||||||
passed.add(o)
|
passed.add(o)
|
||||||
digraph_print_sub(o, printed)
|
if o in dg:
|
||||||
|
digraph_print_sub('', o, printed)
|
||||||
|
if dst_fn:
|
||||||
|
print(dst_fn)
|
||||||
|
dst.close()
|
||||||
|
|
||||||
|
|
||||||
def cflow_preprocess(a):
|
def cflow_preprocess(a):
|
||||||
|
|
Loading…
Reference in New Issue