Monday, July 13, 2015

Using EclipseGraphviz as a debugging aid

My current area of interest is Model Driven Architecture. In this field, and I assume in many others too, our [data] models can be usually represented as graphs. In this scenarios, being able to view our model as an actual graph can be of great help to quickly identify errors in our model.

Come in EclipseGraphviz

Graphviz is a Graph Visualization Software that can produce graph visualizations from a graph representation in a text file (using the DOT language). EclipseGraphviz is a plugin for Eclipse that adds a view in which files with the dot extension will be rendered using Graphviz dot tool.

However, having the need to have a dot file requires you to somehow serialize your model into a file. This limits the use of the viewer for debugging purposes. Surely you can use the console to output a graph in DOT language, then copy the text, paste it to a file... or modify your code to serialize directly into a file...

Wouldn't it be nice to click on a variable in the Variable View during a debug session and have the graph representation of it shown in a nice graph?

EclipseGraphviz + debug

I have extended EclipseGraphviz to make this happen. All you have to do is add a
String toDOT();
method to any class. If the returned string is a valid DOT graph, then you will see it in the View. Simple as that...

This lets you rapidly instrument classes to have a graph representation during debug and doesn't make your projects depend on any of the EclipseGraphviz plugins. It also allows you to keep the toString() method independent if you have a string representation that might be used for other purposes. Having a toDOT() method will also provide you with a means to serialize your model if it needs be.

Bellow you can see a snapshot of how it works. I have selected variable p in the Variables view. The ExecutionPlan class has a toDOT() method. In this case the toString() method just calls toDOT() so you can see the DOT representation of the class in the Variables view.


The source code is available from GitHub (EclipseGraphviz  fork). I think the easiest way is to follow EclipseGraphviz  installation instructions and then build and export my version to your dropins folder in Eclipse.


  1. Cool idea. We also have good experiences using Graphviz for debugging, but up to now without direct integration into the Eclipse debugger. But code generation in Java (your toDOT method) is a bit naughty with the StringBuilder etc. Using a better templating language (e.g. Xtend) should make the code a lot more readable.

    1. The DOT language is simple enough, that in my case, where the data model is a graph, I can get away with generating the correct string representation using a StringBuilder. If your data model follows a different structure, it might be indeed better to use a templating language, or even a model to model and then a model to text.