et_collector(3)
π et_collector π
okay bestie, sit down, hydrate, because we're about to get into et_collector β an Erlang module definition from the Event Trace (ET) application, and it's literally the whole vibe of collecting trace events and holding onto them in a backing storage that's built for iteration. yes ma'am. this page lives in section 3 of the manual (you know, the (3) part) and it's gonna be your new obsession. π¦
β¨ NAME β¨
et_collector β collect trace events and provide a backing storage appropriate for iteration. like a little shelf for your trace events so you can walk through them later. iconic behavior honestly. π
πΈ DESCRIPTION πΈ
Interface module for the Event Trace (ET) application. that's it, that's the tweet. this is the doorway, the portal, the main character. π
π DATA TYPES π
okay so before we get into the functions, let's meet the cast of types, because they show up everywhere and you need to know their names, fr fr.
actor() :: term().collector_fun() :: trace_filter_fun() | event_filter_fun().dbg_match_spec() :: [tuple()].dbg_trace_parameters() :: file:filename() | integer() | {string(), integer()}.dbg_trace_type() :: ip | file | follow_file.ets_match_object_pattern() :: term().event() :: #event{}.event_filter_fun() :: fun((Event :: event()) -> boolean() | {true, event()}).event_ts() :: #event_ts{}.level() :: 0..100.table_handle() :: #table_handle{}.trace_filter_fun() :: fun((TraceData :: tuple()) -> boolean() | {true, event()}).trace_ts() :: #trace_ts{}.
and then there's option(), which is a whole mood board of its own:
option() ::
{parent_pid, pid() | undefined} |
{event_order, trace_ts | event_ts} |
{dict_insert, {filter, all}, collector_fun()} |
{dict_insert,
{filter, EventFilterName :: atom()},
event_filter_fun()} |
{dict_insert, {subscriber, pid()}, Val :: term()} |
{dict_insert, Key :: term(), Val :: term()} |
{dict_delete, Key :: term()} |
{trace_client,
{event_file, file:filename()} |
{dbg_trace_type(), dbg_trace_parameters()}} |
{trace_global, boolean()} |
{trace_pattern,
{module() | undefined, Level :: level() | dbg_match_spec()} |
undefined} |
{trace_port, integer()} |
{trace_max_queue, integer()}.
see? told you. she's got range. π
β¨ FUNCTIONS β¨
change_pattern
change_pattern(CollectorPid, RawPattern) ->
{old_pattern, TracePattern}
when
CollectorPid :: pid(),
RawPattern ::
{module(), min | max | level()},
TracePattern ::
[{[term()] | '_' | atom(),
[term()],
[term()]}].
Change active trace pattern globally on all trace nodes. global queen behavior, no cap. π
clear_table
clear_table(Handle) -> ok
when
Handle :: CollectorPid | table_handle(),
CollectorPid :: pid().
Clear the event table. poof, gone, empty. π«§
dict_delete
dict_delete(CollectorPid :: pid(), Key :: term()) -> ok.
Delete a dictionary entry and send a {et, {dict_delete, Key}} tuple to all registered subscribers. π’
also, heads up bestie β if the deleted entry is a registered subscriber, it will mean that the subscriber process gets unregistered as subscriber as well as it gets its final message. so it's a real goodbye, not a soft launch. π
dict_insert
dict_insert(CollectorPid, What, Value) -> ok
when
CollectorPid :: pid(),
What ::
{filter, atom()} |
{subscriber, pid()} |
Key,
Key :: term(),
Value :: collector_fun() | term().
Insert a dictionary entry and send a {et, {dict_insert, Key, Val}} tuple to all registered subscribers. π
and okay, if the entry is a new subscriber, here's the tea: the new subscriber process first gets one message for each already stored dictionary entry, before it and all old subscribers get this particular entry. the collector process links to and then supervises the subscriber process. and if the subscriber process dies, it means it gets unregistered β same as with a normal dict_delete/2. rip. π
dict_lookup
dict_lookup(CollectorPid :: pid(), Key :: term()) ->
[Val :: term()].
Lookup a dictionary entry and return zero or one value. simple, clean, no drama. π§
dict_match
dict_match(CollectorPid :: pid(), {KeyPattern, ValPattern}) ->
[Match]
when
KeyPattern :: ets_match_object_pattern(),
ValPattern :: ets_match_object_pattern(),
Match :: {Key :: term(), Val :: term()}.
Match some dictionary entries. β¨
get_global_pid
get_global_pid() -> CollectorPid :: pid().
Return the identity of the globally registered collector β if there is any. if there isn't... well. π
iterate
iterate(Handle, Prev, Limit, Fun, Acc) -> NewAcc
when
Handle :: CollectorPid | table_handle(),
CollectorPid :: pid(),
Prev :: first | last | term(),
Limit :: Done | Forward | Backward,
Done :: 0,
Forward :: pos_integer() | infinity,
Backward :: neg_integer() | '-infinity',
Fun :: fun((event(), Acc) -> NewAcc) | undefined,
Acc :: term(),
NewAcc :: term().
Iterate over the currently stored events. walk through them, vibe check each one, apply a function to each event.
the iteration may be performed forwards or backwards and may be limited to a maximum number of events (abs(Limit)). going backwards is valid, slay. π₯
make_key
make_key(Handle, Stuff) -> Key
when
Handle :: table_handle() | trace_ts | event_ts,
Stuff :: event() | Key,
Key :: event_ts() | trace_ts().
Make a key out of an event record or an old key. glue it together, bestie. π
multicast
multicast(CollectorPid :: pid(), Msg :: term()) -> ok.
Sends a message to all registered subscribers. group chat blast, literally. π£π
report_event
report_event(Handle, DetailLevel, From, To, Label, Contents) ->
{ok, Continuation}
when
Handle ::
CollectorPid :: pid() | table_handle(),
DetailLevel :: level(),
From :: actor(),
To :: actor(),
Label :: term(),
Contents ::
[{Key :: term(), Value :: term()}] |
term(),
Continuation :: table_handle().
Report an event to the collector. π¨
All events are filtered thru the collector filter, which optionally may transform or discard the event. and listen β the first call should use the pid of the collector process as report handle, while subsequent calls should use the table handle. first date = pid, every date after = table handle. iykyk. π
save_event_file
save_event_file(CollectorPid, FileName, [Option]) ->
ok | {error, term()}
when
CollectorPid :: pid(),
FileName :: file:filename(),
Option ::
existing | write | append | keep |
clear.
Save the events to a file. πβ¨
By default the currently stored events (existing) are written to a brand new file (write) and the events are kept (keep) after they have been written to the file.
Instead of keeping the events after writing them to file, it is possible to remove all stored events after they have successfully written to file (clear). bye bye events, you lived a good life. π«‘
the options default toexisting,writeandkeep. fr fr.
start_link
start_link(Options) -> {ok, Pid :: pid()} | {error, term()}
when Options :: [option()].
Start a collector process. the birth of a legend. π
The collector collects trace events and keeps them ordered by their timestamp. the timestamp may either reflect the time when the actual trace data was generated (trace_ts) or when the trace data was transformed into an event record (event_ts). and if the time stamp is missing in the trace data (that's the missing timestamp option to erlang:trace/4), the trace_ts will be set to the event_ts. no timestamp, no problem. π
Events are reported to the collector directly with the report function or indirectly via one or more trace clients. all reported events are first filtered thru the collector filter before they are stored by the collector. by replacing the default collector filter with a customized dito it is possible to allow any trace data as input. the collector filter is a dictionary entry with the predefined key {filter, collector} and the value is a fun of arity 1. see et_selector:make_event/1 for interface details, such as which erlang:trace/1 tuples that are accepted. π
The collector has a built-in dictionary service. any term may be stored as value in the dictionary and bound to a unique key. when new values are inserted with an existing key, the new values will overwrite the existing ones. processes may subscribe on dictionary updates by using {subscriber, pid()} as dictionary key. all dictionary updates will be propagated to the subscriber processes matching the pattern {{subscriber, '_'}, '_'} where the first '_' is interpreted as a pid(). π«Ά
In global trace mode, the collector will automatically start tracing on all connected Erlang nodes. when a node connects, a port tracer will be started on that node and a corresponding trace client on the collector node. it's giving networking main character energy. π
Default values, bestie, memorize these:
parent_pidβself().event_orderβtrace_ts.trace_globalβfalse.trace_patternβundefined.trace_portβ4711.trace_max_queueβ50.
start_trace_client
start_trace_client(CollectorPid, Type, Parameter) ->
file_loaded | {trace_client_pid, pid()}
when
CollectorPid :: pid(),
Type :: event_file | dbg_trace_type(),
Parameter :: dbg_trace_parameters().
Load raw Erlang trace from a file, port or process. come through, data. π
stop
stop(pid()) -> ok.
Stop a collector process. it's over, the era has ended, but what an era it was. π
π SEE ALSO π
ngl, this page didn't hand me a SEE ALSO list, so we're keeping it exactly as-is. no invented cross-references here, bestie β the facts stay facts even when the vibe is immaculate. β¨
that's the whole page!! you ate it, you understood it, you're basically an ET application expert now. π
this manual page is brought to you by Ericsson AB, version et 1.8. mwah, take care of her. π
ππ¦
π¦ where this page comes from
- nixos 26.05: erlang 29.1.2
- nixpkgs unstable: erlang 29.1.2
- ubuntu stonking: erlang-doc 1:29.0.6+dfsg-1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms