ObserverWeb.ProcessLabel (Observer Web v0.2.9)
View SourceResolves human-readable names for processes, using the same fallback chain etop uses.
The steps, in order of preference:
- the registered name, when the process has one;
- the
Process.set_label/1process label, stored by OTP in the:"$process_label"dictionary entry; - the
proc_libinitial call (how GenServers, Supervisors and Tasks identify themselves), suffixed with the pid to keep concurrent instances of the same module apart; - the inspected pid.
Callers pick how far down the chain they want to go. resolve/1 walks all of it and always
returns something printable; the from_* functions are pure and operate on data the caller has
already fetched, so a page that pulls :dictionary for other reasons pays no extra round trip.
Labels matter most for processes that have no registered name - LiveViews, Registry/:via
registrations, connection-pool workers and Tasks - which is precisely the population that
would otherwise render as a bare pid.
Summary
Functions
The Process.set_label/1 label held in an already-fetched process dictionary, or nil.
The proc_lib initial call, suffixed with the pid, or nil when there is nothing useful.
The registered name as a string, or nil when the process has none.
Full fallback chain for pid, always returning a printable string.
Functions
The Process.set_label/1 label held in an already-fetched process dictionary, or nil.
Labels are arbitrary terms, so anything that is not already a binary is inspected.
The proc_lib initial call, suffixed with the pid, or nil when there is nothing useful.
proc_lib-spawned processes carry their real starting MFA in the :"$initial_call" dictionary
entry; the raw :initial_call for them is the meaningless proc_lib/erlang wrapper. Anything
without the dictionary entry that only reports a generic spawn wrapper returns nil.
The registered name as a string, or nil when the process has none.
An alive-but-unregistered process reports [] as its registered name.
Full fallback chain for pid, always returning a printable string.
Works for local and remote pids (ObserverWeb.Rpc.pinfo/2 is location transparent). Falls back
to the inspected pid when the process has already died by the time it is asked - common for
short-lived processes.