View Source eprof (tools v4.0)

A Time Profiling Tool for Erlang

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.

Summary

Functions

Equivalent to analyze/2

Equivalent to analyze/2

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

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

Equivalent to profile/6

Equivalent to profile/6

Equivalent to profile/6

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.

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

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.

Stops the Eprof server.

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

Types

Link to this type

analyze_type()

View Source (not exported)
-type analyze_type() :: procs | total.
Link to this type

trace_pattern_mfa()

View Source (not exported)
-type trace_pattern_mfa() :: {atom(), atom(), arity() | '_'}.

Functions

Link to this function

analyze()

View Source (since OTP R14B)
-spec analyze() -> ok | nothing_to_analyze.

Equivalent to analyze/2

Link to this function

analyze(Type)

View Source (since OTP R14B)
-spec analyze(Type) -> ok | nothing_to_analyze when Type :: analyze_type().

Equivalent to analyze/2

Link to this function

analyze(Type, Options)

View Source (since OTP R14B)
-spec analyze(Type, Options) -> ok | nothing_to_analyze
           when
               Type :: analyze_type(),
               Options :: [Option],
               Option :: {filter, Filter} | {sort, Sort},
               Filter :: [{calls, non_neg_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.

-spec log(File) -> ok when File :: atom() | file:filename().

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

Link to this function

profile/1

View Source (since OTP R14B,OTP R16B01)
-spec profile(Fun) -> {ok, Value} | {error, Reason}
           when Fun :: fun(() -> term()), Value :: term(), Reason :: term();
       (Rootset) -> profiling | {error, Reason} when Rootset :: [atom() | pid()], Reason :: term().

Equivalent to profile/6

Link to this function

profile/2

View Source (since OTP R14B,OTP R16B01)
-spec profile(Fun, Options) -> {ok, Value} | {error, Reason}
           when
               Fun :: fun(() -> term()),
               Options :: [set_on_spawn | {set_on_spawn, boolean()}],
               Value :: term(),
               Reason :: term();
       (Rootset, Fun) -> {ok, Value} | {error, Reason}
           when
               Rootset :: [atom() | pid()],
               Fun :: fun(() -> term()),
               Value :: term(),
               Reason :: term().

Equivalent to profile/6

Link to this function

profile(Rootset, Fun, Pattern)

View Source (since OTP R14B,OTP R16B01)
-spec profile(Rootset, Fun, Pattern) -> {ok, Value} | {error, Reason}
           when
               Rootset :: [atom() | pid()],
               Fun :: fun(() -> term()),
               Pattern :: trace_pattern_mfa(),
               Value :: term(),
               Reason :: term().

Equivalent to profile/6

Link to this function

profile/4

View Source (since OTP R14B,OTP R16B01)
-spec profile(Rootset, Module, Function, Args) -> {ok, Value} | {error, Reason}
           when
               Rootset :: [atom() | pid()],
               Module :: module(),
               Function :: atom(),
               Args :: [term()],
               Value :: term(),
               Reason :: term();
       (Rootset, Fun, Pattern, Options) -> {ok, Value} | {error, Reason}
           when
               Rootset :: [atom() | pid()],
               Fun :: fun(() -> term()),
               Pattern :: trace_pattern_mfa(),
               Options :: [set_on_spawn | {set_on_spawn, boolean()}],
               Value :: term(),
               Reason :: term().

Equivalent to profile/6

Link to this function

profile(Rootset, Module, Function, Args, Pattern)

View Source (since OTP R14B,OTP R16B01)
-spec profile(Rootset, Module, Function, Args, Pattern) -> {ok, Value} | {error, Reason}
           when
               Rootset :: [atom() | pid()],
               Module :: module(),
               Function :: atom(),
               Args :: [term()],
               Pattern :: trace_pattern_mfa(),
               Value :: term(),
               Reason :: term().

Equivalent to profile/6

Link to this function

profile(Rootset, Module, Function, Args, Pattern, Options)

View Source (since OTP R14B,OTP R16B01)
-spec profile(Rootset, Module, Function, Args, Pattern, Options) -> {ok, Value} | {error, Reason}
           when
               Rootset :: [atom() | pid()],
               Module :: module(),
               Function :: atom(),
               Args :: [term()],
               Pattern :: trace_pattern_mfa(),
               Options :: [set_on_spawn | {set_on_spawn, boolean()}],
               Value :: term(),
               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.

-spec start() -> {ok, Pid} | {error, Reason} when Pid :: pid(), Reason :: {already_started, Pid}.

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

Link to this function

start_profiling(Rootset)

View Source (since OTP R14B,OTP R16B01)
-spec start_profiling(Rootset) -> profiling | {error, Reason}
                   when Rootset :: [atom() | pid()], Reason :: term().

Equivalent to start_profiling/3

Link to this function

start_profiling(Rootset, Pattern)

View Source (since OTP R14B,OTP R16B01)
-spec start_profiling(Rootset, Pattern) -> profiling | {error, Reason}
                   when
                       Rootset :: [atom() | pid()],
                       Pattern :: trace_pattern_mfa(),
                       Reason :: term().

Equivalent to start_profiling/3

Link to this function

start_profiling(Rootset, Pattern, Options)

View Source (since OTP R14B,OTP R16B01)
-spec start_profiling(Rootset, Pattern, Options) -> profiling | {error, Reason}
                   when
                       Rootset :: [atom() | pid()],
                       Pattern :: trace_pattern_mfa(),
                       Options :: [set_on_spawn | {set_on_spawn, boolean()}],
                       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.

-spec stop() -> stopped.

Stops the Eprof server.

-spec stop_profiling() -> profiling_stopped | profiling_already_stopped.

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