XProf is a profiler that allows you to track execution time of Erlang functions. It's also able to capture arguments and results of a function calls that lasted longer than given number of milliseconds.
XProf was created to help solving performance problems of live, highly concurrent and utilized BE systems. It's often the case that high latency or big CPU usage is caused by very specific requests that are triggering inefficient code. Finding this code is usually pretty difficult.
- Add
xprof
to your rebar.config (and optionally toreltool.config
in order to include it into your release). - Build your project.
- Start
xprof
by executingxprof:start()
in Erlang shell. - Go to http://SERVER:7890.
- Type in function that you would like to start tracing.
- Start tracing clicking green button.
{deps, [
...
{xprof, ".*", {git, "https://github.com/appliscale/xprof.git"}}
]}.
xprof
is available on Hex package manager, so you are able to use it also in the following way:
%% It is possible only with newest version of `rebar3` (at least `3.3.3`):
{deps, [
...
{xprof, "1.1.0"}
]}.
# Inside `mix.exs`:
defp deps do
[
...
{:xprof, "~> 1.1.0"}
]
end
You can configure xprof
by changing its application variables:
Key | Default | Description |
---|---|---|
port | 7890 | Port for the web interface |
CAUTION: Experimental support (WIP).
In the function browser you can also specify further filters in the form of a
match-spec fun (similar to recon or redbug). After the module and function name
one can also give a function definition instead of arity. This gives the user
the full power of match specifications and can be used both to selectively
measure duration of function calls that match complicated filters and to capture
only part of the arguments. The function has the same limitations as
dbg:fun2ms/1
. (See
Match Specifications in Erlang and
ms_transform). The function can
be terminated by a single dot or end.
and return_trace
is always implicitly
on (that is how xprof
measures duration)
For example only measure the duration of ets:lookup
on table data
ets:lookup([data, _]) -> true.
Or only capture the important
field of a possibly big data
record
ets:insert([_, #data{important = I}]) -> message(I).
All improvements, fixes and ideas are very welcomed!
Project uses rebar3 for building and testing erlang code. WebUI part resides in
xprof
app's priv directory and it's already precompiled so there is no need to
build JS sources in order to run xprof
.
make test
The WebUI uses
- React.js
- ECMAScript 6 (with elements from 7th version).
- Bootstap
- Bower
- Webpack
All sources are in priv directory. The app folder contains the sources and the build folder is a placeholder for final JS generated by webpack and then served by cowboy server (XProf's dependency).
To develop xprof
in convenience following setup is recommended.
You have to invoke following command once, if you do not have dependencies or you need to update them:
$ make bootstrap_front_end
Then going with normal development flow - in the first terminal window start
Erlang xprof
by calling make dev
. The sync app will be started, It
automatically reloads erlang modules that have changed, so you don't need to
recompile everytime something changed.
$ make dev
In the second window install all the assets and start webpack in development
mode which is also going to recompile all JS files in priv
directory when
they are modified. To achieve that use following command:
$ make webpack_autoreload