Skip to content

Commit 82beb2d

Browse files
Costa ShulyupinCosta Shulyupin
authored andcommitted
*docs
1 parent 331e1cd commit 82beb2d

File tree

1 file changed

+38
-33
lines changed

1 file changed

+38
-33
lines changed

srcxray.py

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def func_referrers_cscope(name):
217217

218218
def referrers_tree(name, referrer=None, printed=None, level=0):
219219
'''
220-
Arg: <identifier> - prints text referrers tree.
220+
prints text referrers outline.
221221
Ex: nfs_root_data
222222
Obsoleted by doxygen_xml.
223223
'''
@@ -250,15 +250,15 @@ def referrers_tree(name, referrer=None, printed=None, level=0):
250250

251251
def referrers(name):
252252
'''
253-
Arg: <identifier> - simply greps referrers of a symbol
253+
simply greps referrers of a symbol
254254
Ex: nfs_root_data
255255
Prefer to use doxygen_xml.
256256
'''
257257
print(' '.join([a[2] for a in func_referrers_git_grep(name)]))
258258

259259

260260
def referrers_dep(name, referrer=None, printed=None, level=0):
261-
# Arg: <identifier> - prints referrers tree in compact format of
261+
# prints referrers tree in compact format of
262262
# dependency of make
263263
# Obsoleted by doxygen_xml.
264264
if not referrer:
@@ -290,7 +290,7 @@ def referrers_dep(name, referrer=None, printed=None, level=0):
290290

291291
def call_tree(node, printed=None, level=0):
292292
'''
293-
Arg: <identifier> - prints call tree of a function
293+
prints call tree of a function
294294
Ex: start_kernel
295295
Obsoleted by doxygen_xml.
296296
'''
@@ -356,15 +356,16 @@ def my_graph(name=None):
356356
return g
357357

358358

359-
def reduce_graph(g, m=None):
359+
def reduce_graph(g, min_in_degree=None):
360360
'''
361-
Arg: <graph> [min in_degree]- removes leaves
361+
removes leaves
362362
Ex2: \"write_dot(reduce_graph(read_dot('doxygen.dot')),'reduced.dot')\"
363363
'''
364364
rm = set()
365-
m = g.number_of_nodes() + 1 if not m else m
365+
min_in_degree = g.number_of_nodes() + 1 if not min_in_degree else min_in_degree
366366
log(g.number_of_edges())
367-
rm = [n for (n, d) in g.out_degree if not d and g.in_degree(n) < m]
367+
rm = [n for (n, d) in g.out_degree if not d and g.in_degree(n)
368+
< min_in_degree]
368369
g.remove_nodes_from(rm)
369370
print(g.number_of_edges())
370371
return g
@@ -527,9 +528,9 @@ def digraph_predecessors(dg, starts, levels=100, excludes=[], ignores=ignores):
527528
return p
528529

529530

530-
def digraph_tree(dg, starts=None, ignores=ignores):
531+
def digraph_tree(dg, starts=None):
531532
'''
532-
Arg: <graph> <list if starting nodes> - extract a subgraph from a graph
533+
extract a subgraph from a graph
533534
Ex2: \"write_dot(digraph_tree(read_dot('doxygen.dot'), ['main']), 'main.dot')\"
534535
'''
535536
tree = nx.DiGraph()
@@ -562,7 +563,7 @@ def sub(node):
562563

563564
def digraph_print(dg, starts=None, dst_fn=None, sort=False):
564565
'''
565-
Arg: <graph> - print graphs as text tree
566+
prints graph as text tree
566567
Ex2: \"digraph_print(read_dot('a.dot'))\"
567568
'''
568569
dst = open(dst_fn, 'w') if dst_fn else None
@@ -704,7 +705,7 @@ def cflow(a=None):
704705

705706

706707
def import_cflow(a=None, cflow_out=None):
707-
# Arg: $none_or_dir_or_file_or_mask
708+
# $none_or_dir_or_file_or_mask
708709
cf = my_graph()
709710
stack = list()
710711
nprev = -1
@@ -731,15 +732,15 @@ def import_cflow(a=None, cflow_out=None):
731732
return cf
732733

733734

734-
def import_outline(a=None):
735+
def import_outline(outline_txt=None):
735736
'''
736-
Arg: <outline.txt> - convert tree text to graph
737+
converts outline to graph
737738
Ex2: \"write_dot(import_outline('outline.txt'),'outline.dot')\"
738739
'''
739740
cf = my_graph()
740741
stack = list()
741742
nprev = -1
742-
with open(a, 'r') as f:
743+
with open(outline_txt, 'r') as f:
743744
for line in f:
744745
m = re.match(r'^([\t ]*)(.*)', str(line))
745746
if m:
@@ -780,7 +781,7 @@ def esc(s):
780781

