DoTrace

Provides a trace/1 macro to trace function calls at runtime, mimicking Clojure's dotrace output.

A response to a LinkedIn post.

Example usage

iex> defmodule Math do
       def factorial(0), do: 1
       def factorial(n) when n > 0, do: n * factorial(n - 1)
     end
iex> require DoTrace
iex> DoTrace.trace(Math.factorial(5))
TRACE t1028: (factorial [5])
TRACE t1092: | (factorial [4])
TRACE t1156: | | (factorial [3])
TRACE t1220: | | | (factorial [2])
TRACE t1284: | | | | (factorial [1])
TRACE t1348: | | | | | (factorial [0])
TRACE t1348: | | | | | | => 1
TRACE t1284: | | | | | => 1
TRACE t1220: | | | | => 2
TRACE t1156: | | | => 6
TRACE t1092: | | => 24
TRACE t1028: | => 120
120

Installation

Add do_trace to your list of dependencies in mix.exs:

def deps do
  [
    {:do_trace, "~> 0.1.0"}
  ]
end

License

BSD 3-Clause

Documentation

https://hexdocs.pm/do_trace.