Thursday, September 27, 2007

GraphViz


Some notes on the great GraphViz package

Visualize a build dependency tree

maketograph.py

#! /usr/bin/python
import sys
import re

sys.stdout.write("digraph Makefile {\n")

regex = re.compile("^([^:]+): (.+)$")
for line in sys.stdin.read().split('\n'):
    mo = regex.match(line)
    if mo:
        origin = mo.group(1)
        targets = mo.group(2).split()
        for target in targets:
            sys.stdout.write('\t"%s" -> "%s";\n' % (target, origin))

sys.stdout.write("}")

the Makefile

all: main main2

main: main.c libhello.so
    gcc -o $@ $< -L. -lhello

main2: main2.c libhello.so
    gcc -o $@ $< -ldl

hello.o: hello.c hello.h
    gcc -c -fPIC $<

libhello.so: hello.o
    gcc -shared -o $@ $<

clean:
    rm -fr libhello.so main *.o

creating the graph

$ ./maketograph.py < Makefile > Makefile.dot
$ dot -Tpng Makefile.dot >| Makefile.png

The result:


further

  • egypt - create call graph from gcc RTL dump

No comments:

Post a Comment