annotate README @ 7:6d864126b45a tip

Arrggh! I think it's right now.
author samer
date Sat, 12 Apr 2014 12:50:11 +0100
parents 2fa75f473a41
children
rev   line source
samer@0 1 This package provides library(callgraph), a tool for compiling a graph of calls between predicates in a module.
samer@0 2
samer@0 3 ---++++ Prerequisites
samer@0 4
samer@0 5 The graph layout programs from the GraphViz library (http://graphviz.org/) are
samer@1 6 used to render the end result. Whilst you can produce a dot file without them,
samer@0 7 you will need them for the final rendering.
samer@0 8 On Mac OS X with MacPorts installed, do this at the bash prompt.
samer@0 9 ==
samer@0 10 $ sudo port install graphviz
samer@0 11 ==
samer@0 12 On Debian based systems, do this:
samer@0 13 ==
samer@0 14 $ sudo apt-get install graphviz
samer@0 15 ==
samer@0 16 And so on.
samer@0 17 You will need a PDF viewer to see the results.
samer@0 18
samer@0 19
samer@0 20
samer@0 21 ---++++ Simple usage
samer@0 22
samer@0 23 To produce a call graph as a PDF, make sure that both this module and the
samer@0 24 module you wish to analyse are loaded, then do this:
samer@0 25 ==
samer@0 26 ?- module_dotpdf(<module_name>,[]).
samer@0 27 ==
samer@0 28 This will produce a PDF file <module_name>.pdf in the current directory.
samer@0 29 Often, the default layout program, dot, will produce a very wide graph.
samer@0 30 This can sometimes be alleviated by using the unflatten program from the
samer@0 31 Graphviz tools. In module_dotpdf/2, the default layout method does actually
samer@0 32 use unflatten without any parameters, but if this is not enough, you can
samer@0 33 provide values for the -f, -l and -c switches of unflatten (see the man
samer@0 34 page for unflatten for more details). For example, to produce a graph of
samer@0 35 callgraph itself, you can try the following:
samer@0 36 ==
samer@0 37 $ swipl
samer@0 38 ?- use_module(library(callgraph)).
samer@0 39 ?- module_dotpdf(callgraph,[method(unflatten([fl(4),c(4)]))]).
samer@0 40 ==
samer@0 41
samer@0 42 ---++++ Output formats
samer@0 43
samer@0 44 If you want the dot language source file, use module_dot/2 instead. The
samer@0 45 method option is then inapplicable.
samer@0 46
samer@0 47 The code can also produce rendered graphs in any format supported by
samer@0 48 Graphviz, but this functionality is not currently exposed.
samer@0 49
samer@0 50 ---++++ Limitations
samer@0 51
samer@0 52 The graph compilation relies on prolog_walk_code/1 to do the actual code
samer@0 53 analysis. This does a good job in most cases, using meta-predicate declarations
samer@0 54 or inferred meta-predicates to detect many high-order calling patterns.
samer@0 55 Ironically enough, callgraph fails to analyse itself fully because
samer@0 56 prolog_walk_code/1 does not detect that it itself calls a given predicate
samer@0 57 for each call detected. Thus, in the example, there is no edge from
samer@0 58 assert_module_graph/1 to assert_edge/4.
samer@0 59
samer@0 60 ---++++ Planned enhancements
samer@0 61
samer@0 62 The main thing to add next is to render graphs for multiple modules using dot's
samer@0 63 subgraph facility. Otherwise, the system for dealing with style attributes is
samer@0 64 a bit messy and could be cleaned up.