Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,4 @@ if config_env() == :test do

# Initialize plugs at runtime for faster test compilation
config :phoenix, :plug_init_mode, :runtime

config :phoenix_live_view,
# Enable helpful, but potentially expensive runtime checks
enable_expensive_runtime_checks: true
end
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,107 @@ defmodule LiveDebugger.App.Debugger.CallbackTracing.Structs.TraceDisplay do

alias LiveDebugger.Structs.Trace
alias LiveDebugger.Structs.DiffTrace
alias LiveDebugger.App.Utils.Parsers
alias LiveDebugger.CommonTypes

defstruct [:id, :trace, :from_event?, :counter, render_body?: false]
defstruct [
:id,
:from_event?,
:render_body?,
:type,
:title,
:subtitle,
:subtitle_link_data,
:body,
:side_section_left,
:side_section_right
]

@type type() :: :normal | :diff | :error
@type side_section_left() :: {:timestamp, non_neg_integer()}
@type side_section_right() ::
{:execution_time, non_neg_integer() | nil} | {:size, non_neg_integer()}

@type t() :: %__MODULE__{
id: Trace.id(),
trace: Trace.t() | DiffTrace.t(),
from_event?: boolean(),
render_body?: boolean()
render_body?: boolean(),
type: type(),
title: String.t(),
subtitle: String.t() | nil,
subtitle_link_data: %{pid: pid(), cid: CommonTypes.cid()} | nil,
body: list({String.t(), term()}),
side_section_left: side_section_left(),
side_section_right: side_section_right()
}

@spec from_trace(Trace.t() | DiffTrace.t(), boolean()) :: t()
def from_trace(trace, from_event? \\ false) do
%__MODULE__{id: trace.id, trace: trace, from_event?: from_event?}
%__MODULE__{
id: trace.id,
from_event?: from_event?,
render_body?: false,
type: get_type(trace),
title: get_title(trace),
subtitle: get_subtitle(trace),
subtitle_link_data: get_subtitle_link_data(trace),
body: get_body(trace),
side_section_left: get_side_section_left(trace),
side_section_right: get_side_section_right(trace)
}
end

@spec render_body(t()) :: t()
def render_body(%__MODULE__{} = trace) do
Map.put(trace, :render_body?, true)
end

@spec short_content(t(), boolean()) :: String.t()
def short_content(trace_display, full? \\ false) do
trace_display.body
|> Enum.map(fn {_label, content} -> content end)
|> Enum.map_join(" ", &inspect(&1, limit: if(full?, do: :infinity, else: 10), structs: false))
end

defp get_type(%{type: :exception_from}), do: :error
defp get_type(%LiveDebugger.Structs.DiffTrace{}), do: :diff
defp get_type(_), do: :normal

defp get_title(%Trace{} = trace), do: Trace.callback_name(trace)
defp get_title(%DiffTrace{}), do: "Diff sent"

defp get_subtitle(%Trace{module: module, cid: cid}) do
module_string = Parsers.module_to_string(module)
cid_string = if cid, do: " (#{cid})", else: ""

module_string <> cid_string
end

defp get_subtitle(%DiffTrace{}), do: nil

defp get_subtitle_link_data(%Trace{pid: pid, cid: cid}) do
%{pid: pid, cid: cid}
end

defp get_subtitle_link_data(%DiffTrace{}), do: nil

defp get_body(%Trace{args: args} = trace) do
Enum.with_index(args, fn arg, index ->
{"Arg #{index} (#{Trace.arg_name(trace, index)})", arg}
end)
end

defp get_body(%DiffTrace{body: body}), do: [{"Diff content", body}]

defp get_side_section_left(%{timestamp: timestamp}) do
{:timestamp, timestamp}
end

defp get_side_section_right(%Trace{execution_time: execution_time}) do
{:execution_time, execution_time}
end

defp get_side_section_right(%DiffTrace{size: size}) do
{:size, size}
end
end
Loading