View Source tr (erlang_doctor v0.2.6)

Erlang Doctor API module.

Summary

Types

Total accumulated time.
Total number of aggregated calls.
Number of occurrences of a given call tree.
Unique, auto-incremented identifier of a tr/0 record.

Initialization options.

Maximum number of items.
Message event types to trace. Default: none.
Module, function and arguments.
Specifies traced modules and/or individual functions. Default: [].

Condition checked before collecting message traces for a process.

Total own time (without other called functions).
A list of processes to trace. Default: all.

Predicate returning true for matching traces.

Options for trace ranges.

Recipient pid with a boolean indicating if it exists.
Result of a function call.

Trace selector function.

ETS table name.
Merge tracebacks into a tree or return a list (default) of them.

Traceback options.

Order of calls in each returned traceback. Default: top_down.
Which tracebacks to return if they overlap. Default: shortest.
Multiple tracebacks merged into a tree structure.

Options for repeated call tree statistics.

Specifies the behaviour for overlapping call trees.

Trace record, storing one collected trace event.

Source of traces: an ETS table or a list of traces. Default: tab/0.
Options for tracing.

Function call tree node.

Function call tree with its accumulated time and number of repetitions.

Functions

Returns all module names for an application.
Returns call time statistics for traces selected from tab/0.

See also: call_stat/2.

Returns call time statistics for traces selected from tr_source/0.

Removes all traces from the current ETS table.

Looks for DataVal in #tr.data.

Executes the function call for the provided tr/0 record or index.
Dumps the tab/0 table to a file.
Returns matching traces from tab/0.
Returns matching traces from tr_source/0.

Loads an ETS trace table from a file, and makes it the current table.

Returns the tr/0 record from tab/0 for an index.
Replaces arity with Args in an MFA tuple.
Replaces arguments with arity in an MFA tuple.

Prints sorted call time statistics for the selected traces from tab/0.

Returns a list of traces from tab/0 between the first matched call and the corresponding return.

Returns a list of traces from tr_source/0 between the first matched call and the corresponding return.

Returns lists of traces from tab/0 between matched calls and corresponding returns.

See also: ranges/2.

Returns lists of traces from tr_source/0 between matched calls and corresponding returns.
Returns a list of all collected traces from tab/0.
Selects data from matching traces from tab/0 with ets:fun2ms(F).

Selects data from matching traces from tab/0 with ets:fun2ms(F).

Sets a new ETS table for collecting traces, creating it if it doesn't exist.

Returns sorted call time statistics for the selected traces from tab/0.

Starts tr as a stand-alone gen_server. Intended for interactive use.

See also: start/1.

Starts tr as a stand-alone gen_server. Intended for interactive use.

Starts tr as part of a supervision tree.

See also: start/1.

Start tr as part of a supervision tree.

See also: start/1.

Stops the whole tr server process.

Stops tracing, disabling all trace specs.

Returns the name of the current ETS trace table in use.
Returns statistics of repeated function call trees that took most time.

See also: top_call_trees/1.

Returns statistics of repeated function call trees that took most time.

Starts tracing of the specified functions/modules and/or message events.

Starts tracing of the specified functions/modules in specific processes.
Starts tracing of all modules in an application.
Starts tracing of all modules in all provided applications.

Returns traceback of the first matching trace from tr_source/0.

Returns traceback of the first matching trace from tr_source/0.

Returns tracebacks of all matching traces from tab/0.

See also: tracebacks/2.

Returns tracebacks of all matching traces from tr_source/0.
Returns human-readable timestamp according to RFC 3339.

Types

-type acc_time() :: non_neg_integer().
Total accumulated time.
-type call() :: {call, {module(), atom(), list()}}.
-type call_count() :: non_neg_integer().
Total number of aggregated calls.
-type call_tree_count() :: pos_integer().
Number of occurrences of a given call tree.
Link to this type

call_tree_stat_options/0

View Source
-type call_tree_stat_options() :: #{tab => table()}.
Link to this type

call_tree_stat_state/0

View Source
-type call_tree_stat_state() :: #{pid_states := map(), tab := ets:tid()}.
-type erlang_trace_flags() :: [call | timestamp | send | 'receive'].
-type index() :: pos_integer().
Unique, auto-incremented identifier of a tr/0 record.
-type init_options() :: #{tab => table(), index => index(), limit => limit()}.

Initialization options.

tab is the ETS table used for storing traces (default: trace). index is the index value of the first inserted trace (default: 1). When size of tab reaches the optional limit, tracing is stopped.
-type limit() :: pos_integer() | infinity.
Maximum number of items.
-type message_event_types() :: send | recv | all | none.
Message event types to trace. Default: none.
-type mfargs() :: {module(), atom(), list()}.
Module, function and arguments.
-type module_spec() :: [module() | mfa()].
Specifies traced modules and/or individual functions. Default: [].
-type msg_trigger() :: after_traced_call | always.

Condition checked before collecting message traces for a process.

