Skip to content

Commit 3ccdf69

Browse files
committed
Bug: Hide module reloading behind config flag (#420)
* hide behind config option * change name, update docs * fix tests
1 parent 886bba5 commit 3ccdf69

4 files changed

Lines changed: 24 additions & 13 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ config :live_debugger, :disabled?, true
108108
# Time in ms after tracing will be initialized. Useful in case multi-nodes envs
109109
config :live_debugger, :tracing_setup_delay, 0
110110

111+
# Used when working with code reloading and traces are not visible.
112+
# WARNING! This may cause some performance issues.
113+
config :live_debugger, :tracing_update_on_code_reload?, true
114+
111115
# LiveDebugger endpoint config
112116
config :live_debugger,
113117
ip: {127, 0, 0, 1}, # IP on which LiveDebugger will be hosted

docs/config.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ config :live_debugger, :disabled?, true
3838
# Time in ms after tracing will be initialized. Useful in case multi-nodes envs
3939
config :live_debugger, :tracing_setup_delay, 0
4040

41+
# Used when working with code reloading and traces are not visible.
42+
# WARNING! This may cause some performance issues.
43+
config :live_debugger, :tracing_update_on_code_reload?, true
44+
4145
# LiveDebugger endpoint config
4246
config :live_debugger,
4347
ip: {127, 0, 0, 1}, # IP on which LiveDebugger will be hosted

lib/live_debugger/gen_servers/callback_tracing_server.ex

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ defmodule LiveDebugger.GenServers.CallbackTracingServer do
5353
# We trace it to refresh the components tree
5454
Dbg.tp({Phoenix.LiveView.Diff, :delete_component, 2}, [])
5555

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

5961
{:noreply, state}
6062
end
@@ -64,11 +66,8 @@ defmodule LiveDebugger.GenServers.CallbackTracingServer do
6466
{:reply, :ok, state}
6567
end
6668

67-
# This handler is heavy because of fetching state and we do not care for order because it is not displayed to user
68-
# Because of that we do it asynchronously to speed up tracer a bit
69-
# We do not persist this trace because it is not displayed to user
7069
@spec handle_trace(term(), n :: integer()) :: integer()
71-
defp handle_trace({_, _, :return_from, {Mix.Tasks.Compile.Elixir, _, _}, _}, n) do
70+
defp handle_trace({_, _, :return_from, {Mix.Tasks.Compile.Elixir, _, _}, {:ok, _}}, n) do
7271
Process.sleep(100)
7372
add_live_modules_to_tracer()
7473
n
@@ -78,7 +77,17 @@ defmodule LiveDebugger.GenServers.CallbackTracingServer do
7877
n
7978
end
8079

81-
defp handle_trace({_, pid, _, {Phoenix.LiveView.Diff, :delete_component, [cid | _] = args}}, n) do
80+
defp handle_trace({_, _, _, {Mix.Tasks.Compile.Elixir, _, _}, _}, n) do
81+
n
82+
end
83+
84+
# This handler is heavy because of fetching state and we do not care for order because it is not displayed to user
85+
# Because of that we do it asynchronously to speed up tracer a bit
86+
# We do not persist this trace because it is not displayed to user
87+
defp handle_trace(
88+
{_, pid, _, {Phoenix.LiveView.Diff, :delete_component, [cid | _] = args}},
89+
n
90+
) do
8291
Task.start(fn ->
8392
with cid <- %Phoenix.LiveComponent.CID{cid: cid},
8493
{:ok, %{socket: socket}} <- ChannelService.state(pid),

test/gen_servers/callback_tracing_server_test.exs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ defmodule LiveDebugger.GenServers.CallbackTracingServerTest do
4949

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

5653
assert {:noreply, %{}} = CallbackTracingServer.handle_info(:setup_tracing, %{})
5754
end
@@ -64,9 +61,6 @@ defmodule LiveDebugger.GenServers.CallbackTracingServerTest do
6461
MockDbg
6562
|> expect(:p, fn :all, :c -> :ok end)
6663
|> expect(:tp, fn {Phoenix.LiveView.Diff, :delete_component, 2}, [] -> :ok end)
67-
|> expect(:tp, fn {Mix.Tasks.Compile.Elixir, :run, 1}, [{:_, [], [{:return_trace}]}] ->
68-
:ok
69-
end)
7064

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

0 commit comments

Comments
 (0)