Current section
9 Versions
Jump to
Current section
9 Versions
Compare versions
7
files changed
+50
additions
-18
deletions
| @@ -1,8 +1,17 @@ | |
| 1 | - # ExProf [](http://travis-ci.org/parroty/exprof) |
| 1 | + # ExProf [](http://travis-ci.org/parroty/exprof) [](https://hex.pm/packages/exprof) [](https://hex.pm/packages/exprof) |
| 2 2 | A simple code profiler for Elixir using eprof. |
| 3 3 | |
| 4 4 | It provides a simple macro as a wrapper for Erlang's <a href="http://www.erlang.org/doc/man/eprof.html" target="_blank">:eprof</a> profiler. |
| 5 5 | |
| 6 | + ### Install |
| 7 | + Add `:exprof` to `deps` section of `mix.exs`. |
| 8 | + |
| 9 | + ```elixir |
| 10 | + def deps do |
| 11 | + [ {:exprof, "~> 0.2.0"} ] |
| 12 | + end |
| 13 | + ``` |
| 14 | + |
| 6 15 | ### Usage |
| 7 16 | import "ExProf.Macro", then use "profile" macro to start profiling. It prints out results, and returns them as list of records. |
| 8 17 | |
| @@ -28,6 +37,7 @@ end | |
| 28 37 | ``` |
| 29 38 | |
| 30 39 | ### Run |
| 40 | + An example to use in iex console. |
| 31 41 | |
| 32 42 | ```elixir |
| 33 43 | $ iex -S mix |
| @@ -55,3 +65,21 @@ erlang:monitor/2 1 31.03 36 [ 36.00] | |
| 55 65 | "total = 100.0" |
| 56 66 | ``` |
| 57 67 | |
| 68 | + ### Add a Mix Task |
| 69 | + An example to use as mix tasks. |
| 70 | + |
| 71 | + ```elixir |
| 72 | + defmodule Mix.Tasks.Exprof do |
| 73 | + @shortdoc "Profile using ExProf" |
| 74 | + use Mix.Task |
| 75 | + import ExProf.Macro |
| 76 | + |
| 77 | + def run(_mix_args) do |
| 78 | + profile do: do_work(2) |
| 79 | + end |
| 80 | + |
| 81 | + defp do_work(n) do |
| 82 | + :timer.sleep(n * 1000) |
| 83 | + end |
| 84 | + end |
| 85 | + ``` |
| @@ -1,17 +1,18 @@ | |
| 1 1 | {<<"app">>,<<"exprof">>}. |
| 2 2 | {<<"build_tools">>,[<<"mix">>]}. |
| 3 | - {<<"contributors">>,[<<"parroty">>]}. |
| 4 | - {<<"description">>,<<"A simple code profiler for Elixir using eprof.\n">>}. |
| 3 | + {<<"description">>,<<"A simple code profiler for Elixir using eprof.">>}. |
| 5 4 | {<<"elixir">>,<<"~> 1.0">>}. |
| 6 5 | {<<"files">>, |
| 7 6 | [<<"lib/exprof.ex">>,<<"lib/exprof/analyzer.ex">>,<<"lib/exprof/macro.ex">>, |
| 8 7 | <<"lib/exprof/reader.ex">>,<<"lib/exprof/records.ex">>, |
| 9 8 | <<"lib/sample/sample_runner.ex">>,<<"mix.exs">>,<<"README.md">>]}. |
| 10 9 | {<<"licenses">>,[<<"MIT">>]}. |
| 11 | - {<<"links">>,#{<<"GitHub">> => <<"https://github.com/parroty/exprof">>}}. |
| 10 | + {<<"links">>,[{<<"GitHub">>,<<"https://github.com/parroty/exprof">>}]}. |
| 11 | + {<<"maintainers">>,[<<"parroty">>]}. |
| 12 12 | {<<"name">>,<<"exprof">>}. |
| 13 13 | {<<"requirements">>, |
| 14 | - #{<<"exprintf">> => #{<<"app">> => <<"exprintf">>, |
| 15 | - <<"optional">> => nil, |
| 16 | - <<"requirement">> => <<"~> 0.1">>}}}. |
| 17 | - {<<"version">>,<<"0.2.0">>}. |
| 14 | + [[{<<"app">>,<<"exprintf">>}, |
| 15 | + {<<"name">>,<<"exprintf">>}, |
| 16 | + {<<"optional">>,false}, |
| 17 | + {<<"requirement">>,<<"~> 0.2">>}]]}. |
| 18 | + {<<"version">>,<<"0.2.1">>}. |
| @@ -10,7 +10,7 @@ defmodule ExProf do | |
| 10 10 | @doc """ |
| 11 11 | Start the profiling for the specified pid. |
| 12 12 | """ |
| 13 | - def start(pid \\ self) do |
| 13 | + def start(pid \\ self()) do |
| 14 14 | :eprof.start |
| 15 15 | :eprof.start_profiling([pid]) |
| 16 16 | end |
| @@ -25,7 +25,7 @@ defmodule ExProf.Analyzer do | |
| 25 25 | Print records to screen |
| 26 26 | """ |
| 27 27 | def print(records) do |
| 28 | - print_header |
| 28 | + print_header() |
| 29 29 | Enum.each(records, &(do_print(&1))) |
| 30 30 | end |
| @@ -16,7 +16,7 @@ defmodule ExProf.Macro do | |
| 16 16 | quote do |
| 17 17 | pid = spawn(ExProf.Macro, :execute_profile, [fn -> unquote(code) end]) |
| 18 18 | ExProf.start(pid) |
| 19 | - send pid, self |
| 19 | + send pid, self() |
| 20 20 | |
| 21 21 | receive do |
| 22 22 | _ -> nil |
Loading more files…