tr (erlang_doctor v0.3.2)
View SourceSummary
Types
Initialization options.
Condition checked before collecting message traces for a process.
Predicate returning true for matching terms of type T.
Options for obtaining previous and next traces.
Options for trace ranges.
Trace selector function.
Options for sorted call statistics.
Format in which tracebacks are returned.
Traceback options.
Options for repeated call tree statistics.
Specifies the behaviour for overlapping call trees.
Trace record, storing one collected trace event.
Function call tree node.
Functions
Returns call time statistics for traces selected from tr_source().
Returns traces containing DataVal in #tr.data.
Checks if the given value DataVal is present within Data.
Loads an ETS trace table from a file, and makes it the current table.
Returns traces with #tr.data containing any values matching the provided predicate.
Checks if Val contains any values matching the predicate Pred.
Prints sorted function call statistics for the selected traces from tab().
Prints sorted function call statistics for the selected traces from tab().
Returns a list of traces from tab() between the first matched call and the corresponding return.
Returns a list of traces from tr_source() between the first matched call and the corresponding return.
Selects data from matching traces from tab() with ets:fun2ms(F).
Returns sorted function call statistics for the selected traces from tab().
Returns sorted function call statistics for the selected traces from tab().
Starts tr as a stand-alone gen_server. Intended for interactive use.
Stops tracing, disabling all trace specs.
Returns statistics of repeated function call trees that took most time.
Starts tracing of the specified functions/modules and/or message events.
Returns traceback of the first matching trace from tr_source().
Returns traceback of the first matching trace from tr_source().
Types
-type acc_time() :: non_neg_integer().
-type call_count() :: non_neg_integer().
-type call_stat_field() :: count | acc_time | own_time.
-type call_tree_count() :: pos_integer().
-type call_tree_stat_options() :: #{tab => table()}.
-type erlang_trace_flags() :: [call | timestamp | send | 'receive'].
-type index() :: pos_integer().
tr() record.
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.
-type message_event_types() :: send | recv | all | none.
none.
[].
-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 order() :: asc | desc.
-type own_time() :: non_neg_integer().
-type pids() :: [pid()] | all.
all.
-type pred(T) :: fun((T) -> boolean()).
Predicate returning true for matching terms of type T.
Options for obtaining previous and next traces.
tab is the ETS table with traces (default: trace). pred allows to filter the matching traces (default: allow any trace)
-type range_options() :: #{tab => tr_source(), max_depth => limit(), output => range_output()}.
Options for trace ranges.
Optionallimit is the maximum depth of calls in the returned ranges. All traces (including messages) exceeding that depth are skipped.
-type range_output() :: complete | incomplete | all.
-type result() :: {return | exception, any()}.
-type selector(Data) :: fun((tr()) -> Data).
Trace selector function.
For selected traces, it returnsData. For other traces, it should fail.
-type sorted_call_stat_options() :: #{sort_by => call_stat_field(), order => order(), limit => limit()}.
Options for sorted call statistics.
sort_by is the field to sort by (default: acc_time). order is ascending or descending (default: desc). limit is the maximum number of rows returned (default: infinity).
-type state() :: #{tab := table(), index := index(), limit := limit(), trace := none | trace_spec(), tracer_pid := none | pid()}.
-type table() :: atom().
-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() :: list | tree | root.
Format in which tracebacks are returned.
list (default) returns a list of tracebacks. tree merges them into a list of trees. root returns only the root of each tree.
-type tb_options() :: #{tab => tr_source(), output => tb_output(), format => tb_format(), order => tb_order(), limit => limit()}.
Traceback options.
Optionallimit is the maximum number of tracebacks to collect before filtering them according to output.
-type tb_order() :: top_down | bottom_up.
top_down.
-type tb_output() :: shortest | longest | all.
shortest.
-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.
-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{index :: index(), pid :: pid(), event :: call | return | exception | send | recv, mfa :: mfa() | no_mfa, data :: term(), ts :: integer(), info :: recipient() | no_info}.
Trace record, storing one collected trace event.
Record fields:index-index()pid- process in which the traced event occurred,erlang:pid()event-call,returnorexceptionfor function traces;sendorrecvfor messages.mfa-erlang:mfa()for function traces;no_mfafor messages.data- Argument list (for calls), returned value (for returns) or class and value (for exceptions).ts- Timestamp in microseconds.info- Forsendevents it is arecipient()tuple; otherwiseno_info.
tab().
-type trace_options() :: #{modules => module_spec(), pids => pids(), msg => message_event_types(), msg_trigger => msg_trigger()}.
-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{module :: module(), function :: atom(), args :: list(), children :: [#node{}], result :: result()}.
Function call tree node.
Record fields:-type tree_item() :: {acc_time(), call_tree_count(), tree()}.
Functions
-spec call_stat(selector(Key)) -> #{Key => {call_count(), acc_time(), own_time()}}.
tab().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().
Key returned by KeyF.
-spec clean() -> ok.
Returns traces containing DataVal in #tr.data.
DataVal can occur in (possibly nested) tuples, maps or lists.
-spec contains_val(T, T) -> boolean().
Checks if the given value DataVal is present within Data.
true if DataVal is found, otherwise returns false. DataVal can occur in (possibly nested) tuples, maps or lists.
tr() record or index.
-spec dump(file:name_all()) -> ok | {error, any()}.
tab() table to a file.
tab().
tr_source().
-spec load(file:name_all()) -> {ok, table()} | {error, any()}.
Loads an ETS trace table from a file, and makes it the current table.
Overwrites the current table if it is empty.tr() record from tab() for an index.
Returns traces with #tr.data containing any values matching the provided predicate.
Checks if Val contains any values matching the predicate Pred.
Args in an MFA tuple.
-spec next(index() | tr(), prev_next_options()) -> tr().
-spec prev(index() | tr(), prev_next_options()) -> tr().
-spec print_sorted_call_stat(selector(_)) -> ok.
Prints sorted function call statistics for the selected traces from tab().
acc_time(), descending.See also: print_sorted_call_stat/2, sorted_call_stat/1.
-spec print_sorted_call_stat(selector(_), sorted_call_stat_options()) -> ok.
Prints sorted function call statistics for the selected traces from tab().
See also: sorted_call_stat/2.
Returns a list of traces from tab() between the first matched call and the corresponding return.
tr() record. Fails if no trace is matched.See also: range/2.
Returns a list of traces from tr_source() between the first matched call and the corresponding return.
tab() between matched calls and corresponding returns.See also: ranges/2.
-spec ranges(pred(tr()), range_options()) -> [[tr()]].
tr_source() between matched calls and corresponding returns.
-spec reduce_call_trees(ets:tid()) -> true.
tb_tree().
tb_tree() from the provided list.
-spec select() -> [tr()].
tab().
-spec select(selector(Data)) -> [Data].
tab() with ets:fun2ms(F).
Selects data from matching traces from tab() with ets:fun2ms(F).
DataVal in #tr.data. DataVal can occur in (possibly nested) tuples, maps or lists.
-spec set_tab(table()) -> ok.
-spec sorted_call_stat(selector(Key)) -> [{Key, call_count(), acc_time(), own_time()}].
Returns sorted function call statistics for the selected traces from tab().
acc_time(), descending.See also: call_stat/1, sorted_call_stat/2.
-spec sorted_call_stat(selector(Key), sorted_call_stat_options()) -> [{Key, call_count(), acc_time(), own_time()}].
Returns sorted function call statistics for the selected traces from tab().
-spec start() -> {ok, pid()}.
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.
Opts.
-spec start_link() -> {ok, pid()}.
tr as part of a supervision tree.See also: start/1.
-spec start_link(init_options()) -> {ok, pid()}.
tr as part of a supervision tree.See also: start/1.
-spec stop() -> ok.
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().
-spec top_call_trees() -> [tree_item()].
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}.
-spec trace_app(atom()) -> ok | {error, already_tracing}.
-spec trace_apps([atom()]) -> ok | {error, already_tracing}.
Returns traceback of the first matching trace from tr_source().
tr record. Fails if no trace is matched.See also: traceback/2.
Returns traceback of the first matching trace from tr_source().
limit option does not apply.
tab().See also: tracebacks/2.
tr_source().