Erlang Fprof Output Confusing? Try KCachegrind.

written in Erlang

Your Erlang code is perfect, but to find out why other peoples code runs dog slow you probably profile the code with fprof like this:

1
2
3
(node@host)1> fprof:apply(module, function, [arguments]).
(node@host)1> fprof:profile().
(node@host)1> fprof:analyse({dest, "outfile.fprof"}).

The printout of fprof analyse is a text dump of the result, which can grow over 1000 lines and contains a lot of noise which makes it hard to locate the bottlenecks. Below a truncated sample of an actual fprof trace.

KCachegrind

KCachegrind to the rescue! With this tool you can visually inspect the fprof analyse result with sorting, a fancy call graph view, callee map and more.

images

As KCachegrind can’t read fprof analysis output directly, you need to convert it first to the callgrind format with the Erlgrind script by Isac Sacchi e Souza.

1
$ ./erlgrind outfile.fprof callgrind.001

KCachegrind & Erlgrind Installation

For installation of KCachegrind on my Mac I use Homebrew, a package manager for OSX. Notice that you install qcachegrind, the QT version of KCachegrind.

1
2
3
$ brew install qcachegrind
$ brew instal graphviz
$ sudo ln -s /usr/local/bin/dot /usr/bin/dot

Installing the Erlgrind (Github) script:

1
2
3
$ curl -O "https://raw.github.com/isacssouza/erlgrind/master/src/erlgrind"
$ chmod +x erlgrind
$ mv erlgrind /usr/local/bin/

And open qcachegrind:

1
$ open ~/Applications/qcachegrind.app

Enjoy!


Comments