| 1 |
#!/usr/bin/perl -w |
| 2 |
# Change ^^ to the version of Perl you installed the SWIG modules / Graphviz with |
| 3 |
# |
| 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'; |
| 7 |
use gv; |
| 8 |
|
| 9 |
use Getopt::Long; |
| 10 |
GetOptions(\%Args, 'h|help','d|debug'); |
| 11 |
$Debug = $Args{d} || 0; |
| 12 |
$Modules = shift @ARGV || '/proc/modules'; |
| 13 |
|
| 14 |
die &usage if $Args{h}; |
| 15 |
die "Cannot read $Modules. $!\n" unless (-r $Modules); |
| 16 |
|
| 17 |
$G = gv::digraph("G"); |
| 18 |
$N = gv::protonode($G); |
| 19 |
$E = gv::protoedge($G); |
| 20 |
|
| 21 |
gv::setv($G, "rankdir", "LR"); |
| 22 |
gv::setv($G, "nodesep", "0.05"); |
| 23 |
gv::setv($N, "shape", "box"); |
| 24 |
gv::setv($N, "width", "0"); |
| 25 |
gv::setv($N, "height", "0"); |
| 26 |
gv::setv($N, "margin", ".03"); |
| 27 |
gv::setv($N, "fontsize", "8"); |
| 28 |
gv::setv($N, "fontname", "helvetica"); |
| 29 |
gv::setv($E, "arrowsize", ".4"); |
| 30 |
|
| 31 |
open (M,"<$Modules") or die "Can't open $Modules. $!\n"; |
| 32 |
|
| 33 |
while (<M>) { |
| 34 |
chomp; |
| 35 |
my @f = split(/\s+/); |
| 36 |
# Should be at least three columns |
| 37 |
next unless scalar @f >= 3; |
| 38 |
|
| 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; |
| 42 |
my $size = 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); |
| 46 |
$deps =~ s/ Live.*//; |
| 47 |
$deps =~ s/[\[\]\-(),]/ /g; |
| 48 |
|
| 49 |
Debug("$module"); |
| 50 |
my $n = gv::node($G,$module); |
| 51 |
|
| 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) ); |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
gv::layout($G, "dot"); |
| 61 |
gv::render($G, "xlib"); |
| 62 |
|
| 63 |
sub Debug { |
| 64 |
return unless $Debug; |
| 65 |
warn join(" ",@_), "\n"; |
| 66 |
} |
| 67 |
|
| 68 |
sub usage { |
| 69 |
return << "end_usage"; |
| 70 |
modgraph.pl |
| 71 |
|
| 72 |
Displays Linux kernel module dependencies from $Modules |
| 73 |
|
| 74 |
Author: John Ellson <ellson\@research.att.com> |
| 75 |
Perl Port: Max Baker <max\@warped.org> |
| 76 |
|
| 77 |
Usage: $0 [--debug] [/proc/modules] |
| 78 |
|
| 79 |
end_usage |
| 80 |
} |