How to see all function invocations for a process?

In “The Soul of Erlang and Elixir”, Saša Jurić had some custom code to trace function invocations in a process and return the first 50 invocations or all invocations in 1 second, whichever comes first. But he didn’t show the code behind the function he called.

How would you do that? (My guess is that it uses recon somehow.)

2 Likes

[Turning on the @sasajuric Batman spotlight]

2 Likes

The code is available here. It’s made exclusively for that demo, so it’s not the prettiest nor particularly safe :slight_smile: You’ll probably be better off using recon or redbug in real prod.

4 Likes

Just reading it, I have no idea why I’m calling trace twice, returning an error if the second one fails. A single trace call followed by a call to trace_pattern should work.

2 Likes

We need an “Elixir in Anger” :smiley:

would you please point into the direction of how you would do that with recon or redbug in prod?

1 Like

Both of these tools have some form of such safe guards (though IIRC not exactly the same). A good place to learn more would be docs:

https://ferd.github.io/recon/recon_trace.html
https://hexdocs.pm/redbug/

1 Like

There’s also Extrace, which wraps recon to log elixir terms instead of erlang ones.