christhekeele / matcha

🍵 First-class Elixir match specifications.
Other
89 stars 4 forks source link

Trace Not Confined To Specified Process #38

Open OnorioCatenacci opened 1 year ago

OnorioCatenacci commented 1 year ago

I was working through the trace documentation (tracing.livemd) and I ran across something that looks like it may be an error?

Running this:

IO.puts("I am: #{inspect(self())}")

# Configure the tracing engine to only monitor our `self()`
Matcha.Trace.module(Integer, limit: 1_000, pid: self())

do_integer_things = fn ->
  IO.puts("The process now executing some Integer calls is: #{inspect(self())}")
  Integer.digits(123)
  Integer.parse("1")
end

# Calls from this process will emit tracing messages
do_integer_things.()
# The same calls in other processes will not be traced!
IO.puts("A newly spawned process is: #{inspect(spawn(do_integer_things))}")

gave me this output:

I am: #PID<0.135.0> The process now executing some Integer calls is: #PID<0.135.0> A newly spawned process is: #PID<0.597.0> The process now executing some Integer calls is: #PID<0.597.0>

:ok

Matcha.Trace: Elixir.Integer.digits(123) called on #PID<0.135.0> Matcha.Trace: Elixir.Integer.parse("1") called on #PID<0.135.0> Matcha.Trace: Elixir.Integer.digits(123) called on #PID<0.597.0> Matcha.Trace: Elixir.Integer.parse("1") called on #PID<0.597.0>

From the documentation it seems that #PID<0.597.0> should not get traced. Please disregard this if if I'm simply reading the docs incorrectly!

christhekeele commented 1 year ago

It's a pretty complicated little example snippet, TBH. The goal of this is to demonstrate the pid functionality; and you are correct that we are receiving messages for processes that should not.

The problem likely lies in how we are propagating the Matcha pid options into the recon call... So marking as a bug. I wonder if I read the recon docs wrong.

Notice that we do some extra hijinks to accept argument and pid lists and create permutations of traces. That's pretty untested, so another vector of this bug.

christhekeele commented 1 year ago

Oddly enough I can repeat this with an equivalent recon call, so I think I'm just failing to understand how this recon feature is supposed to be used?

Same functionality, just swapped out the Matcha for :recon:

IO.puts("I am: #{inspect(self())}")

# Configure the tracing engine to only monitor our `self()`
# Matcha.Trace.module(Integer, limit: 1_000, pid: self())
:recon_trace.calls({Integer, :_, :_}, 1_000, pid: self())

do_integer_things = fn ->
  IO.puts("The process now executing some Integer calls is: #{inspect(self())}")
  Integer.digits(123)
  Integer.parse("1")
end

# Calls from this process will emit tracing messages
do_integer_things.()
# The same calls in other processes will not be traced!
IO.puts("A newly spawned process is: #{inspect(spawn(do_integer_things))}")