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: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ config :live_debugger, :disabled?, true
# Time in ms after tracing will be initialized. Useful in case multi-nodes envs
config :live_debugger, :tracing_setup_delay, 0

# Used when working with code reloading and traces are not visible.
# WARNING! This may cause some performance issues.
config :live_debugger, :tracing_update_on_code_reload?, true

# LiveDebugger endpoint config
config :live_debugger,
ip: {127, 0, 0, 1}, # IP on which LiveDebugger will be hosted
Expand Down
4 changes: 4 additions & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ config :live_debugger, :disabled?, true
# Time in ms after tracing will be initialized. Useful in case multi-nodes envs
config :live_debugger, :tracing_setup_delay, 0

# Used when working with code reloading and traces are not visible.
# WARNING! This may cause some performance issues.
config :live_debugger, :tracing_update_on_code_reload?, true

# LiveDebugger endpoint config
config :live_debugger,
ip: {127, 0, 0, 1}, # IP on which LiveDebugger will be hosted
Expand Down
18 changes: 12 additions & 6 deletions lib/live_debugger/gen_servers/callback_tracing_server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ defmodule LiveDebugger.GenServers.CallbackTracingServer do
# We trace it to refresh the components tree
Dbg.tp({Phoenix.LiveView.Diff, :delete_component, 2}, [])

# We need to get information when code reloads to properly trace modules
Dbg.tp({Mix.Tasks.Compile.Elixir, :run, 1}, [{:_, [], [{:return_trace}]}])
if Application.get_env(:live_debugger, :tracing_update_on_code_reload?, false) do
# We need to get information when code reloads to properly trace modules
Dbg.tp({Mix.Tasks.Compile.Elixir, :run, 1}, [{:_, [], [{:return_trace}]}])
end

{:noreply, state}
end
Expand All @@ -64,11 +66,8 @@ defmodule LiveDebugger.GenServers.CallbackTracingServer do
{:reply, :ok, state}
end

# This handler is heavy because of fetching state and we do not care for order because it is not displayed to user
# Because of that we do it asynchronously to speed up tracer a bit
# We do not persist this trace because it is not displayed to user
@spec handle_trace(term(), n :: integer()) :: integer()
defp handle_trace({_, _, :return_from, {Mix.Tasks.Compile.Elixir, _, _}, _, _}, n) do
defp handle_trace({_, _, :return_from, {Mix.Tasks.Compile.Elixir, _, _}, {:ok, _}, _}, n) do
Process.sleep(100)
add_live_modules_to_tracer()
n
Expand All @@ -78,6 +77,13 @@ defmodule LiveDebugger.GenServers.CallbackTracingServer do
n
end

defp handle_trace({_, _, _, {Mix.Tasks.Compile.Elixir, _, _}, _, _}, n) do
n
end

# This handler is heavy because of fetching state and we do not care for order because it is not displayed to user
# Because of that we do it asynchronously to speed up tracer a bit
# We do not persist this trace because it is not displayed to user
defp handle_trace(
{_, pid, _, {Phoenix.LiveView.Diff, :delete_component, [cid | _] = args}, timestamp},
n
Expand Down
6 changes: 0 additions & 6 deletions test/gen_servers/callback_tracing_server_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ defmodule LiveDebugger.GenServers.CallbackTracingServerTest do

MockDbg
|> expect(:tp, fn {Phoenix.LiveView.Diff, :delete_component, 2}, [] -> :ok end)
|> expect(:tp, fn {Mix.Tasks.Compile.Elixir, :run, 1}, [{:_, [], [{:return_trace}]}] ->
:ok
end)

assert {:noreply, %{}} = CallbackTracingServer.handle_info(:setup_tracing, %{})
end
Expand All @@ -65,9 +62,6 @@ defmodule LiveDebugger.GenServers.CallbackTracingServerTest do
MockDbg
|> expect(:p, fn :all, [:c, :timestamp] -> :ok end)
|> expect(:tp, fn {Phoenix.LiveView.Diff, :delete_component, 2}, [] -> :ok end)
|> expect(:tp, fn {Mix.Tasks.Compile.Elixir, :run, 1}, [{:_, [], [{:return_trace}]}] ->
:ok
end)

# In order to keep CallbackTracingServer.handle_trace function private we extract it here
# and send to test process so that we can test it
Expand Down