Skip to content

Commit

Permalink
cover: Eliminate COLLECTION_CLAUSE_TABLE
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorng committed Nov 10, 2023
1 parent dabad16 commit 24c1d31
Showing 1 changed file with 17 additions and 34 deletions.
51 changes: 17 additions & 34 deletions lib/tools/src/cover.erl
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@
%% counter array for the module. It is used both during instrumentation
%% of cover-compiled modules and when collecting the counter values.
%%
%% The main node owns the tables ?COLLECTION_TABLE and
%% ?COLLECTION_CLAUSE_TABLE. The counter data is consolidated into those
%% tables from the counters on both the main node and from remote nodes.
%% This consolidation is done when a remote node is stopped with
%% cover:stop/1 or just before starting an analysis.
%% The main node owns the table ?COLLECTION_TABLE. The counter data
%% is consolidated into this table from the counters on both the main
%% node and from remote nodes. This consolidation is done when a
%% remote node is stopped with cover:stop/1 or just before starting an
%% analysis.
%%
%% The main node also has a table named ?BINARY_TABLE. This table
%% contains the abstract code code for each cover-compiled
Expand Down Expand Up @@ -140,7 +140,6 @@
-define(COVER_MAPPING_TABLE, 'cover_internal_mapping_table').
-define(BINARY_TABLE, 'cover_binary_code_table').
-define(COLLECTION_TABLE, 'cover_collected_remote_data_table').
-define(COLLECTION_CLAUSE_TABLE, 'cover_collected_remote_clause_table').

-define(TAG, cover_compiled).
-define(SERVER, cover_server).
Expand Down Expand Up @@ -804,8 +803,6 @@ init_main(Starter) ->
?BINARY_TABLE = ets:new(?BINARY_TABLE, [set, public, named_table]),
?COLLECTION_TABLE = ets:new(?COLLECTION_TABLE, [set, public,
named_table]),
?COLLECTION_CLAUSE_TABLE = ets:new(?COLLECTION_CLAUSE_TABLE,
[set, public, named_table]),
ok = net_kernel:monitor_nodes(true),
Starter ! {?SERVER,started},
main_process_loop(#main_state{})
Expand Down Expand Up @@ -936,7 +933,6 @@ main_process_loop(State) ->
ets:delete(?COVER_MAPPING_TABLE),
ets:delete(?BINARY_TABLE),
ets:delete(?COLLECTION_TABLE),
ets:delete(?COLLECTION_CLAUSE_TABLE),
delete_all_counters(),
unregister(?SERVER),
reply(From, ok);
Expand Down Expand Up @@ -2028,7 +2024,6 @@ collect_module(Module, #main_state{nodes=Nodes}) ->
%% When analysing, the data from the local ?COVER_TABLE is moved to the
%% ?COLLECTION_TABLE. Resetting data in ?COVER_TABLE
move_modules(Module) when is_atom(Module) ->
ets:insert(?COLLECTION_CLAUSE_TABLE, {Module,[]}),
move_counters(Module).

%% Given a .beam file, find the .erl file. Look first in same directory as
Expand Down Expand Up @@ -2097,20 +2092,19 @@ analyse_list(Modules, Analysis, Level, State) ->
Loaded = [M || {M,_} <- LoadedMF],
Imported = [M || {M,_} <- ImportedMF],
collect(Loaded, State#main_state.nodes),
MS = [{{'$1','_'},[{'==','$1',M}],['$_']} || M <- Loaded ++ Imported],
AllClauses = ets:select(?COLLECTION_CLAUSE_TABLE,MS),
Fun = fun({Module,_Clauses}) ->
All = Loaded ++ Imported,
Fun = fun(Module) ->
do_analyse(Module, Analysis, Level)
end,
{result, lists:flatten(pmap(Fun, AllClauses)), Error}.
{result, lists:flatten(pmap(Fun, All)), Error}.

analyse_all(Analysis, Level, State) ->
collect(State#main_state.nodes),
AllClauses = ets:tab2list(?COLLECTION_CLAUSE_TABLE),
Fun = fun({Module,_Clauses}) ->
All = ets:tab2list(?BINARY_TABLE),
Fun = fun({Module,_}) ->
do_analyse(Module, Analysis, Level)
end,
{result, lists:flatten(pmap(Fun, AllClauses)), []}.
{result, lists:flatten(pmap(Fun, All)), []}.

do_parallel_analysis(Module, Analysis, Level, Loaded, From, State) ->
analyse_info(Module,State#main_state.imported),
Expand Down Expand Up @@ -2494,14 +2488,12 @@ merge([{Module,File,_ImportFiles}|Imported],ModuleList) ->
merge([],ModuleList) ->
ModuleList.

write_module_data([{Module,File}|ModList],Fd) ->
write({file,Module,File},Fd),
[Clauses] = ets:lookup(?COLLECTION_CLAUSE_TABLE,Module),
write(Clauses,Fd),
ModuleData = ets:match_object(?COLLECTION_TABLE,{#bump{module=Module},'_'}),
do_write_module_data(ModuleData,Fd),
write_module_data(ModList,Fd);
write_module_data([],_Fd) ->
write_module_data([{Module,File}|ModList], Fd) ->
write({file,Module,File}, Fd),
ModuleData = ets:match_object(?COLLECTION_TABLE, {#bump{module=Module},'_'}),
do_write_module_data(ModuleData, Fd),
write_module_data(ModList, Fd);
write_module_data([], _Fd) ->
ok.

do_write_module_data([H|T],Fd) ->
Expand Down Expand Up @@ -2542,14 +2534,6 @@ do_import_to_table(Fd,ImportFile,Imported,DontImport) ->
ok
end,
do_import_to_table(Fd,ImportFile,Imported,DontImport);
{Module,Clauses} ->
case lists:member(Module,DontImport) of
false ->
ets:insert(?COLLECTION_CLAUSE_TABLE,{Module,Clauses});
true ->
ok
end,
do_import_to_table(Fd,ImportFile,Imported,DontImport);
eof ->
Imported
end.
Expand Down Expand Up @@ -2579,7 +2563,6 @@ do_reset_main_node(Module,Nodes) ->
remote_reset(Module,Nodes).

do_reset_collection_table(Module) ->
ets:delete(?COLLECTION_CLAUSE_TABLE,Module),
ets:match_delete(?COLLECTION_TABLE, {#bump{module=Module},'_'}).

do_clear(Module) ->
Expand Down

0 comments on commit 24c1d31

Please sign in to comment.