Packages
ex_esdb
0.7.8
0.11.0
0.10.0
0.9.0
0.8.0
0.7.8
0.7.7
0.7.6
0.7.5
0.7.4
0.7.3
0.7.2
0.7.1
0.7.0
0.6.1
0.6.0
0.5.1
0.5.0
0.4.8
0.4.7
0.4.6
0.4.5
0.4.4
0.4.3
0.4.2
0.4.1
0.4.0
0.3.3
0.3.2
0.3.1
0.3.0
0.2.5
0.2.4
0.2.3
0.2.2
0.2.1
0.2.0
0.1.7
0.1.6
0.1.5
0.1.4
0.1.3
0.1.2
0.1.1
0.1.0
0.0.20
0.0.19
0.0.18
0.0.17
0.0.16
0.0.15
0.0.14-alpha
0.0.13-alpha
0.0.12-alpha
0.0.11-alpha
0.0.10-alpha
0.0.9-alpha
0.0.8-alpha
0.0.6-alpha
0.0.5-alpha
0.0.4-alpha
0.0.3-alpha
0.0.2-alfa
0.0.1-alfa
ExESDB is a reincarnation of rabbitmq/khepri, specialized for use as a BEAM-native event store.
Current section
Files
Jump to
Current section
Files
lib/ex_esdb/inspection/tree_inspector.ex
defmodule ExESDB.Inspection.TreeInspector do
@moduledoc """
Inspects the supervision tree of the ExESDB system.
Provides visualization and analysis of the system's supervision
hierarchy to aid in debugging and monitoring.
"""
use GenServer
# API
def start_link(opts \\ []) do
GenServer.start_link(__MODULE__, opts, name: __MODULE__)
end
def view_supervision_tree(store_id \\ nil) do
GenServer.call(__MODULE__, {:view_supervision_tree, store_id})
end
# GenServer callbacks
@impl true
def init(_opts) do
{:ok, %{}}
end
@impl true
def handle_call({:view_supervision_tree, store_id}, _from, state) do
store_id = store_id || :default_store
tree = fetch_supervision_tree(store_id)
{:reply, tree, state}
end
# Private functions
defp fetch_supervision_tree(store_id) do
system_name = ExESDB.System.system_name(store_id)
pid = Process.whereis(system_name)
build_tree(system_name, pid, 0)
end
defp build_tree(name, pid, depth) do
if Process.alive?(pid) do
children = Supervisor.which_children(pid)
|> Enum.map(fn {child_id, child_pid, type, _modules} ->
child_tree = if type == :supervisor and child_pid != :undefined do
build_tree(child_id, child_pid, depth + 1)
else
nil
end
%{
id: child_id,
pid: child_pid,
type: type,
alive: Process.alive?(child_pid),
children: child_tree
}
end)
%{
name: name,
pid: pid,
alive: Process.alive?(pid),
depth: depth,
children: children
}
else
%{
name: name,
pid: :undefined,
alive: false,
depth: depth,
children: []
}
end
end
end