jump to navigation

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:

controlflowgraph1

This time, with kpart integrated in KDevelop tool view and some configuration in Graphviz node attributes:

controlflowgraph2

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 :)).

controlflowgraph3

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.

controlflowgraph4

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 ?

xraySystemPackagesDependencyView

Suggestions are welcome !!!

See you in the next GSoC update …

goingtoakademy

Comments»

1. illogic-al - June 17, 2009

That looks awesome, and I indeed sit, in awe.

2. nixternal - June 17, 2009

I had to take a cold shower after that!

3. Helio - June 17, 2009

I remember point graphviz to someone at Foz do Iguaçu 😀

4. Abhishek Tiwari - June 18, 2009

Woo, interesting. I am writing an article on software visualization and I hope to include reference to this article as well.

5. Zeke Connor - June 18, 2009

I’ve been waiting for this ^_^. Keep it up

6. OpenGuru - June 18, 2009

Now that’s what I call as cool stuff..

The right way to go.. 🙂

7. fabo - June 18, 2009

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.

8. Thorben - June 18, 2009

Awesome!
Where can I find your code?

9. Oded - June 18, 2009

That. Is. Awesome!

10. Anon - June 18, 2009

The KDevelop Team continues to impress – superb work!

11. moltonel - June 18, 2009

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.

12. maninalift - June 18, 2009

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?

13. Sandro Andrade - June 18, 2009

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 ? 🙂

14. Bernhard - June 18, 2009

AWESOME! I’m just speechless…

Great work, keep going!

15. seb - June 18, 2009

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.

16. Stefan Majewsky - June 18, 2009

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.

17. Mate - June 19, 2009

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!

18. travlr - June 19, 2009

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

19. bráulio - June 19, 2009

beautiful!

20. MiTcH - June 23, 2009

yeah great !
but imho Graphviz is not very eyecandy….

Sandro Andrade - June 30, 2009

Hi MiTcH, any alternative to Graphviz ?
Thanks,

21. Sudeepta - August 10, 2009

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

22. VJ - May 12, 2010

The tool looks awesome, but how can I get it?

Sandro Andrade - May 12, 2010

Hi,

It is still in playground, but it should be going to review and then trunk in a few weeks.
See you,

VJ - May 14, 2010

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.

23. Sandro Andrade - May 14, 2010
24. stativ - June 30, 2010

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);

Sandro Andrade - June 30, 2010

Thanks, stativ. I’ve just commited you patch.
See you,

25. VJ - September 27, 2010

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?

Sandro Andrade - September 27, 2010
Vladimir Jovic - September 28, 2010

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.

26. VJ - October 1, 2010

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?

Sandro Andrade - October 1, 2010

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,

27. anon - September 19, 2014

Hi, where can I download this plugin?

28. anon - September 19, 2014

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…

Sandro Andrade - September 19, 2014

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.


Leave a reply to moltonel Cancel reply