Stop cover server between eunit runs for speed

Cover gets slower and slower for each application. This is due to the
cover_server internal state. Stopping the cover server between
eunit+cover runs, emptying the cover_server state, gives a ~5-6x speed
improvement when analyzing many Erlang modules. Stopping the cover
server replaces the earlier practice of doing a cover:reset before each
run. On a project consisting of 62 dependencies with a total of 1866
Erlang modules the running time of rebar eunit decreased from ~20
minutes to ~3 minutes.
This commit is contained in:
Markus Näsman 2012-08-28 13:46:54 +02:00 committed by Tuncer Ayaz
parent ff8337f9b0
commit 2d139ea6c2

View file

@ -140,6 +140,10 @@ run_eunit(Config, CodePath, SrcErls) ->
ok
end,
%% Stop cover to clean the cover_server state. This is important if we want
%% eunit+cover to not slow down when analyzing many Erlang modules.
ok = cover:stop(),
case EunitResult of
ok ->
ok;
@ -418,16 +422,16 @@ cover_init(false, _BeamFiles) ->
{ok, not_enabled};
cover_init(true, BeamFiles) ->
%% Attempt to start the cover server, then set its group leader to
%% ?EUNIT_DIR/cover.log, so all cover log messages will go there instead of
%% to stdout. If the cover server is already started we'll reuse that
%% pid.
{ok, CoverPid} = case cover:start() of
{ok, _P} = OkStart ->
OkStart;
{error,{already_started, P}} ->
{ok, P};
{error, _Reason} = ErrorStart ->
ErrorStart
%% .eunit/cover.log, so all cover log messages will go there instead of
%% to stdout. If the cover server is already started, we'll kill that
%% server and start a new one in order not to inherit a polluted
%% cover_server state.
{ok, CoverPid} = case whereis(cover_server) of
undefined ->
cover:start();
_ ->
cover:stop(),
cover:start()
end,
{ok, F} = OkOpen = file:open(
@ -436,9 +440,6 @@ cover_init(true, BeamFiles) ->
group_leader(F, CoverPid),
%% Make sure any previous runs of cover don't unduly influence
cover:reset(),
?INFO("Cover compiling ~s\n", [rebar_utils:get_cwd()]),
Compiled = [{Beam, cover:compile_beam(Beam)} || Beam <- BeamFiles],