defmodule Observer.Web.Apps.Process do @moduledoc false use Observer.Web, :html use Phoenix.Component alias Observer.Web.Components.Attention attr :info, :map, required: true attr :id, :map, required: true def content(assigns) do info = assigns.info map_phx_lv_socket = fn %Phoenix.LiveView.Socket{} = phx_lv_socket -> [ %{name: "Id", value: "#{phx_lv_socket.id}"}, %{name: "Endpoint", value: "#{inspect(phx_lv_socket.endpoint)}"}, %{name: "View", value: "#{inspect(phx_lv_socket.view)}"}, %{name: "Router", value: "#{inspect(phx_lv_socket.router)}"}, %{name: "Connected?", value: "#{inspect(phx_lv_socket.transport_pid)}"}, %{name: "redirected", value: "#{inspect(phx_lv_socket.redirected)}"} ] _socket -> nil end map_phx_lv_socket_uri = fn %Phoenix.LiveView.Socket{host_uri: %URI{} = host_uri} -> [ %{name: "Scheme", value: "#{host_uri.scheme}"}, %{name: "User Info", value: "#{inspect(host_uri.userinfo)}"}, %{name: "Host", value: "#{host_uri.host}"}, %{name: "Port", value: "#{inspect(host_uri.port)}"}, %{name: "Path", value: "#{host_uri.path}"}, %{name: "Query", value: "#{inspect(host_uri.query)}"}, %{name: "Fragment", value: "#{inspect(host_uri.fragment)}"} ] _socket -> nil end process_mappings = if is_map(info) do %{ overview: [ %{name: "Id", value: "#{inspect(info.pid)}"}, %{name: "Registered name", value: "#{info.registered_name}"}, %{name: "Status", value: "#{info.meta.status}"}, %{name: "Class", value: "#{info.meta.class}"}, %{name: "Message Queue Length", value: "#{info.message_queue_len}"}, %{name: "Group Leader", value: "#{inspect(info.relations.group_leader)}"}, %{name: "Trap exit", value: "#{info.trap_exit}"} ], memory: [ %{name: "Total", value: "#{info.memory.total}"}, %{name: "Heap Size", value: "#{info.memory.heap_size}"}, %{name: "Stack Size", value: "#{info.memory.stack_size}"}, %{name: "GC Min Heap Size", value: "#{info.memory.gc_min_heap_size}"}, %{name: "GC FullSweep After", value: "#{info.memory.gc_full_sweep_after}"} ], phx_lv_socket: map_phx_lv_socket.(info.phx_lv_socket), phx_lv_socket_uri: map_phx_lv_socket_uri.(info.phx_lv_socket) } else nil end assigns = assigns |> assign(process_mappings: process_mappings) ~H"""
<%= cond do %> <% @info == nil -> %> <% @info == :undefined -> %> <% true -> %>
<:col :let={item}> {item.name} <:col :let={item}> {item.value} <:col :let={item}> {item.name} <:col :let={item}> {item.value} <.relations title="State" value={"#{inspect(@info.state)}"} />
<.relations title="Links" value={"#{inspect(@info.relations.links)}"} /> <.relations title="Ancestors" value={"#{inspect(@info.relations.ancestors)}" } /> <.relations title="Monitors" value={"#{inspect(@info.relations.monitors)}"} /> <.relations title="Monitored by" value={"#{inspect(@info.relations.monitored_by)}"} />
<:col :let={item}> {item.name} <:col :let={item}> {item.value} <:col :let={item}> {item.name} <:col :let={item}> {item.value} <.relations title="Phoenix.LiveView.Socket - Assigns" title_bg_color="MediumSeaGreen" value={to_string(:io_lib.format("~tp", [@info.phx_lv_socket.assigns]))} />
<% end %>
""" end attr :title, :string, required: true attr :value, :string, required: true attr :title_bg_color, :string, default: "LightGray" defp relations(assigns) do ~H"""
{@title}
{@value}
""" end end