Skip to content

Commit

Permalink
Flame graphs using :eflame
Browse files Browse the repository at this point in the history
The example puzzle is the same as the one in the Sudoku solver test, except with
several more cells filled in. Using the original causes :eflame to time out
while creating the final report (see
proger/eflame#13).

Ensure rebar is installed (the original, not rebar3), and run the following:

    $ MIX_ENV=prod mix do clean, deps.get, deps.compile, compile
    $ MIX_ENV=prod iex -S mix run -e "Backtrex.Profiler.eflame; exit(:normal)"
    $ ./deps/eflame/stack_to_flame.sh < stacks.out > flame-prod.svg

Credit goes to http://learningelixir.joekain.com/profiling-elixir-2/ for getting
me started.
  • Loading branch information
jmitchell committed Jan 17, 2017
1 parent c456a1f commit 57e7692
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
25 changes: 25 additions & 0 deletions lib/backtrex/profiler.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
defmodule Backtrex.Profiler do
alias Backtrex.Examples.Sudoku

def eflame do
:eflame.apply(&run_test/0, [])
end

def example_puzzle do
{:ok, puzzle} = Sudoku.Puzzle.from_list([
[5, 3, :_, :_, 7, :_, :_, 1, 2],
[6, 7, :_, 1, 9, 5, :_, 4, :_],
[1, 9, 8, 3, :_, :_, 5, 6, 7],
[8, :_, 9, :_, 6, :_, 4, :_, 3],
[4, 2, :_, 8, :_, 3, 7, :_, 1],
[7, :_, 3, :_, 2, 4, :_, 5, 6],
[:_, 6, :_, 5, :_, 7, 2, 8, :_],
[2, :_, :_, 4, 1, 9, 6, :_, 5],
[:_, 4, 5, :_, 8, 6, :_, 7, 9]])
puzzle
end

def run_test do
{:ok, :solution, _} = example_puzzle() |> Sudoku.Solver.solve
end
end
3 changes: 2 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ defmodule Backtrex.Mixfile do
end

def application do
[extra_applications: [:logger],
[extra_applications: [:logger, :eflame],
applications: [:logger]] # format expected by Elixir 1.3
end

defp deps do
[
{:credo, "~> 0.5", only: [:dev, :test]},
{:dialyxir, "~> 0.4", only: [:dev], runtime: false},
{:eflame, ~r/.*/, git: "https://github.com/proger/eflame.git", compile: "rebar compile"},
{:ex_doc, "~> 0.14", only: :dev},
]
end
Expand Down
1 change: 1 addition & 0 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"credo": {:hex, :credo, "0.5.3", "0c405b36e7651245a8ed63c09e2d52c2e2b89b6d02b1570c4d611e0fcbecf4a2", [:mix], [{:bunt, "~> 0.1.6", [hex: :bunt, optional: false]}]},
"dialyxir": {:hex, :dialyxir, "0.4.3", "a4daeebd0107de10d3bbae2ccb6b8905e69544db1ed5fe9148ad27cd4cb2c0cd", [:mix], []},
"earmark": {:hex, :earmark, "1.0.3", "89bdbaf2aca8bbb5c97d8b3b55c5dd0cff517ecc78d417e87f1d0982e514557b", [:mix], []},
"eflame": {:git, "https://github.com/proger/eflame.git", "ee3a44b950aeb2434460045274809ad506141a83", []},
"ex_doc": {:hex, :ex_doc, "0.14.5", "c0433c8117e948404d93ca69411dd575ec6be39b47802e81ca8d91017a0cf83c", [:mix], [{:earmark, "~> 1.0", [hex: :earmark, optional: false]}]},
"inch_ex": {:hex, :inch_ex, "0.5.5", "b63f57e281467bd3456461525fdbc9e158c8edbe603da6e3e4671befde796a3d", [:mix], [{:poison, "~> 1.5 or ~> 2.0 or ~> 3.0", [hex: :poison, optional: false]}]},
"poison": {:hex, :poison, "3.0.0", "625ebd64d33ae2e65201c2c14d6c85c27cc8b68f2d0dd37828fde9c6920dd131", [:mix], []}}

0 comments on commit 57e7692

Please sign in to comment.