after_traced_call (default) means that a process needs to call at least one traced function before its message events start being collected. always means that messages for all traced processes are collected.
-type own_time() :: non_neg_integer().
Total own time (without other called functions).
-type pid_call_state() :: [tree() | call()].
-type pids() :: [pid()] | all.
A list of processes to trace. Default: all.
-type pred() :: fun((tr()) -> boolean()).

Predicate returning true for matching traces.

For other traces it can return a different value or fail.
-type range_options() :: #{tab => tr_source(), max_depth => limit()}.

Options for trace ranges.

Optional limit is the maximum depth of calls in the returned ranges. All traces (including messages) exceeding that depth are skipped.
-type recipient() :: {pid(), boolean()}.
Recipient pid with a boolean indicating if it exists.
-type result() :: {return | exception, any()}.
Result of a function call.
-type selector(Data) :: fun((tr()) -> Data).

Trace selector function.

For selected traces, it returns Data. For other traces, it should fail.
-type simple_tr() :: call() | result().
-type state() ::
    #{tab := table(),
      index := index(),
      limit := limit(),
      trace := none | trace_spec(),
      tracer_pid := none | pid()}.
-type table() :: atom().
ETS table name.
-type tb_acc() :: tb_acc_tree() | tb_acc_list().
-type tb_acc_list() :: [[tr()]].
-type tb_acc_tree() :: [{tr(), tb_acc_tree()}].
-type tb_format() :: tree | list.
Merge tracebacks into a tree or return a list (default) of them.
-type tb_options() ::
    #{tab => tr_source(),
      output => tb_output(),
      format => tb_format(),
      order => tb_order(),
      limit => limit()}.

Traceback options.

Optional limit is the maximum number of tracebacks to collect before filtering them according to output.
-type tb_order() :: top_down | bottom_up.
Order of calls in each returned traceback. Default: top_down.
-type tb_output() :: shortest | longest | all.
Which tracebacks to return if they overlap. Default: shortest.
-type tb_tree() :: [tr() | {tr(), tb_tree()}].
Multiple tracebacks merged into a tree structure.
Link to this type

top_call_trees_options/0

View Source
-type top_call_trees_options() ::
    #{max_size => pos_integer(),
      min_count => call_tree_count(),
      min_time => acc_time(),
      output => top_call_trees_output()}.

Options for repeated call tree statistics.

min_time is an optional minimum accumulated time of a tree. min_count (default: 2) specifies minimum number of repetitions of a tree. max_size (default: 10) specifies maximum number of listed call trees.
Link to this type

top_call_trees_output/0

View Source
-type top_call_trees_output() :: reduced | complete.

Specifies the behaviour for overlapping call trees.

reduced (default) hides subtrees, while complete keeps them.
-type tr() :: #tr{}.

Trace record, storing one collected trace event.

Record fields:
  • index - index/0
  • pid - process in which the traced event occurred, erlang:pid()
  • event - call, return or exception for function traces; send or recv for messages.
  • mfa - erlang:mfa() for function traces; no_mfa for messages.
  • data - Argument list (for calls), returned value (for returns) or class and value (for exceptions).
  • ts - Timestamp in microseconds.
  • info - For send events it is a recipient/0 tuple; otherwise no_info.
-type tr_source() :: table() | [tr()].
Source of traces: an ETS table or a list of traces. Default: tab/0.
-type trace_options() ::
    #{modules => module_spec(),
      pids => pids(),
      msg => message_event_types(),
      msg_trigger => msg_trigger()}.
Options for tracing.
-type trace_spec() ::
    #{modules := module_spec(),
      pids := pids(),
      msg := message_event_types(),
      msg_trigger := msg_trigger()}.
-type traced_pids_tab() :: none | ets:table().
-type tree() :: #node{}.

Function call tree node.

Record fields:
  • module - module name
  • function - function name
  • args - argument list
  • children - a list of child nodes, each of them being tree/0
  • result - return value or exception, result/0
-type tree_item() :: {acc_time(), call_tree_count(), tree()}.
Function call tree with its accumulated time and number of repetitions.

Functions

-spec app_modules(atom()) -> [module()].
Returns all module names for an application.
-spec call_stat(selector(Key)) -> #{Key => {call_count(), acc_time(), own_time()}}.
Returns call time statistics for traces selected from tab/0.

See also: call_stat/2.

-spec call_stat(selector(Key), tr_source()) -> #{Key => {call_count(), acc_time(), own_time()}}.

Returns call time statistics for traces selected from tr_source/0.

Calls are aggregated by Key returned by KeyF.
-spec clean() -> ok.
Removes all traces from the current ETS table.
Link to this function

contains_data(DataVal, Tr)

View Source
-spec contains_data(term(), tr()) -> boolean().

Looks for DataVal in #tr.data.

DataVal can occur in (possibly nested) tuples, maps or lists.
-spec do(tr()) -> term().
Executes the function call for the provided tr/0 record or index.
-spec dump(file:name_all()) -> ok | {error, any()}.
Dumps the tab/0 table to a file.
-spec filter(pred()) -> [tr()].
Returns matching traces from tab/0.
-spec filter(pred(), tr_source()) -> [tr()].
Returns matching traces from tr_source/0.
-spec load(file:name_all()) -> {ok, table()} | {error, any()}.

Loads an ETS trace table from a file, and makes it the current table.

Fails if the table already exists.
-spec lookup(index()) -> tr().
Returns the tr/0 record from tab/0 for an index.
-spec mfargs(mfa(), list()) -> mfargs().
Replaces arity with Args in an MFA tuple.
-spec mfarity(mfa() | mfargs()) -> mfa().
Replaces arguments with arity in an MFA tuple.
-spec range(pred() | index() | tr()) -> [tr()].

Returns a list of traces from tab/0 between the first matched call and the corresponding return.

Matching can be done with a predicate function, an index value or a tr/0 record. Fails if no trace is matched.

See also: range/2.

-spec range(pred(), range_options()) -> [tr()].

Returns a list of traces from tr_source/0 between the first matched call and the corresponding return.

Fails if no call is matched.
-spec ranges(pred()) -> [[tr()]].
Returns lists of traces from tab/0 between matched calls and corresponding returns.

See also: ranges/2.

-spec ranges(pred(), range_options()) -> [[tr()]].
Returns lists of traces from tr_source/0 between matched calls and corresponding returns.
Link to this function

reduce_call_trees(TreeTab)

View Source
-spec reduce_call_trees(ets:tid()) -> true.
-spec select() -> [tr()].
Returns a list of all collected traces from tab/0.
-spec select(selector(Data)) -> [Data].
Selects data from matching traces from tab/0 with ets:fun2ms(F).
-spec select(selector(Data), term()) -> [Data].

Selects data from matching traces from tab/0 with ets:fun2ms(F).

Additionally, the selected traces have to contain DataVal in #tr.data. DataVal can occur in (possibly nested) tuples, maps or lists.
-spec set_tab(table()) -> ok.
Sets a new ETS table for collecting traces, creating it if it doesn't exist.
-spec sorted_call_stat(selector(Key)) -> [{Key, call_count(), acc_time(), own_time()}].

Returns sorted call time statistics for the selected traces from tab/0.

The statistics are sorted according to acc_time/0, descending.

See also: call_stat/1.

-spec start() -> {ok, pid()}.
Starts tr as a stand-alone gen_server. Intended for interactive use.

See also: start/1.

-spec start(init_options()) -> {ok, pid()}.

Starts tr as a stand-alone gen_server. Intended for interactive use.

You can override the selected Opts.
-spec start_link() -> {ok, pid()}.
Starts tr as part of a supervision tree.

See also: start/1.

-spec start_link(init_options()) -> {ok, pid()}.
Start tr as part of a supervision tree.

See also: start/1.

-spec stop() -> ok.
Stops the whole tr server process.
-spec stop_tracing() -> ok | {error, not_tracing}.

Stops tracing, disabling all trace specs.

Any future messages from the Erlang tracer will be ignored.
-spec tab() -> table().
Returns the name of the current ETS trace table in use.
-spec top_call_trees() -> [tree_item()].
Returns statistics of repeated function call trees that took most time.

See also: top_call_trees/1.

-spec top_call_trees(top_call_trees_options()) -> [tree_item()].

Returns statistics of repeated function call trees that took most time.

Two call trees repeat if they contain the same function calls and returns in the same order taking the same arguments and returning the same values, respectively. The results are sorted according to accumulated time.
-spec trace(module_spec() | trace_options()) -> ok | {error, already_tracing}.

Starts tracing of the specified functions/modules and/or message events.

You can either provide a list of modules/functions or a more generic map of options.
-spec trace(module_spec(), pids()) -> ok | {error, already_tracing}.
Starts tracing of the specified functions/modules in specific processes.
-spec trace_app(atom()) -> ok | {error, already_tracing}.
Starts tracing of all modules in an application.
-spec trace_apps([atom()]) -> ok | {error, already_tracing}.
Starts tracing of all modules in all provided applications.
-spec traceback(pred() | index() | tr()) -> [tr()].

Returns traceback of the first matching trace from tr_source/0.

Matching can be done with a predicate function, an index value or a tr record. Fails if no trace is matched.

See also: traceback/2.

Link to this function

traceback(PredF, Options)

View Source
-spec traceback(pred(), tb_options()) -> [tr()].

Returns traceback of the first matching trace from tr_source/0.

Fails if no trace is matched. The options limit and format do not apply.
-spec tracebacks(pred()) -> [[tr()]] | tb_tree().
Returns tracebacks of all matching traces from tab/0.

See also: tracebacks/2.

Link to this function

tracebacks(PredF, Options)

View Source
-spec tracebacks(pred(), tb_options()) -> [[tr()]] | tb_tree().
Returns tracebacks of all matching traces from tr_source/0.
-spec ts(tr()) -> string().
Returns human-readable timestamp according to RFC 3339.