modgraph.pl 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. use Getopt::Long;
  9. GetOptions(\%Args, 'h|help','d|debug');
  10. $Debug = $Args{d} || 0;
  11. $Modules = shift @ARGV || '/proc/modules';
  12. die &usage if $Args{h};
  13. die "Cannot read $Modules. $!\n" unless (-r $Modules);
  14. $G = gv::digraph("G");
  15. $N = gv::protonode($G);
  16. $E = gv::protoedge($G);
  17. gv::setv($G, "rankdir", "LR");
  18. gv::setv($G, "nodesep", "0.05");
  19. gv::setv($N, "shape", "box");
  20. gv::setv($N, "width", "0");
  21. gv::setv($N, "height", "0");
  22. gv::setv($N, "margin", ".03");
  23. gv::setv($N, "fontsize", "8");
  24. gv::setv($N, "fontname", "helvetica");
  25. gv::setv($E, "arrowsize", ".4");
  26. open (M,"<$Modules") or die "Can't open $Modules. $!\n";
  27. while (<M>) {
  28. chomp;
  29. my @f = split(/\s+/);
  30. # Should be at least three columns
  31. next unless scalar @f >= 3;
  32. # Linux 2.4 : parport 36832 1 (autoclean) [parport_pc lp]
  33. # Linux 2.6 : eeprom 14929 0 - Live 0xffffffff88cc5000
  34. my $module = shift @f;
  35. my $size = shift @f;
  36. my $used_by = shift @f;
  37. # this is ugly, needed to clean up the list of deps from 2.4 or 2.6
  38. my $deps = join (' ',@f);
  39. $deps =~ s/ Live.*//;
  40. $deps =~ s/[\[\]\-(),]/ /g;
  41. Debug("$module");
  42. my $n = gv::node($G,$module);
  43. foreach my $d ( split(/\s+/,$deps) ){
  44. # gv::node($G, $d) creates the node, if needed,
  45. # but doesn't complain if it already exists
  46. Debug(" $d -> $module");
  47. gv::edge($n, gv::node($G, $d) );
  48. }
  49. }
  50. gv::layout($G, "dot");
  51. gv::render($G, "xlib");
  52. sub Debug {
  53. return unless $Debug;
  54. warn join(" ",@_), "\n";
  55. }
  56. sub usage {
  57. return << "end_usage";
  58. modgraph.pl
  59. Displays Linux kernel module dependencies from $Modules
  60. Author: John Ellson <ellson\@research.att.com>
  61. Perl Port: Max Baker <max\@warped.org>
  62. Usage: $0 [--debug] [/proc/modules]
  63. end_usage
  64. }