Visualize your code in KDevelop June 17, 2009
Posted by Sandro Andrade in planetkde-sandroandrade.trackback
Who of us hasn’t ever got lost when doing maintenance and evolution activities in highly complex software with hundreds of thousands of source code lines ? So, this is the first update on my GSoC project about static code visualization (in contrast with dynamic visualization – as in KCachegrind – and evolution visualization – for repository analysis) in KDevelop.
As I’ve mentioned before, the goal is to implement two well-known static visualization paradigms: control flow graphs and polymetric visualization. Control flow graphs should provide a direct, interactive and configurable visualization of control flow between functions, classes, and modules, whereas polymetric visualization aims at representing software metrics as easily assimilated visual pictograms. We think these features can enhance program comprehension and set the stage for advanced visualization mechanisms, such as architecture discovery and requirements tracking.
Cutting straight to the chase: in KDevelop, control flow graphs should visually represent DU-chain traversals from the function definition that contains the cursor and enable direct source code navigation and filtering facilities.
DU-chain traversals have been modelled as graphs by using Graphviz. The Graphviz’s algorithms for graph layout are used for spatial positioning of graph nodes and then the control flow graph is visualized in the KGraphViewer’s kpart.
This was my first attempt, yet limited to just one-level (direct) function call:
This time, with kpart integrated in KDevelop tool view and some configuration in Graphviz node attributes:
With a little bit of more work on my DUChainControlFlow class, we have multi-level control flow graphs from the function definition containing the cursor until the first definition-unavailable function (I know, this can be quite time-consuming for large projects. Keep reading :)).
By integrating some KGraphViewer’s kpart features with my KDevelop tool view we are able to zooming in/out/best-fit the control flow graph. Also graph nodes are colored according to its class/namespace.
My ultimate goal is to implement some features for DU-chain traversal configuration. Certainly we will have some (but not all :)) of the following:
- Definition of depth limit: by specifying the number of recursive analysis of function calls we will be able to constrain the visualization to a managed scope and have a first overview of control flow without have to wait for a depth-complete DU-chain traversal;
- DU-chain traversal filtering: it should be interesting to have some features for limiting the control flow graph generation to a specific class, module, directory, and/or project(s);
- Select control block granularity: we should be able to generate control flow graphs depicting control flow between functions, classes, and modules;
- Individual expansion of graph nodes: this will allow the user to get into the details of specific graph branches;
- Mapping of metrics to visual attributes: in a more sophisticated approach, software metrics such as function size, cyclomatic complexity etc could be mapped to visual attributes like node width, height, and color or even influence somehow the control flow graph layouting;
- Integration with debugging and profiling tools.
In the second part of my GSoC project I will implement the polymetric visualization, as presented here:
And, if time permits, what about class dependency visualization ?
Suggestions are welcome !!!
See you in the next GSoC update …
That looks awesome, and I indeed sit, in awe.
I had to take a cold shower after that!
I remember point graphviz to someone at Foz do Iguaçu 😀
Woo, interesting. I am writing an article on software visualization and I hope to include reference to this article as well.
I’ve been waiting for this ^_^. Keep it up
Now that’s what I call as cool stuff..
The right way to go.. 🙂
It reminds me some part of Kscope.
Kscope is a great tool to understand source code.
It would be great to merge some ideas from it.
Awesome!
Where can I find your code?
That. Is. Awesome!
The KDevelop Team continues to impress – superb work!
Great work, keep it up 🙂
A few questions:
* Is it solely dependent on th DU-chain info, or do you have some language-specific code ? In other words, do I only need to implement DU-chain support for $LANGUAGE in order to visualize my code with your work ?
* Are only function calls supported ? I’m thinking of languages, like Erlang, where visualizing message-passing between processes (threads) is just as important (if not more) as visualizing function calls.
Wow great stuff. Does Graphviz just output bitmapps? Only it would be great if the visulisations could be interactinve, allowing you to navigate to the relevant code by clicking on the visualisatin… things like that.
p.s. Is kcachegrind also being integrated with kdevelop?
Hélio – Yes, Graphviz rules !
Fabo – I’ll check Kscope, thanks !
Thorben – It’s in KDE playground (devtools/kdevelop4-extra-plugins/controlflowgraph), but it’s yet a work in progress so expect some crashs 🙂
Moltonel – the implementation is language-independent and by now only function calls are supported
Maninalift – Graphviz is able to export bitmaps but the rendering has been done by KGraphViewer kpart. Interaction in control flow graph will be implemented soon. I haven’t heard about any KCachegrind integration in KDevelop. Interested ? 🙂
AWESOME! I’m just speechless…
Great work, keep going!
I am waiting for years for this king of tools to come into kdevelop. I am finally glad to see the hard effort put in DUChain bringing such a great project.
This is great news. Thank you.
Very cool.
I beg you to implement the class dependency visualisation. This graph is really important for bigger projects to check for violations of the set modularisation principles.
Great-great-great! I LOVE this! Keep up the great work!
I work(ed?) quite a bit with graphviz, and indeed it can simplify the understanding of complex relationships. The KGraphViewer (used in kcachegrind, if I am not mistaken) is great, and it would be *awsome* if you could make navigation possible, just as in kcachegrind: it shows a couple of levels down and up, and through double-clicking on a box you can navigate. I think such a navigation-window would be usable as-is, that is to say, it would allow the user to just see a window with the graph and nothing else (i.e. no need of looking at the sourcecode). It would be awesome as it would abstract away all the complexity, and make code-understanding much easier: very useful if you need to understand a code written by someone else, for instance!
All in all, keep up this work, it’s amazing!
I too am extremely excited! I’ve been waiting a very long time for this. Please see KScope to encorporate a similiar functionality. KScope works well but is not completely C++ diagnostic.
Thank you!
Thank you!
travlr
beautiful!
yeah great !
but imho Graphviz is not very eyecandy….
Hi MiTcH, any alternative to Graphviz ?
Thanks,
HI, I am dying for it, does it support java, VC++, etc? it you can please make the visualization like that used in Paycheck movie, I believe it is better then Imagix 4D (http://www.imagix.com/index.html) and Headway structure guy (http://www.headwaysoftware.com/products/structure101/index.php).
It is awesome great … I can’t think anything other than this.
Thanks
The tool looks awesome, but how can I get it?
Hi,
It is still in playground, but it should be going to review and then trunk in a few weeks.
See you,
Is it going to be open source?
Do you have a project set somewhere?
I would still like to try if possible. Doesn’t matter if it is pre-alpha, and crash after 5 minutes.
Of course.
Plugin location:
http://websvn.kde.org/trunk/playground/devtools/kdevelop4-extra-plugins/controlflowgraph/
You also need graphviz installed and KGraphViewer from KDE trunk:
http://websvn.kde.org/trunk/extragear/graphics/kgraphviewer/
Hello,
the control flow graph plugin doesn’t compile with kdevplatform from git master. I made a small fix for it:
Index: kdevcontrolflowgraphviewplugin.cpp
===================================================================
— kdevcontrolflowgraphviewplugin.cpp (revision 1142941)
+++ kdevcontrolflowgraphviewplugin.cpp (working copy)
@@ -196,7 +196,7 @@
foreach(ProjectBaseItem *item, items)
{
ProjectFolderItem *folder = item->folder();
– if (folder && folder->isProjectRoot())
+ if (folder && !folder->parent())
{
m_exportProjectControlFlowGraph->setData(QVariant::fromValue(folder->project()->name()));
extension.addAction(KDevelop::ContextMenuExtension::ExtensionGroup, m_exportProjectControlFlowGraph);
Thanks, stativ. I’ve just commited you patch.
See you,
Hello again,
I just tried to download the source (again), and failed :
[packman@playground try]$ svn co http://websvn.kde.org/trunk/playground/devtools/kdevelop4-extra-plugins/controlflowgraph/ .
svn: ‘http://websvn.kde.org/trunk/playground/devtools/kdevelop4-extra-plugins/controlflowgraph’ path not found
Have you moved the plugin location?
Yes 🙂
http://websvn.kde.org/trunk/kdereview/controlflowgraph/
Thank you for quick response.
What do I do with the .so file? Where to place it and how to enable it in the kdevelop? Do you have a link? Quick google search didn’t help.
hmmm I built the plugin, but how do I set the kdevelop to use it? I tried copying it to the directory where all plugins are, and I do not see it on the list.
Do you have a link explaining how to do that?
Hi, sorry no documentation about it atm.
You should check if X-KDevelop-Version option in kdevcontrolflowgraphview.desktop contains the right version of KDevelop and then just run “make install” and start KDevelop. Check if it appears in Settings->KDevelop->Plugins.
Note that currently the plugins isn’t compiling against KDevPlatform/KDevelop trunk due to recent modifications in DU-Chain codebase.
Thanks,
Hi, where can I download this plugin?
ok, I managed to find it on github. Now when I start kdevelop, I see the plugin window and inside it a message “no graph loaded”, so I’m trying now how to load a graph…
Hi,
The official repository is: git://anongit.kde.org/kdev-control-flow-graph
It’s currently unmaintained and needs investigation about the ‘no graph loaded’ message.