3
# display the kernel module dependencies
5
# author: John Ellson <ellson@research.att.com>
7
use lib "/usr/lib/graphviz/perl";
2
# Change ^^ to the version of Perl you installed the SWIG modules / Graphviz with
4
# Change this to point to your installed graphviz lib dir
5
# Normally either /usr/local/lib/graphviz/perl or /usr/lib/graphviz/perl
6
#use lib '/home/maxb/lib/graphviz/perl';
10
GetOptions(\%Args, 'h|help','d|debug');
11
$Debug = $Args{d} || 0;
12
$Modules = shift @ARGV || '/proc/modules';
14
die &usage if $Args{h};
15
die "Cannot read $Modules. $!\n" unless (-r $Modules);
10
17
$G = gv::digraph("G");
11
18
$N = gv::protonode($G);
12
19
$E = gv::protoedge($G);
21
28
gv::setv($N, "fontname", "helvetica");
22
29
gv::setv($E, "arrowsize", ".4");
24
#FIXME - complete translation to perl
26
#f = File.open('/proc/modules', mode="r")
30
# for mod, usedbylist in string.gfind(rec, "([_%w]+) %w+ %w+ ([-,_%w]+)") do
32
# for usedby in string.gfind(usedbylist, "([-_%w]+)") do
33
# if (usedby ~= '-') and (usedby ~= '') then
34
# gv.edge(n, gv.node(G, usedby))
31
open (M,"<$Modules") or die "Can't open $Modules. $!\n";
36
# Should be at least three columns
37
next unless scalar @f >= 3;
39
# Linux 2.4 : parport 36832 1 (autoclean) [parport_pc lp]
40
# Linux 2.6 : eeprom 14929 0 - Live 0xffffffff88cc5000
41
my $module = shift @f;
43
my $used_by = shift @f;
44
# this is ugly, needed to clean up the list of deps from 2.4 or 2.6
45
my $deps = join (' ',@f);
47
$deps =~ s/[\[\]\-(),]/ /g;
50
my $n = gv::node($G,$module);
52
foreach my $d ( split(/\s+/,$deps) ){
53
# gv::node($G, $d) creates the node, if needed,
54
# but doesn't complain if it already exists
55
Debug(" $d -> $module");
56
gv::edge($n, gv::node($G, $d) );
42
60
gv::layout($G, "dot");
43
gv::render($G, "gtk");
61
gv::render($G, "xlib");
65
warn join(" ",@_), "\n";
69
return << "end_usage";
72
Displays Linux kernel module dependencies from $Modules
74
Author: John Ellson <ellson\@research.att.com>
75
Perl Port: Max Baker <max\@warped.org>
77
Usage: $0 [--debug] [/proc/modules]