^cflow_linux

This commit is contained in:
Costa Shulyupin 2018-07-31 05:21:50 +03:00
parent 4e3d5b005b
commit 5726a30ee9
1 changed files with 46 additions and 33 deletions

View File

@ -635,44 +635,57 @@ def read_dot2(dot):
def cflow_linux(): def cflow_linux():
dirs = ('init kernel kernel/time ' dirs = ('init kernel kernel/time '
'mm fs fs/ext4 block ' 'fs fs/ext4 block '
'ipc net net/ipv4 ' 'ipc net '
'lib security security/keys crypto ' 'lib security security/keys '
'arch/x86/kernel drivers/char drivers/pci ' 'arch/x86/kernel drivers/char drivers/pci '
).split() ).split()
# dirs += ('mm net/ipv4 crypto').split()
dirs = ('init kernel arch/x86/kernel fs ').split()
# fs/notify/fanotify fs/notify/inotify # fs/notify/fanotify fs/notify/inotify
try:
print('loading all.dot')
all = read_dot2('all.dot')
# all = nx.DiGraph(read_dot('all.dot'))
except FileNotFoundError:
all = nx.DiGraph() all = nx.DiGraph()
for a in dirs: for a in dirs:
print(a) print(a)
dir = nx.DiGraph() index = nx.DiGraph()
for c in glob.glob(os.path.join(a, "*.c")): for c in glob.glob(os.path.join(a, "*.c")):
g = None g = None
dot = str(Path(c).with_suffix(".dot")) dot = str(Path(c).with_suffix(".dot"))
if not os.path.isfile(dot): if not os.path.isfile(dot):
g = import_cflow(c, Path(c).with_suffix(".cflow")) g = import_cflow(c, Path(c).with_suffix(".cflow"))
print(g['start_kernel'])
write_dot(g, dot) write_dot(g, dot)
print(dot, popen("ctags -x %s | wc -l" % (c))[0], len(set(e[0] for e in g.edges()))) print(dot, popen("ctags -x %s | wc -l" % (c))[0], len(set(e[0] for e in g.edges())))
else: else:
print(dot)
try: try:
# g = nx.drawing.nx_agraph.read_dot(dot)
g = read_dot(dot) g = read_dot(dot)
except TypeError: except (TypeError, pygraphviz.agraph.DotError):
g = nx.drawing.nx_agraph.read_dot(dot) print('nx_pydot <- nx_agraph')
g2 = nx.DiGraph() g = nx.drawing.nx_pydot.read_dot(dot)
g2.add_edges_from(g.edges()) # digraph_print(g, [], Path(c).with_suffix(".tree"))
write_dot(g, dot + '2') # index.add_nodes_from(g.nodes())
# print(dot) index.add_edges_from(g.edges())
digraph_print(g, [], Path(c).with_suffix(".tree")) write_dot(index, str(os.path.join(a, 'index.dot')))
# dir.add_nodes_from(g.nodes()) digraph_print(digraph_tree(index), [], os.path.join(a, 'index.tree'))
dir.add_edges_from(g.edges()) # all.add_nodes_from(index.nodes())
write_dot(dir, str(os.path.join(a, 'dir.dot'))) all.add_edges_from(index.edges())
digraph_print(digraph_tree(dir), [], os.path.join(a, 'dir.tree'))
# all.add_nodes_from(dir.nodes())
all.add_edges_from(dir.edges())
write_dot(all, 'all.dot') write_dot(all, 'all.dot')
digraph_print(all, ['x86_64_start_kernel', 'start_kernel', 'main', 'initcall', 'early_param', '__setup'], # print('loops: ' + str( all.nodes_with_selfloops()))
print('trees:')
digraph_print(all, ['x86_64_start_kernel', 'start_kernel', 'main', 'initcall', 'early_param', '__setup', 'sys_write', 'write'],
'all.tree') 'all.tree')
start_kernel = digraph_tree(all, ['start_kernel'])
write_dot(start_kernel, 'start_kernel.dot')
write_dot(reduce_graph(start_kernel), 'start_kernel-reduced.dot')
write_dot(reduce_graph(reduce_graph(start_kernel)), 'start_kernel-reduced2.dot')
me = os.path.basename(sys.argv[0]) me = os.path.basename(sys.argv[0])