781782
def write_dot(g, dot):
782783
'''
783-
Arg: <graph> <file> - writes a graph into a file with custom attributes
784+
writes a graph into a file with custom attributes
784785
'''
785786
# Other similar external functions to_agraph agwrite
786787
dot = str(dot)
@@ -958,7 +959,9 @@ def cflow_dir(a):
958959

959960

960961
def cflow_linux():
961-
# Arg:
962+
'''
963+
extracts with cflow various graphs from Linux kernel source
964+
'''
962965
dirs = ('init kernel kernel/time '
963966
'fs fs/ext4 block '
964967
'ipc net '
@@ -1000,11 +1003,12 @@ def cflow_linux():
10001003
write_dot(reduce_graph(digraph_tree(all, ['sys_clone'])), 'sys_clone.dot')
10011004

10021005

1003-
def stats(a):
1006+
def stats(graph):
10041007
'''
1005-
Arg: <dot file> - measures various simple statistical metrics of a graph
1008+
measures various simple statistical metrics of a graph
1009+
Ex: graph.dot
10061010
'''
1007-
dg = to_dg(a)
1011+
dg = to_dg(graph)
10081012
stat = Munch()
10091013
im = dict()
10101014
om = dict()
@@ -1107,17 +1111,17 @@ def import_symbols():
11071111
me = os.path.basename(sys.argv[0])
11081112

11091113

1110-
def dir_tree(d='.'):
1114+
def dir_tree(path='.'):
11111115
'''
1112-
Arg: [directory] - scan directory into graph
1116+
scans directory into graph
11131117
Ex2: \"write_dot(dir_tree('.'),'tree.dot')\"
11141118
'''
11151119
stack = list()
11161120
nprev = -1
11171121
g = my_graph()
11181122
# all = nx.DiGraph()
11191123
# TODO
1120-
for path, dirs, files, fds in os.fwalk(d):
1124+
for path, dirs, files, fds in os.fwalk(path):
11211125
(dir, base) = os.path.split(path)
11221126
dir = re.sub(r'^\.\/', '', dir)
11231127
path = re.sub(r'^\.\/', '', path)
@@ -1139,14 +1143,14 @@ def dir_tree(d='.'):
11391143
return g
11401144

11411145

1142-
def doxygen(*input):
1146+
def doxygen(*sources):
11431147
'''
1144-
Arg: <source files>
1148+
extracts call graph from sources with doxygen
11451149
Ex: *.c
11461150
'''
1147-
log(' '.join([i for i in input]))
1151+
log(' '.join([i for i in sources]))
11481152
p = run(['doxygen', '-'], stdout=PIPE,
1149-
input="INPUT=" + ' '.join([i for i in input]) + """
1153+
input="INPUT=" + ' '.join([i for i in sources]) + """
11501154
EXCLUDE_SYMBOLS=*310* *311* SOC_ENUM_SINGLE* EXPORT_SYMBOL*
11511155
CALL_GRAPH = YES
11521156
EXTRACT_ALL = YES
@@ -1174,7 +1178,7 @@ def doxygen(*input):
11741178

11751179
def doxygen_xml(a):
11761180
'''
1177-
Arg: <xml directory generated by doxygen> - extracts call graph
1181+
extracts call graph from xml directory generated by doxygen
11781182
Ex2: \"write_dot(doxygen_xml('xml'), 'doxygen.dot')\"
11791183
'''
11801184
g = my_graph()
@@ -1231,14 +1235,15 @@ def usage():
12311235
d = inspect.getdoc(m[1])
12321236
if not d:
12331237
continue
1234-
print('\n' + d.replace('Arg:', '\033[1m' + m[1].__name__ + '\033[0m').
1235-
replace('Ex:',
1236-
'\033[3mExample usage:\033[0m\n' + me + ' ' + m[1].__name__).
1238+
print('\n\033[1m' + m[1].__name__ + '\033[0m' +
1239+
str(inspect.signature(m[1])) + ' -',
1240+
d.replace('Ex:',
1241+
'\033[3mExample:\033[0m ' + me + ' ' + m[1].__name__).
12371242
replace('Ex2:',
1238-
'\033[3mExample usage:\033[0m\n' + me)
1243+
'\033[3mExample:\033[0m ' + me)
12391244
)
12401245
print("\nTry this: ")
1241-
print("cd linux/init;", me, "unittest")
1246+
print("cd linux;", me, "unittest")
12421247
print("\nEmergency termination: ^Z, kill %1")
12431248
print()
12441249

0 commit comments

Comments
 (0)