-
Notifications
You must be signed in to change notification settings - Fork 11
/
plot.py
98 lines (79 loc) · 3.21 KB
/
plot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/env python3
import os
import fire
from graphviz import Digraph
def plot(data=None, output=None):
components=["lib-newlib" ,"posix-libdl" ,"posix-process" ,"posix-user" ,"ramfs" ,"ukalloc" ,"ukallocbbuddy" ,"uklock" ,"ukmpi" ,"uknetdev" ,"uksched" ,"ukschedcoop" , "ukswrand" ,"uktime" ,"uktimeconv" ,"vfscore", "lib-lwip"]
dot = Digraph(comment='Nginx graph plot')
dot.attr(ratio="compress")
dot.attr(ranksep="0")
dot.attr(concentrate="true")
dot.attr(size="50,20")
dot.attr(rankdir="LR")
dot.attr("node", fontname="Helvetica", fontcolor="black", fontsize="80",shape="box")
dot.attr("edge", fontname="Helvetica", fontcolor="blue", fontsize="35")
adj_list = {}
for i in components:
adj_list[i] = {}
for line in open(os.path.join(data, i) + ".deps", "r"):
if "lib" in line:
j = line.split("/")[2]
if j == i or j == "ukdebug":
continue
if j not in components:
continue
if j not in adj_list[i]:
adj_list[i][j] = 0
adj_list[i][j] = adj_list[i][j] + 1
myDict = {
**dict.fromkeys(["lib-newlib", "posix-process", "posix-user", "posix-libdl"], "posix-layer"),
**dict.fromkeys(["vfscore", "ramfs"], "fs"),
**dict.fromkeys(["uktime", "uktimeconv"], "time"),
**dict.fromkeys(["uklock"], "locking"),
**dict.fromkeys(["uksched", "ukschedcoop"], "sched"),
**dict.fromkeys(["ukswrand"], "security"),
**dict.fromkeys(["ukalloc", "ukallocbbuddy"], "mm"),
**dict.fromkeys(["uknetdev", "lib-lwip"], "net"),
**dict.fromkeys(["ukmpi"], "ipc"),
**dict.fromkeys(["uksglist"], "ukds"),
**dict.fromkeys(["ukboot"], "ukboot1"),
**dict.fromkeys(["ukargparse"], "ukargparse1"),
**dict.fromkeys(["ukbus"], "ukbus1"),
}
G = {}
for i in components:
G[myDict[i]] = {}
for j, value in adj_list[i].items():
#print(myDict[j])
if myDict[j] not in G[myDict[i]]:
G[myDict[i]][myDict[j]] = 0
G[myDict[i]][myDict[j]] += value
#dot.edge(i, j, label=str(value))
for i, value in G.items():
#print("##### " + i)
continue
t = "cluster"+i
with dot.subgraph(name=t) as c:
c.attr(label=i)
c.attr(pack="8")
c.attr(style="filled")
c.attr(color="lightgrey")
c.attr(overlap='false')
c.attr(style='rounded, filled')
c.attr(fontsize='10')
#for j, value2 in myDict.items():
#if value2 == i:
#c.node(j, shape="box", style="filled, rounded",color="white",fontsize="12")
for i, value in G.items():
for j, value2 in value.items():
if i != j:
dot.edge(i,j, label=str(value2))
# indirect calls are missing, we add them manually
dot.edge("posix-layer", "mm", "6")
dot.edge("sched", "mm", "2")
dot.attr("node", fontcolor="white", fontsize="80", shape="box", style="filled", color="black")
dot.edge("nginx", "posix-layer")
dot.edge("nginx", "net")
dot.render(output)
if __name__ == '__main__':
fire.Fire(plot)