mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-27 12:48:22 +00:00
kernel: add python script to generate init dependency graph
This commit is contained in:
@@ -32,3 +32,4 @@ initrds
|
||||
hdd.img
|
||||
netdump.dat
|
||||
build-*
|
||||
graph_kernel_deps.png
|
||||
|
||||
Executable
+71
@@ -0,0 +1,71 @@
|
||||
#!/usr/bin/env python3
|
||||
# Generates a graph of the Kernel's init dependencies
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
from matplotlib import pyplot as plt
|
||||
import networkx as nx
|
||||
from networkx.drawing.nx_agraph import graphviz_layout
|
||||
|
||||
path = os.path.abspath(__file__)
|
||||
kernel_source = os.path.dirname(path) + '/kernel-src'
|
||||
|
||||
routine_dependencies = {}
|
||||
|
||||
lines = subprocess.Popen(['grep', '-R', 'INIT_ROUTINE_DEFINE(', kernel_source], stdout=subprocess.PIPE).stdout.readlines()
|
||||
|
||||
for line in lines:
|
||||
if b"#define" in line:
|
||||
continue
|
||||
|
||||
line = line.strip()
|
||||
|
||||
junk, line = line.split(b'(')
|
||||
|
||||
line = line.replace(b';', b'').replace(b')', b'')
|
||||
|
||||
if line.count(b',') > 2:
|
||||
name, flags, function, dependencies = line.split(b',', 3)
|
||||
else:
|
||||
# no dependencies
|
||||
name, flags, function = line.split(b',', 2)
|
||||
dependencies = b''
|
||||
|
||||
name = name.strip().decode('utf-8')
|
||||
routine_dependencies[name] = []
|
||||
|
||||
dependencies = dependencies.split(b',')
|
||||
|
||||
for dep in dependencies:
|
||||
dep = dep.strip().decode('utf-8')
|
||||
if dep == '':
|
||||
continue
|
||||
|
||||
routine_dependencies[name].insert(0, dep)
|
||||
|
||||
for routine in routine_dependencies:
|
||||
print("routine '", routine, "' has dependencies: ", end='', sep='')
|
||||
dependencies = routine_dependencies[routine]
|
||||
print(dependencies)
|
||||
|
||||
# plot
|
||||
|
||||
graph = nx.DiGraph()
|
||||
|
||||
graph.add_nodes_from(routine_dependencies.keys())
|
||||
|
||||
edges = []
|
||||
for routine in routine_dependencies:
|
||||
for dep in routine_dependencies[routine]:
|
||||
edges.insert(0, (dep, routine))
|
||||
|
||||
graph.add_edges_from(edges)
|
||||
|
||||
plt.figure(figsize=(20, 16))
|
||||
|
||||
pos = graphviz_layout(graph, prog='dot')
|
||||
nx.draw(graph, pos, with_labels=True, node_size=3000)
|
||||
plt.title("Kernel init dependencies")
|
||||
plt.savefig('graph_kernel_deps.png')
|
||||
|
||||
print("File saved in graph_kernel_deps.png")
|
||||
+1
-5
@@ -9,11 +9,7 @@
|
||||
|
||||
static cpu_t bsp_cpu;
|
||||
|
||||
INIT_ROUTINE_DEFINE(bsp_early,
|
||||
INIT_ROUTINE_FLAGS_PHONY,
|
||||
NULL,
|
||||
alloc, term, cpu
|
||||
);
|
||||
INIT_ROUTINE_DEFINE(bsp_early, INIT_ROUTINE_FLAGS_PHONY, NULL, alloc, term, cpu);
|
||||
|
||||
DEFINE_KERNEL_ARGUMENT(root, char *);
|
||||
DEFINE_KERNEL_ARGUMENT(rootfs, char *);
|
||||
|
||||
+1
-4
@@ -267,10 +267,7 @@ void pmm_init() {
|
||||
MUTEX_INIT(&freelistmutex);
|
||||
}
|
||||
|
||||
INIT_ROUTINE_DEFINE(pmm,
|
||||
INIT_ROUTINE_FLAGS_NONE,
|
||||
pmm_init,
|
||||
arch_early);
|
||||
INIT_ROUTINE_DEFINE(pmm, INIT_ROUTINE_FLAGS_NONE, pmm_init, arch_early);
|
||||
|
||||
// XXX pmm_alloc won't be able to take pages from the page cache when the allocation size is over 1 page
|
||||
|
||||
|
||||
Reference in New Issue
Block a user