Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Profile target #9

Merged
merged 1 commit into from
Feb 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.eunit
doc/README.md
erl_crash.dump
fprofx.*
_build
27 changes: 19 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,31 +1,42 @@
REBAR=./rebar3
CACHEGRIND=qcachegrind
REBAR3=./rebar3

all: compile

clean:
@echo "Running rebar3 clean..."
@$(REBAR) clean -a
@$(REBAR3) clean -a

compile:
@echo "Running rebar3 compile..."
@$(REBAR) as compile compile
@$(REBAR3) as compile compile

dialyzer:
@echo "Running rebar3 dialyze..."
@$(REBAR) dialyzer
@$(REBAR3) dialyzer

edoc:
@echo "Running rebar3 edoc..."
@$(REBAR) as edoc edoc
@$(REBAR3) as edoc edoc

eunit:
@echo "Running rebar3 eunit..."
@$(REBAR) do eunit -cv, cover -v
@$(REBAR3) do eunit -cv, cover -v

profile:
@echo "Profiling..."
@$(REBAR3) as test compile
@erl -noshell \
-pa _build/test/lib/*/ebin \
-eval 'anchor_profile:fprofx()' \
-eval 'init:stop()'
@_build/test/lib/fprofx/erlgrindx -p fprofx.analysis
@$(CACHEGRIND) fprofx.cgrind

test: dialyzer eunit xref

xref:
@echo "Running rebar3 xref..."
@$(REBAR) xref
@$(REBAR3) xref

.PHONY: edoc test xref
.PHONY: clean compile dialyzer edoc eunit profile xref
3 changes: 3 additions & 0 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
{deps, [
{edown, {git, "https://github.com/uwiger/edown.git", {tag, "0.7"}}}
]}
]},
{test, [
{src_dirs, ["src", "test"]}
]}
]}.

Expand Down
50 changes: 50 additions & 0 deletions test/anchor_profile.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
-module(anchor_profile).

-export([
fprofx/0
]).

-define(N, 1000).
-define(P, 20).

%% public
-spec fprofx() -> ok.

fprofx() ->
Filenames = filelib:wildcard("_build/default/lib/*/ebin/*.beam"),
Rootnames = [filename:rootname(Filename, ".beam") ||
Filename <- Filenames],
lists:foreach(fun code:load_abs/1, Rootnames),

fprofx:start(),
{ok, Tracer} = fprofx:profile(start),
fprofx:trace([start, {procs, new}, {tracer, Tracer}]),

anchor_app:start(),
anchor:set(<<"key">>, <<"value">>),

Self = self(),
[spawn(fun () ->
[anchor:get(<<"key">>) || _ <- lists:seq(1, ?N)],
Self ! exit
end) || _ <- lists:seq(1, ?P)],
wait(),

fprofx:trace(stop),
fprofx:analyse([totals, {dest, ""}]),
fprofx:stop(),

anchor_app:stop(),
ok.

%% private
wait() ->
wait(?P).

wait(0) ->
ok;
wait(X) ->
receive
exit ->
wait(X - 1)
end.