Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Got error - 1st argument: invalid spec for pid or port, while calling :erlang.trace. #46

Open
hongseokyoon opened this issue Jul 10, 2024 · 1 comment

Comments

@hongseokyoon
Copy link

hongseokyoon commented Jul 10, 2024

If I turn flame on in LiveDashboard and send a request to my Phoenix app, it printed errors.

image
>>>pid:#PID<0.1082.0>
>>>tracer:#PID<0.1082.0> alive?:true
>>>self:#PID<0.1087.0> alive?:true process_info:[
  current_function: {Process, :info, 1},
  initial_call: {:proc_lib, :init_p, 5},
  status: :running,
  message_queue_len: 0,
  links: [#PID<0.1085.0>],
  dictionary: [
    "$ancestors": [#PID<0.1085.0>, #PID<0.642.0>, #PID<0.641.0>,
     MyWeb.Endpoint, Owp.Supervisor, #PID<0.475.0>],
    "$meck_call": {:cowboy_handler, :execute},
    "$initial_call": {:cowboy_stream_h, :request_process, 3}
  ],
  trap_exit: false,
  error_handler: :error_handler,
  priority: :normal,
  group_leader: #PID<0.474.0>,
  total_heap_size: 2208,
  heap_size: 1598,
  stack_size: 30,
  reductions: 408,
  garbage_collection: [
    max_heap_size: %{error_logger: true, kill: true, size: 0},
    min_bin_vheap_size: 46422,
    min_heap_size: 233,
    fullsweep_after: 65535,
    minor_gcs: 4
  ],
  suspending: []
]
[error] ** can only have one tracer per process


[error] Ranch protocol #PID<0.1087.0> of listener OwpWeb.Endpoint.HTTP (connection #PID<0.1085.0>, stream id 1) terminated
an exception was raised:
    ** (ArgumentError) errors were found at the given arguments:

  * 1st argument: invalid spec for pid or port

        :erlang.trace(#PID<0.1087.0>, true, [{:tracer, #PID<0.1087.0>}, :call, :return_to, :running, :arity, :timestamp])
        (flame_on 0.7.0) lib/flame_on/capture/mock_function.ex:12: FlameOn.Capture.MockFunction.start_if_not_started/1
        (flame_on 0.7.0) lib/flame_on/capture/mock_function.ex:27: anonymous fn/3 in FlameOn.Capture.MockFunction.generate/3

Added some log to /lib/flame_on/capture/trace.ex.

defmodule FlameOn.Capture.Trace do
  alias FlameOn.Capture.Server

  @flags [:call, :return_to, :running, :arity, :timestamp]
  def start_trace(tracer) do
    IO.puts ">>>tracer:#{inspect(tracer, limit: :infinity, pretty: true)} alive?:#{Process.alive?(tracer)}"
    match_spec = [{:_, [], [{:message, {{:cp, {:caller}}}}]}]
    :erlang.trace_pattern(:on_load, match_spec, [:local])
    :erlang.trace_pattern({:_, :_, :_}, match_spec, [:local])
    IO.puts ">>>self:#{inspect(self(), limit: :infinity, pretty: true)} alive?:#{Process.alive?(self())} process_info:#{inspect(Process.info(self()), limit: :infinity, pretty: true)}"
    :erlang.trace(self(), true, [{:tracer, self()} | @flags])
  end

  def stop_trace do
    :erlang.trace(self(), false, [:all])
    Server.stop_trace()
  end
end

It says that the pid is valid and why does it keep complaining that the first argument is not valid?

@TheFirstAvenger
Copy link
Member

@hongseokyoon what version of Elixir/Erlang are you running?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants