roza / rcviz

Python call graph visualization for recursive functions.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool


  • Python module to visualize a recursion as a tree with arguments and return values at each node.
  • Provides a decorator to instrument target functions (as opposed to trace or debugger based approaches)
  • Uses pygraphviz to render the graph.


  1. Use the @viz decorator to instrument the recursive function.

def factorial(n):

  1. Render the recursion with


The output file type is derived from the file name. Supported types include .dot (graphviz dot file), .png (png image), .svg (vector graphic)


Output for recursive Fibonacci function and for a Recursive Descent parse can be found on this blog post

from rcviz import callgraph, viz

def quicksort(items):
    if len(items) <= 1: 
        return items
        pivot = items[0]
        lesser = quicksort([x for x in items[1:] if x < pivot])
        greater = quicksort([x for x in items[1:] if x >= pivot])
        return lesser + [pivot] + greater

print quicksort( list("helloworld") )


quicksort rcviz output


  1. The edges are numbered by the order in which they were traversed by the execution.
  2. The edges are colored from black to grey to indicate order of traversal : black edges first, grey edges last.


Show intermediate values of local variables in the output render by invoking decoratedfunction.track(param1=val1, param2=val2,...). In the quicksort example above you can track the pivot with:

	pivot = items[0]
	quicksort.track(the_pivot=pivot) # shows a new row labelled the_pivot in each node 


This requires the native graphviz and libgraphviz-dev packages pre-installed. e.g. On ubuntu do:

$sudo apt-get install graphviz libgraphviz-dev


For python2:

python -m virtualenv .venv source .venv/bin/activate python install

For python3.x:

python -m venv .venv source .venv/bin/activate python install

Tested on python 2.7.3 and python 3.6

Setup script by adampetrovic.

ezoic increase your site revenue


Python call graph visualization for recursive functions.


Language:Python 100.0%