Archive for juillet 2011

Showing kernel modules dependencies graphically using graphviz

A few time ago, I had problems with my sound card module on my new linux laptop, I did not understand well how modules were loaded.

I finally solved my problem, but I was curious about the modules depency structure, and I started playing with graphviz to have a graphical view of that.

I finally came with this small & dirty python script :

# -*-coding:utf-8-*-
import os, re
#usual usage is : ./ | dot -Tpng > modules.png

print 'digraph linux_modules {'
lines = [line for line in os.popen('lsmod')]
for line in lines[1:] :
    line = [x for x in re.split('\ |,', line.replace('\n','')) if not len(x)==0]
    for dep in line[3:]:
        print '\t' + line[0] + ' -> ' + dep + ';'
print '}'

It reads the dependencies between the linux modules by calling lsmod(8), and then formats the output into a file acceptable by the dot utility, from the graphviz package.

The png output is quite cool, … And you can see how complex the sound handling is under linux compared to video !!

The other conclusion is to see how fast and easy it is to generate graphs using graphviz !

Catégories :Uncategorized