Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save paulo-ferraz-oliveira/117a1af2e1c3c537656eabb6d290e275 to your computer and use it in GitHub Desktop.
Save paulo-ferraz-oliveira/117a1af2e1c3c537656eabb6d290e275 to your computer and use it in GitHub Desktop.
Profiling in Elixir using :fprof

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment