Erlang -- eprof

Tools

Reference Manual

Version 3.3.1

- User's Guide
- Reference Manual
- Release Notes
- PDF
- Top

- Expand All
- Contract All

### Table of Contents

- cover
  - Top of manual page
  - analyse/0
  - analyse/1
  - analyse/1
  - analyse/1
  - analyse/2
  - analyse/2
  - analyse/2
  - analyse/3
  - analyse_to_file/0
  - analyse_to_file/1
  - analyse_to_file/1
  - analyse_to_file/2
  - async_analyse_to_file/1
  - async_analyse_to_file/2
  - async_analyse_to_file/2
  - async_analyse_to_file/3
  - compile/1
  - compile/2
  - compile_beam/1
  - compile_beam_directory/0
  - compile_beam_directory/1
  - compile_directory/0
  - compile_directory/1
  - compile_directory/2
  - compile_module/1
  - compile_module/2
  - export/1
  - export/2
  - flush/1
  - import/1
  - imported/0
  - imported_modules/0
  - is_compiled/1
  - local_only/0
  - modules/0
  - reset/1
  - reset/0
  - start/0
  - start/1
  - stop/0
  - stop/1
  - which_nodes/0
- 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
  - analyze/0
  - analyze/1
  - analyze/2
  - log/1
  - profile/1
  - profile/2
  - profile/1
  - profile/2
  - profile/3
  - profile/4
  - profile/5
  - profile/6
  - start/0
  - start_profiling/1
  - start_profiling/2
  - start_profiling/3
  - stop/0
  - stop_profiling/0
- erlang.el
- fprof
  - Top of manual page
  - analyse/0
  - analyse/2
  - analyse/1
  - analyse/1
  - analyse/1
  - apply/2
  - apply/3
  - apply/3
  - apply/4
  - profile/0
  - profile/2
  - profile/1
  - profile/1
  - profile/1
  - start/0
  - stop/0
  - stop/1
  - trace/2
  - trace/2
  - trace/2
  - trace/1
  - trace/1
  - trace/1
  - trace/1
- instrument
  - Top of manual page
  - allocations/0
  - allocations/1
  - carriers/0
  - carriers/1
- lcnt
  - Top of manual page
  - apply/1
  - apply/2
  - apply/3
  - clear/0
  - clear/1
  - collect/0
  - collect/1
  - conflicts/0
  - conflicts/1
  - information/0
  - inspect/1
  - inspect/2
  - load/1
  - locations/0
  - locations/1
  - pid/2
  - pid/3
  - port/1
  - port/2
  - rt_clear/0
  - rt_clear/1
  - rt_collect/0
  - rt_collect/1
  - rt_mask/0
  - rt_mask/1
  - rt_mask/1
  - rt_mask/2
  - rt_opt/1
  - rt_opt/2
  - save/1
  - start/0
  - stop/0
  - swap_pid_keys/0
- make
  - Top of manual page
  - all/0
  - all/1
  - files/1
  - files/2
- tags
  - Top of manual page
  - dir/1
  - dirs/1
  - file/1
  - files/1
  - root/1
  - subdir/1
  - subdirs/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

# eprof

### Module

eprof

### Module Summary

A Time Profiling Tool for Erlang

### Description

The module eprof provides a set of functions for time profiling of Erlang programs to find out how the execution time is used. The profiling is done using the Erlang trace BIFs. Tracing of local function calls for a specified set of processes is enabled when profiling is begun, and disabled when profiling is stopped.

When using Eprof, expect a slowdown in program execution.

### Exports

start() -> {ok,Pid} | {error,Reason} |

### Types

Pid = pid()
Reason = {already_started,Pid}

Starts the Eprof server which holds the internal state of the collected data.

start_profiling(Rootset) -> profiling | {error, Reason} |

start_profiling(Rootset,Pattern) -> profiling | {error, Reason} | OTP R14B

start_profiling(Rootset,Pattern,Options) -> profiling | {error, Reason} | OTP R16B01

### Types

Rootset = [atom() | pid()]
Pattern = {Module, Function, Arity}
Module = Function = atom()
Arity = integer()
Options = [set_on_spawn]
Reason = term()

Starts profiling for the processes in Rootset (and any new processes spawned from them). Information about activity in any profiled process is stored in the Eprof database.

Rootset is a list of pids and registered names.

The function returns profiling if tracing could be enabled for all processes in Rootset, or error otherwise.

A pattern can be selected to narrow the profiling. For instance a specific module can be selected, and only the code executed in that module will be profiled.

The set_on_spawn option will active call time tracing for all processes spawned by processes in the rootset. This is the default behaviour.

stop_profiling() -> profiling_stopped | profiling_already_stopped |

Stops profiling started with start_profiling/1 or profile/1.

profile(Fun) -> profiling | {error, Reason} |

profile(Fun, Options) -> profiling | {error, Reason} |

profile(Rootset) -> profiling | {error, Reason} |

profile(Rootset,Fun) -> {ok, Value} | {error,Reason} |

profile(Rootset,Fun,Pattern) -> {ok, Value} | {error, Reason} | OTP R14B

profile(Rootset,Module,Function,Args) -> {ok, Value} | {error, Reason} |

profile(Rootset,Module,Function,Args,Pattern) -> {ok, Value} | {error, Reason} | OTP R14B

profile(Rootset,Module,Function,Args,Pattern,Options) -> {ok, Value} | {error, Reason} | OTP R16B01

### Types

Rootset = [atom() | pid()]
Fun = fun() -> term() end
Pattern = {Module, Function, Arity}
Module = Function = atom()
Args = [term()]
Arity = integer()
Options = [set_on_spawn]
Value = Reason = term()

This function first spawns a process P which evaluates Fun() or apply(Module,Function,Args). Then, it starts profiling for P and the processes in Rootset (and any new processes spawned from them). Information about activity in any profiled process is stored in the Eprof database.

Rootset is a list of pids and registered names.

If tracing could be enabled for P and all processes in Rootset, the function returns {ok,Value} when Fun()/apply returns with the value Value, or {error,Reason} if Fun()/apply fails with exit reason Reason. Otherwise it returns {error, Reason} immediately.

The set_on_spawn option will active call time tracing for all processes spawned by processes in the rootset. This is the default behaviour.

The programmer must ensure that the function given as argument is truly synchronous and that no work continues after the function has returned a value.

analyze() -> ok | OTP R14B

analyze(Type) -> ok | OTP R14B

analyze(Type,Options) -> ok | OTP R14B

### Types

Type = procs | total
Options = [{filter, Filter} | {sort, Sort}
Filter = [{calls, integer()} | {time, float()}]
Sort = time | calls | mfa

Call this function when profiling has been stopped to display the results per process, that is:

- how much time has been used by each process, and
- in which function calls this time has been spent.

Call analyze with total option when profiling has been stopped to display the results per function call, that is in which function calls the time has been spent.

Time is shown as percentage of total time and as absolute time.

log(File) -> ok |

### Types

File = atom() | string()

This function ensures that the results displayed by analyze/0,1,2 are printed both to the file File and the screen.

stop() -> stopped |

Stops the Eprof server.