Skip to content

Instantly share code, notes, and snippets.

@styx

styx/elixir.ex

Created May 27, 2015
Embed
What would you like to do?
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