Coloured call graphs!

Juha Jeronen has added some features to the Python call-graph generator (pyan) I’ve previously blogged about. With a single command line, I can now get pictures like this:

pyan.py -c backup.py journal.py journalcmd.py links.py --dot | dot -Tpng > backup-use-and-def.png

A bit of colour always shows a program’s structure in a better light. Green for the backup program, orange and blue for high-level and low-level journal manipulation, and yellow for link creation.

As well as automatic colouring by namespace, there are options to control whether use- and define- edges are shown, and whether nodes in each namespaces are grouped together. For instance, instead of drawing define-edges between namespaces and their members as above, we could omit those edges and instead group them. The “fdp” layout algorithm seems to render best for this graph:

pyan.py -n -g -c backup.py journal.py journalcmd.py links.py --dot | fdp -Tpng > backup-use-and-group.png

Juha’s colour and grouping enhancements are implemented for the GraphViz output. pyan also outputs .tgf files for yEd. But “trivial graph format” is just too trivial to support these options, so I may soon extend the program to write the more advanced .graphml format.

This entry was posted in Programming and tagged , , , . Bookmark the permalink.

9 Responses to Coloured call graphs!

  1. Juha Jeronen says:

    Thanks for the post. Nice ‘screenshots’ :)

    By the way, I have now modified XDot, too. The new version comes with an incremental Find feature (handy for looking for nodes by label text), and highlights outgoing/incoming linked nodes (if modifiers held down) when hovering over nodes. It also has some new UI animations, the UI has been generally polished, and it has built-in documentation.

    I just posted about the changes to the original site ( http://code.google.com/p/jrfonseca/wiki/XDot ), currently waiting if there is an interest.

    Check it out (no pun intended) if you or any of the readers are interested. It’s available at:

    https://yousource.it.jyu.fi/jjrandom2/miniprojects/trees/master/refactoring/

  2. Juha Jeronen says:

    Update: my repository for this was getting a bit messy, so it has been reorganized. The modified Pyan and XDot are now both in their own subfolders:

    https://yousource.it.jyu.fi/jjrandom2/miniprojects/trees/master/refactoring/pyan
    https://yousource.it.jyu.fi/jjrandom2/miniprojects/trees/master/refactoring/xdot

    The top-level directory

    https://yousource.it.jyu.fi/jjrandom2/miniprojects/trees/master/refactoring

    contains a combined README and a wrapper script (analyze.sh) for convenience.

  3. Pingback: More thoughts on version control | EJRH

  4. This is a brilliant project and I was so glad to find it! I’ve extracted the code from both your repositories into a single one that contains a history from each of your original commits, but not in the same repository as your other software … I hope that’s useful. It’s at:

    https://github.com/davidfraser/pyan/

Leave a comment