Draw kernel module dependancy graph.

lsmod | perl -e 'print "digraph \"lsmod\" {";<>;while(<>){@_=split/\s+/; print "\"$_[0]\" -> \"$_\"\n" for split/,/,$_[3]}print "}"' | dot -Tpng | display -
parse `lsmod' output and pass to `dot' drawing utility then finally pass it to an image viewer

35
By: bandie91
2011-11-27 14:02:35

1 Alternatives + Submit Alt

What Others Think

Wonderful.
kaedenn · 517 weeks and 3 days ago
"Imagemagick is smarter than you think. It can display dot files, so the dot command is unnecessary." - Comment by dratini0 8 hours ago
bandie91 · 517 weeks and 2 days ago
So how would you do this with ImageMagick?
SuperFly · 517 weeks and 2 days ago
If anyone's running into a missing helvetica error on debian or ubuntu, give this a try: sudo apt-get install xfs xfstt t1-xfree86-nonfree ttf-xfree86-nonfree ttf-xfree86-nonfree-syriac xfonts-75dpi xfonts-100dpi and reboot. (from http://root.cern.ch/phpBB3/viewtopic.php?f=3&t=12627#p54486)
psykotron · 517 weeks and 1 day ago
SuperFly: lsmod | perl -e 'print "digraph \"lsmod\" {";;while(){@_=split/\s+/; print "\"$_[0]\" -> \"$_\"\n" for split/,/,$_[3]}print "}"' | display - you can also replace 'display - ' with 'gm display - ' if you have GraphicsMagick installed instead of ImageMagick (or just install graphicsmagick-imagemagick-compat to replace GraphicsMagick completely)
psykotron · 517 weeks and 1 day ago
@SuperFly: with IM not the whole procedure, just the `dot | display' thing. `display' can interpret this format too and displays it on transparent (for me). @psykotron: i think reboot unneccessary. Run `fc-cache -r' !
bandie91 · 517 weeks and 1 day ago
I have ImageMagick-6.2.8.0-4.el5_5.3.x86_64 installed and I get this: lsmod | perl -e 'print "digraph \"lsmod\" {";<>;while(<>){@_=split/\s+/; print "\"$_[0]\" -> \"$_\"\n" for split/,/,$_[3]}print "}"' | display - display: no decode delegate for this image format `/tmp/magick-XX6QuBzg'.
SuperFly · 517 weeks and 1 day ago
type `display -list format' to get supported formata. display -list format | grep DOT DOT DOT r-- Graphviz I've: display -list configure Path: /usr/lib/ImageMagick-6.6.0/config/configure.xml Name Value ------------------------------------------------------------------------------- CC gcc -std=gnu99 -std=gnu99 CFLAGS -I/usr/include/lqr-1 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -fopenmp -g -O2 -Wall -W -pthread CONFIGURE ./configure '--prefix=/usr' '--mandir=${prefix}/share/man' '--infodir=${prefix}/share/info' '--with-modules' '--with-gs-font-dir=/usr/share/fonts/type1/gsfonts' '--with-magick-plus-plus' '--with-djvu' '--enable-shared' '--without-dps' '--without-fpx' '--with-perl-options=INSTALLDIRS=vendor' '--x-includes=/usr/include/X11' '--x-libraries=/usr/lib/X11' 'CFLAGS=-g -O2' 'LDFLAGS=' 'CPPFLAGS=' 'CXXFLAGS=-g -O2' COPYRIGHT Copyright (C) 1999-2010 ImageMagick Studio LLC CPPFLAGS -I/usr/include/ImageMagick CXX g++ CXXFLAGS -g -O2 -Wall -W -pthread DEFS -DHAVE_CONFIG_H DELEGATES bzlib djvu fontconfig freetype gvc jpeg jng jp2 lcms lqr openexr png rsvg tiff x11 xml wmf zlib DISTCHECK_CONFIG_FLAGS 'CFLAGS=-g -O2' 'CPPFLAGS=' 'LDFLAGS=' --disable-deprecated --with-quantum-depth=16 --with-umem=no --with-autotrace=no --with-dps=no --with-fpx=no --with-gslib=no --with-fontpath= --with-gs-font-dir=/usr/share/fonts/type1/gsfonts EXEC-PREFIX /usr HOST i686-pc-linux-gnu LDFLAGS -L/usr/lib -L/usr/lib/X11 LIB_VERSION 0x660 LIB_VERSION_NUMBER 6,6,0,4 LIBS -lMagickCore -llcms -ltiff -lfreetype -ljpeg -llqr-1 -lglib-2.0 -lfontconfig -lXext -lSM -lICE -lX11 -lXt -lbz2 -lz -lm -lgomp -lpthread -lltdl NAME ImageMagick PCFLAGS -fopenmp PREFIX /usr QuantumDepth 16 RELEASE_DATE 2010-11-16 VERSION 6.6.0 WEBSITE http://www.imagemagick.org
bandie91 · 517 weeks and 1 day ago
# `awk` is very good at parsing the output of `lsmod` lsmod | awk 'BEGIN{print "digraph lsmod {"}; NR!=1&&NF==4{printf("\t%s -> { %s };\n", $1, gensub(",", "", "g", $4))}; END{print "}"}' | dot -Tpng | display -
kev · 517 weeks and 1 day ago
# sorry, please change `gensub(",", "", "g", $4)` to `gensub(",", " ", "g", $4)`
kev · 517 weeks and 1 day ago
@unixmonkey21861: it not really works... how modulenames in 4th field filled? printf doesnt accept gensub's array.
bandie91 · 517 weeks and 1 day ago
brilliant..
alperyilmaz · 516 weeks and 3 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: