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
24 changes: 10 additions & 14 deletions lib/live_debugger/services/trace_service.ex
Original file line number Diff line number Diff line change
Expand Up @@ -140,42 +140,38 @@ defmodule LiveDebugger.Services.TraceService do
]
end

def to_spec([], []), do: [{:"/=", :"$2", nil}]

def to_spec(functions, []) do
[{:andalso, List.first(functions_to_spec(functions)), {:"/=", :"$2", nil}}]
end

def to_spec([], execution_times) do
[{:andalso, List.first(execution_times_to_spec(execution_times)), {:"/=", :"$2", nil}}]
[{:andalso, functions_to_spec(functions), {:"/=", :"$2", nil}}]
end

def to_spec(functions, execution_times) do
[
{:andalso,
{:andalso, List.first(functions_to_spec(functions)),
List.first(execution_times_to_spec(execution_times))}, {:"/=", :"$2", nil}}
{:andalso, functions_to_spec(functions), execution_times_to_spec(execution_times)},
{:"/=", :"$2", nil}}
]
end

def functions_to_spec([single]), do: [{:"=:=", :"$1", single}]
def functions_to_spec([]), do: false

def functions_to_spec([single]), do: {:"=:=", :"$1", single}

def functions_to_spec([first, second | rest]) do
initial_orelse =
{:orelse, List.first(functions_to_spec([first])), List.first(functions_to_spec([second]))}
{:orelse, functions_to_spec([first]), functions_to_spec([second])}

result =
Enum.reduce(rest, initial_orelse, fn x, acc ->
{:orelse, acc, List.first(functions_to_spec([x]))}
{:orelse, acc, functions_to_spec([x])}
end)

[{:andalso, result, {:"/=", :"$2", nil}}]
{:andalso, result, {:"/=", :"$2", nil}}
end

def execution_times_to_spec(execution_times) do
min_time = Keyword.get(execution_times, :exec_time_min, 0)
max_time = Keyword.get(execution_times, :exec_time_max, :infinity)
[{:andalso, {:>=, :"$2", min_time}, {:"=<", :"$2", max_time}}]
{:andalso, {:>=, :"$2", min_time}, {:"=<", :"$2", max_time}}
end

@spec ets_table!(pid :: ets_table_id()) :: :ets.table()
Expand Down
12 changes: 12 additions & 0 deletions test/live_debugger/channel_dashboard_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,18 @@ defmodule LiveDebugger.ChannelDashboardTest do
"render/1",
"mount/3"
])
|> click(filters_button())
|> click(checkbox("mount"))
|> click(checkbox("handle_params"))
|> click(checkbox("handle_info"))
|> click(checkbox("handle_call"))
|> click(checkbox("handle_cast"))
|> click(checkbox("terminate"))
|> click(checkbox("render"))
|> click(checkbox("handle_event"))
|> click(checkbox("handle_async"))
|> click(css("button", text: "Apply"))
|> assert_has(traces(count: 0))
end

defp assert_traces(session, count, callback_names) do
Expand Down
32 changes: 21 additions & 11 deletions test/services/trace_service_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ defmodule Services.TraceServiceTest do
alias LiveDebugger.Services.TraceService
alias LiveDebugger.MockEtsTableServer

@all_functions LiveDebugger.Utils.Callbacks.callbacks_functions()

setup :verify_on_exit!

setup_all do
Expand Down Expand Up @@ -56,7 +58,8 @@ defmodule Services.TraceServiceTest do
MockEtsTableServer
|> expect(:table!, fn ^pid -> table end)

assert {[^trace1, ^trace2], _} = TraceService.existing_traces(pid)
assert {[^trace1, ^trace2], _} =
TraceService.existing_traces(pid, functions: @all_functions)
end

test "returns traces with limit and continuation", %{module: module, pid: pid, table: table} do
Expand All @@ -71,12 +74,13 @@ defmodule Services.TraceServiceTest do
MockEtsTableServer
|> expect(:table!, fn ^pid -> table end)

{traces1, cont} = TraceService.existing_traces(pid, limit: 2)
{traces2, cont} = TraceService.existing_traces(pid, cont: cont)
{traces1, cont} = TraceService.existing_traces(pid, limit: 2, functions: @all_functions)
{traces2, cont} = TraceService.existing_traces(pid, cont: cont, functions: @all_functions)

assert [trace1, trace2] == traces1
assert [trace3] == traces2
assert cont == :end_of_table

assert :end_of_table == TraceService.existing_traces(pid, cont: :end_of_table)
end

Expand Down Expand Up @@ -121,12 +125,14 @@ defmodule Services.TraceServiceTest do

assert {[^trace2], _} =
TraceService.existing_traces(pid,
execution_times: [exec_time_min: 15, exec_time_max: 50]
execution_times: [exec_time_min: 15, exec_time_max: 50],
functions: @all_functions
)

assert {[^trace2, ^trace3], _} =
TraceService.existing_traces(pid,
execution_times: [exec_time_min: 15, exec_time_max: :infinity]
execution_times: [exec_time_min: 15, exec_time_max: :infinity],
functions: @all_functions
)
end

Expand Down Expand Up @@ -173,8 +179,11 @@ defmodule Services.TraceServiceTest do
MockEtsTableServer
|> expect(:table!, 2, fn ^pid -> table end)

assert {[^trace1], _} = TraceService.existing_traces(pid, node_id: pid)
assert {[^trace2, ^trace3], _} = TraceService.existing_traces(pid, node_id: cid)
assert {[^trace1], _} =
TraceService.existing_traces(pid, node_id: pid, functions: @all_functions)

assert {[^trace2, ^trace3], _} =
TraceService.existing_traces(pid, node_id: cid, functions: @all_functions)
end

test "returns :end_of_table when no traces match", %{module: module, pid: pid, table: table} do
Expand All @@ -201,7 +210,7 @@ defmodule Services.TraceServiceTest do
MockEtsTableServer
|> expect(:table!, fn ^pid -> table end)

assert {[^trace1], _} = TraceService.existing_traces(pid)
assert {[^trace1], _} = TraceService.existing_traces(pid, functions: @all_functions)
end
end

Expand All @@ -218,15 +227,16 @@ defmodule Services.TraceServiceTest do
MockEtsTableServer
|> expect(:table!, 5, fn ^pid -> table end)

assert {[^trace1, ^trace2], _} = TraceService.existing_traces(pid)
assert {[^trace1, ^trace2], _} =
TraceService.existing_traces(pid, functions: @all_functions)

TraceService.clear_traces(pid, trace1.pid)

assert {[^trace2], _} = TraceService.existing_traces(pid)
assert {[^trace2], _} = TraceService.existing_traces(pid, functions: @all_functions)

TraceService.clear_traces(pid, trace2.cid)

assert :end_of_table = TraceService.existing_traces(pid)
assert :end_of_table = TraceService.existing_traces(pid, functions: @all_functions)
end
end
end