Erlang -- cprof

User's Guide
Reference Manual
Release Notes
PDF
Top

Tools
Reference Manual
Version 2.6.6.3

Expand All
Contract All

Table of Contents

- cover
  - Top of manual page
  - start/0
  - start/1
  - compile/1
  - compile/2
  - compile_module/1
  - compile_module/2
  - compile_directory/0
  - compile_directory/1
  - compile_directory/2
  - compile_beam/1
  - compile_beam_directory/0
  - compile_beam_directory/1
  - analyse/1
  - analyse/2
  - analyse/2
  - analyse/3
  - analyse_to_file/1
  - analyse_to_file/2
  - analyse_to_file/2
  - analyse_to_file/3
  - async_analyse_to_file/1
  - async_analyse_to_file/2
  - async_analyse_to_file/2
  - async_analyse_to_file/3
  - modules/0
  - imported_modules/0
  - imported/0
  - which_nodes/0
  - is_compiled/1
  - reset/1
  - reset/0
  - export/1
  - export/2
  - import/1
  - stop/0
  - stop/1
- cprof
  - Top of manual page
  - analyse/0
  - analyse/1
  - analyse/1
  - analyse/2
  - pause/0
  - pause/1
  - pause/2
  - pause/3
  - restart/0
  - restart/1
  - restart/2
  - restart/3
  - start/0
  - start/1
  - start/2
  - start/3
  - stop/0
  - stop/1
  - stop/2
  - stop/3
- eprof
  - Top of manual page
  - start/0
  - start_profiling/1
  - start_profiling/2
  - stop_profiling/0
  - profile/1
  - profile/1
  - profile/2
  - profile/3
  - profile/4
  - profile/5
  - analyze/0
  - analyze/1
  - analyze/2
  - log/1
  - stop/0
- erlang.el
- fprof
  - Top of manual page
  - start/0
  - stop/0
  - stop/1
  - apply/2
  - apply/3
  - apply/3
  - apply/4
  - trace/2
  - trace/2
  - trace/2
  - trace/1
  - trace/1
  - trace/1
  - trace/1
  - profile/0
  - profile/2
  - profile/1
  - profile/1
  - profile/1
  - analyse/0
  - analyse/2
  - analyse/1
  - analyse/1
  - analyse/1
- instrument
  - Top of manual page
  - allocator_descr/2
  - block_header_size/1
  - class_descr/2
  - descr/1
  - holes/1
  - mem_limits/1
  - memory_data/0
  - memory_status/1
  - read_memory_data/1
  - read_memory_status/1
  - sort/1
  - store_memory_data/1
  - store_memory_status/1
  - sum_blocks/1
  - type_descr/2
  - type_no_range/1
- lcnt
  - Top of manual page
  - start/0
  - stop/0
  - collect/0
  - collect/1
  - clear/0
  - clear/1
  - conflicts/0
  - conflicts/1
  - locations/0
  - locations/1
  - inspect/1
  - inspect/2
  - information/0
  - swap_pid_keys/0
  - load/1
  - save/1
  - apply/1
  - apply/2
  - apply/3
  - pid/2
  - pid/3
  - port/1
  - port/2
  - rt_collect/0
  - rt_collect/1
  - rt_clear/0
  - rt_clear/1
  - rt_opt/1
  - rt_opt/2
- make
  - Top of manual page
  - all/0
  - all/1
  - files/1
  - files/2
- tags
  - Top of manual page
  - file/1
  - files/1
  - dir/1
  - dirs/1
  - subdir/1
  - subdirs/1
  - root/1
- xref
  - Top of manual page
  - add_application/2
  - add_directory/2
  - add_module/2
  - add_release/2
  - analyze/2
  - d/1
  - forget/1
  - forget/2
  - format_error/1
  - get_default/1
  - get_default/2
  - get_library_path/1
  - info/1
  - info/2
  - info/3
  - m/1
  - m/1
  - q/2
  - remove_application/2
  - remove_module/2
  - remove_release/2
  - replace_application/3
  - replace_module/3
  - set_default/3
  - set_default/2
  - set_library_path/2
  - start/1
  - start/2
  - stop/1
  - update/1
  - variables/1

# cprof

### MODULE

cprof

### MODULE SUMMARY

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

### DESCRIPTION

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.

### EXPORTS

analyse() -> {AllCallCount, ModAnalysisList}
analyse(Limit) -> {AllCallCount, ModAnalysisList}
analyse(Mod) -> ModAnlysis
analyse(Mod, Limit) -> ModAnalysis

Types:

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

See also pause/1..3 below.

pause(FuncSpec) -> integer()
pause(Mod, Func) -> integer()
pause(Mod, Func, Arity) -> integer()

Types:

FuncSpec = Mod | {Mod,Func,Arity}, {FS}
Mod = atom()
Func = atom()
Arity = integer()
FS = term()

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. See erlang(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.

restart() -> integer()
restart(FuncSpec) -> integer()
restart(Mod, Func) -> integer()
restart(Mod, Func, Arity) -> integer()

Types:

FuncSpec = Mod | {Mod,Func,Arity}, {FS}
Mod = atom()
Func = atom()
Arity = integer()
FS = term()

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. See erlang(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.

start() -> 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.

start(FuncSpec) -> integer()
start(Mod, Func) -> integer()
start(Mod, Func, Arity) -> integer()

Types:

FuncSpec = Mod | {Mod,Func,Arity}, {FS}
Mod = atom()
Func = atom()
Arity = integer()
FS = term()

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. See erlang(3).

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.

stop() -> 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.

stop(FuncSpec) -> integer()
stop(Mod, Func) -> integer()
stop(Mod, Func, Arity) -> integer()

Types:

FuncSpec = Mod | {Mod,Func,Arity}, {FS}
Mod = atom()
Func = atom()
Arity = integer()
FS = term()

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. See erlang(3).

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.

### See Also

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