4
votes

Let's say I'd want to override each function call with a macro that counts how many times I called each particular function.
Is it possible in Elixir?

I know there is a possibility of overriding builtin macros and functions with

import Kernel, except: [name: arity]
import MyOwnKernel

But it doesn't seem to work for apply/2 nor apply/3

2

2 Answers

4
votes

You cannot. Those are defined as special forms (Kernel.SpecialForms) and they cannot be overridden.

4
votes

Not the answer to your direct question, but if you really want to trace function calls and do some analysis, you may consider Erlang tracing capabilities. I provided a simple example in this answer.

Also, you might look into fprof for profiling, which can give you function count. IIRC fprof analyzes only the process in which you start it, and you can't run multiple profiles simultaneously.