+
+%% ============================================================================
+%% Process code origin approximation or naming the anonymous processes.
+%%
+%% At runtime, given a PID, how precicely can we identify the origin of the
+%% code it is running?
+%%
+%% We have these data points:
+%%
+%% - Sometimes | registered name (if so, we're done)
+%% - Sometimes | ancestor PIDs or registered names
+%% - Always | initial_call (can be too generic, such as erlang:apply)
+%% - Always | current_function (can be too far down the stack)
+%% - Always | current_location (can be too far down the stack)
+%% - Potentially | application tree, but maybe expensive to compute, need to check
+%% ============================================================================
+
+-define(TAG(Tag), fun (X) -> {Tag, X} end).
+
+-spec get_best_known_origin(t()) ->
+ best_known_origin().
+get_best_known_origin(?T{registered_name={some, RegisteredName}}) ->
+ {registered_name, RegisteredName};
+get_best_known_origin(?T{registered_name=none, ancestry=Ancestry}) ->
+ {ancestry, Ancestry}.