ObserverWeb.ProcessLabel (Observer Web v0.2.9)

View Source

Resolves human-readable names for processes, using the same fallback chain etop uses.

The steps, in order of preference:

  1. the registered name, when the process has one;
  2. the Process.set_label/1 process label, stored by OTP in the :"$process_label" dictionary entry;
  3. the proc_lib initial call (how GenServers, Supervisors and Tasks identify themselves), suffixed with the pid to keep concurrent instances of the same module apart;
  4. 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

from_dictionary(dictionary)

@spec from_dictionary(term()) :: String.t() | nil

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.

from_initial_call(dictionary, initial_call, pid)

@spec from_initial_call(term(), term(), pid()) :: String.t() | nil

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.

from_registered_name(name)

@spec from_registered_name(term()) :: String.t() | nil

The registered name as a string, or nil when the process has none.

An alive-but-unregistered process reports [] as its registered name.

resolve(pid)

@spec resolve(pid()) :: String.t()

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.