defmodule Observer.Web.Profiling.Page do @moduledoc """ This is the live component responsible for handling the Profiling tools (Count, Duration, Call Sequence and Flame Graph). Shares the node/module/function selection logic with `Observer.Web.Tracing.Page` via `Observer.Web.Tracing.Selection`, but runs its sessions with a `tool` selected instead of the raw match-spec picker, and shows a single aggregated report instead of a live event stream. """ @behaviour Observer.Web.Page use Observer.Web, :live_component alias Observer.Web.Components.Attention alias Observer.Web.Components.Core alias Observer.Web.Components.MultiSelectList alias Observer.Web.Page alias Observer.Web.Tracing.Selection alias ObserverWeb.Tracer @impl Phoenix.LiveComponent def render(assigns) do unselected_services_keys = assigns.node_info.services_keys -- assigns.node_info.selected_services_keys unselected_modules_keys = assigns.node_info.modules_keys -- assigns.node_info.selected_modules_keys unselected_functions_keys = assigns.node_info.functions_keys -- assigns.node_info.selected_functions_keys trace_state = Tracer.state() trace_idle? = trace_state.status == :idle trace_owner? = trace_state.session_id == assigns.trace_session_id show_tracing_options = trace_idle? and trace_owner? and assigns.show_tracing_options tool = assigns.form.params["tool"] || "count" attention_msg = attention_msg(tool) # A report only makes sense to render once the tool that produced it is still the one # selected - the Tool dropdown can be switched (or a new run started with a different tool) # before/without re-running, and each tool's report has a completely different shape (e.g. # Count/Duration's {{node, mod, fun, arity, message}, value} tuples vs Call Sequence and Flame # Graph's maps), so rendering a stale report under the wrong tool would crash. report_matches_tool? = assigns.report != nil and tool == assigns.report_tool flame_report = if report_matches_tool? and tool == "flame_graph" do flame_report_selected(assigns.report, assigns.form.params) end assigns = assigns |> assign(unselected_services_keys: unselected_services_keys) |> assign(unselected_modules_keys: unselected_modules_keys) |> assign(unselected_functions_keys: unselected_functions_keys) |> assign(trace_idle?: trace_idle?) |> assign(trace_owner?: trace_owner?) |> assign(show_tracing_options: show_tracing_options) |> assign(attention_msg: attention_msg) |> assign(tool: tool) |> assign(report_matches_tool?: report_matches_tool?) |> assign(flame_report: flame_report) ~H"""