[erlang-questions] code dependency diagrams

Ulf Wiger (TN/EAB) ulf.wiger@REDACTED
Fri Feb 15 12:20:46 CET 2008


I've mentioned on occasion that I'd like to see a visualization tool
that shows an UML-style structure diagram for Erlang applications,
but with annotations showing the direction and arity of the
dependencies.

Why? Because in some communities, you clearly don't understand modeling
unless you can show a pictured of named boxes stringed together, but
also because this sort of thing could be useful, if it also takes the
opportunity to show the degree of dependency between two blocks of code.


Writing code that counts dependencies between heaps of beam files is
not difficult. It's quite possible that xref does it out of the box,
but the xref manual is so scary that I can't bring myself to use it
(a bit like others seem to feel about xmerl, I guess...)

So I wrote my own little module to start with (I can provide it on
request, but it's not interesting enough to burden the mailing list
with). It will spit out things like:

3> depends:cycles(1157).
[{"acc_ch","ccpc_gen",5,0},
  {"agm_om","hcfa_gen",10,0},
  {"agm_om","oms1",10,0},
  {"agm_om","rcmKernel",2,0},
  {"agm_om","sys1",4,0},
  {"agm_om","sysCmd",1,0},

where 1157 in this case is an ets table, and the output is
[{AppA, AppB, CallsAtoB, CallsBtoA}], and what's counted is
really how many /modules/ have some dependency to some module
in the other application. Obviously, there are other ways to
measure the degree of dependency, but this is also not that
interesting for now. (:

(Running it on OTP really does reveal a few cyclical dependencies,
mainly between stdlib and kernel, but also e.g. mnesia and snmp.)

Now to the real challenge: drawing the &#*! chart. I made an
attempt at using GraphViz, and generated a Dot file like this
one:

=================================================

digraph G {

  subgraph cluster_ags {
    style=filled;
     color=lightgrey;
     node [style=filled, color=white];

     label = "ags";
   }

  subgraph cluster_syf {
    style=filled;
     color=lightgrey;
     node [style=filled, color=white];

     label = "syf";
   }
acc_ch -> ccpc_gen [headlabel = 5];ctxt_ch -> ccpc_gen [headlabel = 
1];ctxt_ch -> sysCmd [headlabel = 8];}

=================================================

...then converted it to SVG using some WinGraphViz demo program.

This worked reasonably well for small numbers of applications,
but my full example (charting dependencies between two subsystems)
had 150 entries, and that turned out a useless graph. Perhaps any
block diagram with 150 blocks stringed together will be utterly
useless, and the answer is to filter and aggregate the info.
Or maybe there are knobs and levers in GraphViz that I have yet
to learn about that will give me better layouts...?

And now to the question: Which tool would you recommend I use?
I looked at Eclipse once, but got the feeling that you won't get
anywhere without first writing a thousand or so lines of Java code.
Is this still the way to go?

Bonus question: does anyone want to play with me on this?

BR,
Ulf W



More information about the erlang-questions mailing list