Debian Codegraph @

tclpkg/gv/demo/modgraph.rb

raw
1 #!/usr/bin/ruby
2
3 # display the kernel module dependencies
4
5 #based on: modgraph.tcl by: John Ellson <[email protected]>
6 #ruby adaptation by: Patricio Ros <[email protected]>
7 #additional fixes: Ralph Mueller <[email protected]>
8
9 require 'gv'
10
11 G = Gv.digraph("G")
12 N = Gv.protonode(G)
13 E = Gv.protoedge(G)
14
15 Gv.setv(G, 'rankdir', 'LR')
16 Gv.setv(G, 'nodesep', '0.05')
17 Gv.setv(N, 'shape', 'box')
18 Gv.setv(N, 'width', '0')
19 Gv.setv(N, 'height', '0')
20 Gv.setv(N, 'margin', '.03')
21 Gv.setv(N, 'fontsize', '8')
22 Gv.setv(N, 'fontname', 'helvetica')
23 Gv.setv(E, 'arrowsize', '.4')
24
25 modules = File.open('/proc/modules', mode="r").readlines
26
27 modules.each {|rec|
28 fields = rec.split(' ')
29 n = Gv.node(G, fields[0])
30 fields[3].split(',').each {|usedby|
31 Gv.edge(n, Gv.node(G, usedby)) if (usedby != '-') and (usedby != '')
32 }
33 }
34
35 Gv.layout(G, 'dot')
36 Gv.render(G, 'xlib')