Did you know ... Search Documentation:
Packs (add-ons) for SWI-Prolog

Package "callgraph"

Title:Predicate call graph visualisation
Rating:
(1/1)
Latest version:0.4.1
SHA1 sum:eb6d378310d0ceb675ba07ef257479589b92d7fc
Author:Samer Abdallah <s.abdallah@ucl.ac.uk>
Download URL:https://raw.githubusercontent.com/samer--/prolog/master/callgraph/release/callgraph-0.4.1.tgz
Requires:dcgutils
fileutils
swipe

Reviews

Write a review or add a rating.
Awesome, maybe I will integrate in loqt.
Wednesday 17 December 2014, Carlo Capelli

Details by download location

VersionSHA1#DownloadsURL
0.2585213cf0583bfc95b1e2f7f0bf518fed5c9d2ed1https://code.soundsoftware.ac.uk/projects/callgraph/repository/raw/release/callgraph-0.2.tgz
0.2.1793935ef30828d94edd22d328845147bb7add7855https://code.soundsoftware.ac.uk/projects/callgraph/repository/raw/release/callgraph-0.2.1.tgz
http://code.soundsoftware.ac.uk/projects/callgraph/repository/raw/release/callgraph-0.2.1.tgz
0.2.2860e15580efb9bb4264208d99a900f8c42223eda1https://github.com/samer--/prolog/raw/master/callgraph/release/callgraph-0.2.2.tgz
0.2.3195af706f056a5fce21e0f778ddaac2704b9bd981https://github.com/samer--/prolog/raw/master/callgraph/release/callgraph-0.2.3.tgz
0.2.41321388d24356bc9987eb6b72f79cc4d2dc483b11https://github.com/samer--/prolog/raw/master/callgraph/release/callgraph-0.2.4.tgz
0.2.5fceae79f9a0939a075757c3732a9dd12a27629cb2https://github.com/samer--/prolog/raw/master/callgraph/release/callgraph-0.2.5.tgz
0.2.6129cf58a9c66d580287e033c38ba4b9da3b859521https://github.com/samer--/prolog/raw/master/callgraph/release/callgraph-0.2.6.tgz
0.2.742e02c8389ab4a8e20261121d463523c509babde3https://github.com/samer--/prolog/raw/master/callgraph/release/callgraph-0.2.7.tgz
0.2.8d8a2c29a5bef17851fc38293126efa1cc4d041f01https://github.com/samer--/prolog/raw/master/callgraph/release/callgraph-0.2.8.tgz
0.2.97623371e7422ef431a4b31064cae04989c0fdd9d2https://github.com/samer--/prolog/raw/master/callgraph/release/callgraph-0.2.9.tgz
0.3.00158cdc37d0e445b47650bb38d36ea6db5c60f3b2https://github.com/samer--/prolog/raw/master/callgraph/release/callgraph-0.3.0.tgz
0.3.108c2b970d1e761d24c5211cf49bb86667bd315442https://github.com/samer--/prolog/raw/master/callgraph/release/callgraph-0.3.1.tgz
0.3.29a2752d82eb8977732b41c0df24a727b2702baad4https://github.com/samer--/prolog/raw/master/callgraph/release/callgraph-0.3.2.tgz
0.3.36b91781154560385f68dab5fd49bea8b5b45048f1https://github.com/samer--/prolog/raw/master/callgraph/release/callgraph-0.3.3.tgz
0.3.49a6cad576ad8c1f5cb71da05ce7a8bcce77a60d910https://github.com/samer--/prolog/raw/master/callgraph/release/callgraph-0.3.4.tgz
0.3.5370c2d5349f74b0481d1bb92b9be4c820179b76a9https://github.com/samer--/prolog/raw/master/callgraph/release/callgraph-0.3.5.tgz
0.4.07d0d38e0b062e00bbfe4c7870d916a6bfb84f63a88https://github.com/samer--/prolog/raw/master/callgraph/release/callgraph-0.4.0.tgz
0.4.1eb6d378310d0ceb675ba07ef257479589b92d7fc8https://raw.githubusercontent.com/samer--/prolog/master/callgraph/release/callgraph-0.4.1.tgz

This package provides library(callgraph), a tool for compiling a graph of calls between predicates in a module.

Prerequisites

The graph layout programs from the GraphViz library (http://graphviz.org/) are used to render the end result. Whilst you can produce a dot file without them, you will need them for the final rendering. On Mac OS X with MacPorts installed, do this at the bash prompt.

$ sudo port install graphviz

On Debian based systems, do this:

$ sudo apt-get install graphviz

And so on. You will need a PDF viewer to see the results.

Simple usage

To produce a call graph as a PDF, make sure that both this module and the module you wish to analyse are loaded, then do this:

?- module_dotpdf(<module_name>,[]).

This will produce a PDF file <module_name>.pdf in the current directory. Often, the default layout program, dot, will produce a very wide graph. This can sometimes be alleviated by using the unflatten program from the Graphviz tools. In module_dotpdf/2, the default layout method does actually use unflatten without any parameters, but if this is not enough, you can provide values for the -f, -l and -c switches of unflatten (see the man page for unflatten for more details). For example, to produce a graph of callgraph itself, you can try the following:

$ swipl
?- use_module(library(callgraph)).
?- module_dotpdf(callgraph,[method(unflatten([fl(4),c(4)]))]).

More complex usage

Version 0.2.5 adds support for graphing multiple modules. For example, to graph modules callgraph and dot to a file called test.pdf, use

modules_dotpdf([callgraph,dot],[method(unflatten([fl(4),c(4)]))],test).

Version 0.3.2 adds support for node links by supplying the linkbase parameter. For example, if you have an SWI Prolog documentation server running on port 8000, then

?- module_render(callgraph,[linkbase('http://localhost:8000/help/source/doc_for?object='),
                            format(svg),method(unflatten([fl(4),c(4)]))]),
   www_open_url('callgraph.svg').

should produce open an SVG in your browser with clickable nodes that link to the documentation for each predicate.

Output formats

If you want the dot language source file, use module_dot/2 instead. The method option is then inapplicable.

The code can also produce rendered graphs in any format supported by Graphviz, but this functionality is not currently exposed.

Limitations

The graph compilation relies on prolog_walk_code/1 to do the actual code analysis. This does a good job in most cases, using meta-predicate declarations or inferred meta-predicates to detect many high-order calling patterns. Ironically enough, callgraph fails to analyse itself fully because prolog_walk_code/1 does not detect that it itself calls a given predicate for each call detected. Thus, in the example, there is no edge from assert_module_graph/1 to assert_edge/4.

Planned enhancements

Allow more control of subgraph layout and style. Handling of recorded database is a bit unsatisfactory. The system for dealing with style attributes is a bit messy and could be cleaned up.

Change log

Changes in v 0.4.0

  • Switched to using swipe for building shell pipelines
  • Now allow filename/1 option to determine full path of output PDF file.

Contents of pack "callgraph"

Pack contains 8 files holding a total of 104K bytes.