Instantly share code, notes, and snippets.

Embed
What would you like to do?
Quick escript to generate a visualization of app dependencies in Erlang/OTP.
%%% Run with 'escript app_deps.erl'
%%% Change the path in filelib:wildcard/1 as required to capture all
%%% your dependencies.
%%%
%%% Rectangular nodes will represent library apps (no processes involved)
%%% and the circular nodes will represent regular apps. An arrow going from
%%% 'A -> B' means 'A depends on B'.
%%%
%%% This script depends on graphviz being present on the system.
-module(app_deps).
-export([main/1]).
main(_) ->
AppFiles = filelib:wildcard("deps/*/ebin/*.app")
++
filelib:wildcard("ebin/*.app"),
Deps = [{App, proplists:get_value(applications, Props, []), apptype(Props)}
|| {ok, [{_,App,Props}]} <-
[file:consult(AppFile) || AppFile <- AppFiles]],
to_graphviz(Deps).
apptype(Props) ->
case proplists:get_value(mod, Props) of
undefined -> library;
_ -> regular
end.
to_graphviz(Deps) ->
Bytes = ["digraph G { ",
"K=0.25; ",
"ratio=0.75; ",
"overlap=\"9:prism\"; ",
[io_lib:format("~p [shape=box] ", [App])
|| {App, _, library} <- Deps],
[[io_lib:format("~p->~p ", [App,Dep]) || Dep <- DepList -- [kernel, stdlib]]
|| {App, DepList, _} <- Deps],
"}"],
file:write_file("app-deps.dot", Bytes),
io:format("~s",[os:cmd("dot app-deps.dot -Tpng -o app-deps.png")]).
@ferd

This comment has been minimized.

Copy link
Owner

ferd commented Sep 23, 2012

Example output done on Riak: http://i.imgur.com/DAZGP.png

@formido

This comment has been minimized.

Copy link

formido commented Jul 21, 2014

Nice.

@binarytemple

This comment has been minimized.

Copy link

binarytemple commented Dec 11, 2014

Nice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment