Created
August 6, 2019 16:30
-
-
Save nyaray/8dc380c8df9768ac2875c54c2bb6cd20 to your computer and use it in GitHub Desktop.
paste these functions into a module where you want to profile runtimes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# call this before the code under inspection | |
defp clock_start(x) do | |
now = :erlang.timestamp() | |
Process.put(:"$clock_start", now) | |
Process.put(:"$clock_step_start", now) | |
Process.put(:"$clock_steps", []) | |
x | |
end | |
# call this after start when you want to checkpoint intermediate steps | |
defp cLOCK_STEP(x, tag) do | |
now = :erlang.timestamp() | |
step_start = Process.get(:"$clock_step_start") | |
steps = Process.get(:"$clock_steps", []) | |
Process.put(:"$clock_steps", [{tag, :timer.now_diff(now, step_start)} | steps]) | |
Process.put(:"$clock_step_start", now) | |
x | |
end | |
# call this to get all accumulated measured steps | |
defp clock_read(), do: Process.get(:"$clock_steps") |> Enum.reverse() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment