View Source cprof (tools v4.0)

A simple Call Count Profiling Tool using breakpoints for minimal runtime performance impact.

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.

See Also

eprof(3), fprof(3), erlang(3), User's Guide

Summary

Functions

Equivalent to analyse/2

Equivalent to analyse/2

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

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})).

Equivalent to pause/3

Equivalent to pause/3

Pause call counters for matching functions in matching modules. The FS argument can be used to specify the first argument to erlang:trace_pattern/3.

Equivalent to restart/3

Restart call counters for the matching functions in matching modules that are call count traced. The FS argument can be used to specify the first argument to erlang:trace_pattern/3.

Start call count tracing for all functions in all modules, and also for all functions in modules to be loaded. This is the same as (start({'_','_','_'})+start({on_load})).

Equivalent to start/3

Equivalent to start/3

Start call count tracing for matching functions in matching modules. The FS argument can be used to specify the first argument to erlang:trace_pattern/3, for example on_load.

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

Equivalent to stop/3

Equivalent to stop/3

Stop call count tracing for matching functions in matching modules. The FS argument can be used to specify the first argument to erlang:trace_pattern/3, for example on_load.

Types

Link to this type

func_analysis_list()

View Source (not exported)
-type func_analysis_list() :: [{mfa(), FuncCallCount :: non_neg_integer()}].
Link to this type

mod_analysis()

View Source (not exported)
-type mod_analysis() ::
    {Mod :: module(), ModCallCount :: non_neg_integer(), FuncAnalysisList :: func_analysis_list()}.
Link to this type

mod_analysis_list()

View Source (not exported)
-type mod_analysis_list() :: [mod_analysis()].

Functions

-spec analyse() -> {AllCallCount :: non_neg_integer(), ModAnalysisList :: mod_analysis_list()}.

Equivalent to analyse/2

-spec analyse(Limit) -> {AllCallCount :: non_neg_integer(), ModAnalysisList :: mod_analysis_list()}
           when Limit :: non_neg_integer();
       (Mod) -> ModAnalysis :: mod_analysis() when Mod :: module().

Equivalent to analyse/2

-spec analyse(Mod, Limit) -> ModAnalysis :: mod_analysis()
           when Mod :: module(), Limit :: non_neg_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.

-spec pause() -> non_neg_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})).

See also pause/1..3 below.

-spec pause(FuncSpec) -> non_neg_integer() when FuncSpec :: (Mod :: module()) | mfa() | {FS :: term()}.

Equivalent to pause/3

-spec pause(Mod, Func) -> non_neg_integer() when Mod :: module(), Func :: atom().

Equivalent to pause/3

-spec pause(Mod, Func, Arity) -> non_neg_integer()
         when Mod :: module(), Func :: atom(), Arity :: arity().

Pause call counters for matching functions in matching modules. The FS argument can be used to specify the first argument to erlang:trace_pattern/3.

The call counters for all matching functions that has got call count breakpoints are paused at their current count.

Return the number of matching functions that can have call count breakpoints, the same as start/0..3 with the same arguments would have returned.

-spec restart() -> non_neg_integer().

Equivalent to restart/3

-spec restart(FuncSpec) -> non_neg_integer() when FuncSpec :: (Mod :: module()) | mfa() | {FS :: term()}.

Equivalent to restart/3

-spec restart(Mod, Func) -> non_neg_integer() when Mod :: module(), Func :: atom().

Equivalent to restart/3

Link to this function

restart(Mod, Func, Arity)

View Source
-spec restart(Mod, Func, Arity) -> non_neg_integer()
           when Mod :: module(), Func :: atom(), Arity :: arity().

Restart call counters for the matching functions in matching modules that are call count traced. The FS argument can be used to specify the first argument to erlang:trace_pattern/3.

The call counters for all matching functions that has got call count breakpoints are set to zero and running.

Return the number of matching functions that can have call count breakpoints, the same as start/0..3 with the same arguments would have returned.

-spec start() -> non_neg_integer().

Start call count tracing for all functions in all modules, and also for all functions in modules to be loaded. This is the same as (start({'_','_','_'})+start({on_load})).

See also start/1..3 below.

-spec start(FuncSpec) -> non_neg_integer() when FuncSpec :: (Mod :: module()) | mfa() | {FS :: term()}.

Equivalent to start/3

-spec start(Mod, Func) -> non_neg_integer() when Mod :: module(), Func :: atom().

Equivalent to start/3

-spec start(Mod, Func, Arity) -> non_neg_integer()
         when Mod :: module(), Func :: atom(), Arity :: arity().

Start call count tracing for matching functions in matching modules. The FS argument can be used to specify the first argument to erlang:trace_pattern/3, for example on_load.

Set call count breakpoints on the matching functions that has no call count breakpoints. Call counters are set to zero and running for all matching functions.

Return the number of matching functions that has got call count breakpoints.

-spec stop() -> non_neg_integer().

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

See also stop/1..3 below.

-spec stop(FuncSpec) -> non_neg_integer() when FuncSpec :: (Mod :: module()) | mfa() | {FS :: term()}.

Equivalent to stop/3

-spec stop(Mod, Func) -> non_neg_integer() when Mod :: module(), Func :: atom().

Equivalent to stop/3

-spec stop(Mod, Func, Arity) -> non_neg_integer() when Mod :: module(), Func :: atom(), Arity :: arity().

Stop call count tracing for matching functions in matching modules. The FS argument can be used to specify the first argument to erlang:trace_pattern/3, for example on_load.

Remove call count breakpoints from the matching functions that has call count breakpoints.

Return the number of matching functions that can have call count breakpoints, the same as start/0..3 with the same arguments would have returned.