cprof

The cprof module is used to profile a program
to find out how many times different functions are called.
Breakpoints similar to local call trace, but containing a
counter, are used to minimise runtime performance impact.

Since breakpoints are used there is no need for special
compilation of any module to be profiled. For now these
breakpoints can only be set on BEAM code so BIFs
cannot be call count traced.

The size of the call counters is the host machine word
size. One bit is used when pausing the counter, so the maximum
counter value for a 32-bit host is 2147483647.

The profiling result is delivered as a term containing a
sorted list of entries, one per module. Each module entry
contains a sorted list of functions. The sorting order in both
cases is of decreasing call count.

Call count tracing is very lightweight compared to other forms
of tracing since no trace message has to be generated. Some
measurements indicates performance degradation in the vicinity
of 10 percent.

Functions

analyse() -> {AllCallCount, ModAnalysisList}

analyse(Limit) -> {AllCallCount, ModAnalysisList}

analyse(Mod) -> ModAnlysis

analyse(Mod, Limit) -> ModAnalysis

Limit = integer()

Mod = atom()

AllCallCount = integer()

ModAnalysisList = [ModAnalysis]

ModAnalysis = {Mod, ModCallCount, FuncAnalysisList}

ModCallCount = integer()

FuncAnalysisList = [{{Mod, Func, Arity}, FuncCallCount}]

Func = atom()

Arity = integer()

FuncCallCount = integer()

Collects and analyses the call counters presently in the
node for either module Mod, or for all modules
(except cprof itself), and returns:

FuncAnalysisList

A list of tuples, one for each function in a module, in
decreasing FuncCallCount order.

ModCallCount

The sum of FuncCallCount values for all
functions in module Mod.

AllCallCount

The sum of ModCallCount values for all modules
concerned in ModAnalysisList.

ModAnalysisList

A list of tuples, one for each module except
cprof, in decreasing ModCallCount order.

If call counters are still running while
analyse/0..2 is executing, you might get an
inconsistent result. This happens if the process executing
analyse/0..2 gets scheduled out so some other process
can increment the counters that are being analysed, Calling
pause() before analysing takes care of the problem.

If the Mod argument is given, the result contains a
ModAnalysis tuple for module Mod only,
otherwise the result contains one ModAnalysis tuple
for all modules returned from code:all_loaded()
except cprof itself.

All functions with a FuncCallCount lower than
Limit are excluded from FuncAnalysisList. They
are still included in ModCallCount, though.
The default value for Limit is 1.

pause() -> integer()

Pause call count tracing for all functions in all modules
and stop it for all functions in modules to be
loaded. This is the same as
(pause({'_','_','_'})+stop({on_load})).