Skip to content

Instantly share code, notes, and snippets.

@styx
Created May 27, 2015 11:43
Show Gist options
  • Save styx/b4810ddd968062ed1d23 to your computer and use it in GitHub Desktop.
Save styx/b4810ddd968062ed1d23 to your computer and use it in GitHub Desktop.
Elixir profiling
defmodule Test do
def run do
Enum.each(1..50, &simulated_bottleneck/1)
end
defp simulated_bottleneck(x) do
:timer.sleep(x)
end
end
defmodule Profiler do
def profile(fun) do
:fprof.apply(fun, [], file: 'profile.trace')
:fprof.profile({:file, 'profile.trace'})
:fprof.analyse(dest: 'profile.analyse')
File.rm("profile.trace")
File.read!("profile.analyse") |> IO.puts
File.rm("profile.analyst")
end
end
Profiler.profile(fn -> Test.run end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment