Something like
def trace(ms, where) do
Task.start(fn ->
# making sure file is writable (otherwise it'll only crash later, after a WHILE)
:ok = File.write(where, "")
:ok = :fprof.stop()
{:ok, _} = :fprof.start()
:ok = :fprof.trace([:start, procs: :all])
:timer.sleep(ms) # tracing...
:ok = :fprof.trace([:stop])
:ok = :fprof.profile()
:ok = :fprof.analyse(dest: String.to_atom(where))
:ok = :fprof.stop()
# Remnants of execution
:ok = File.rm("fprof.trace")
end)
end