Last active
November 5, 2020 19:08
-
-
Save garthk/621d0f2ebb8567720a027021e0e7d238 to your computer and use it in GitHub Desktop.
Watch all Phoenix.LiveView and LiveComponent handle_event callbacks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(fn gl -> | |
:dbg.stop_clear() | |
repr = fn | |
%Phoenix.LiveView.Socket{} -> "socket" | |
v -> inspect(v) | |
end | |
{:ok, _} = | |
:dbg.tracer( | |
:process, | |
{fn | |
{:trace, pid, :call, {module, function, args}}, _ -> | |
IO.puts(gl, [ | |
[inspect(pid), ": ", inspect(module), ".", Atom.to_string(function), "("], | |
args |> Enum.map(repr) |> Enum.intersperse(", "), | |
")" | |
]) | |
end, :state} | |
) | |
:dbg.p(:all, [:call]) | |
for {app, _desc, _version} <- :application.loaded_applications(), | |
{:ok, modules} = :application.get_key(app, :modules), | |
module <- modules, | |
Kernel.function_exported?(module, :__live__, 0), | |
do: :dbg.tpl(module, :handle_event, [{:_, [], []}]) | |
end).(Process.group_leader()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Paste the above at the
iex>
prompt to print out the function calls being made to yourhandle_event
callbacks:Works on remote prompts, because
Process.group_leader()
; see Pretty for more detail on how that works.