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 ok
end, 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 case EunitResult of
ok -> ok ->
ok; ok;
@ -418,16 +422,16 @@ cover_init(false, _BeamFiles) ->
{ok, not_enabled}; {ok, not_enabled};
cover_init(true, BeamFiles) -> cover_init(true, BeamFiles) ->
%% Attempt to start the cover server, then set its group leader to %% 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 %% .eunit/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 %% to stdout. If the cover server is already started, we'll kill that
%% pid. %% server and start a new one in order not to inherit a polluted
{ok, CoverPid} = case cover:start() of %% cover_server state.
{ok, _P} = OkStart -> {ok, CoverPid} = case whereis(cover_server) of
OkStart; undefined ->
{error,{already_started, P}} -> cover:start();
{ok, P}; _ ->
{error, _Reason} = ErrorStart -> cover:stop(),
ErrorStart cover:start()
end, end,
{ok, F} = OkOpen = file:open( {ok, F} = OkOpen = file:open(
@ -436,9 +440,6 @@ cover_init(true, BeamFiles) ->
group_leader(F, CoverPid), 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()]), ?INFO("Cover compiling ~s\n", [rebar_utils:get_cwd()]),
Compiled = [{Beam, cover:compile_beam(Beam)} || Beam <- BeamFiles], Compiled = [{Beam, cover:compile_beam(Beam)} || Beam <- BeamFiles],