From 24c1d31ffcea4df172ed90d2571a6533039f4465 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Fri, 10 Nov 2023 06:30:05 +0100 Subject: [PATCH] cover: Eliminate COLLECTION_CLAUSE_TABLE --- lib/tools/src/cover.erl | 51 ++++++++++++++--------------------------- 1 file changed, 17 insertions(+), 34 deletions(-) diff --git a/lib/tools/src/cover.erl b/lib/tools/src/cover.erl index f76038cabcf5..aabbd802ae02 100644 --- a/lib/tools/src/cover.erl +++ b/lib/tools/src/cover.erl @@ -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 @@ -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). @@ -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{}) @@ -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); @@ -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 @@ -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), @@ -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) -> @@ -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. @@ -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) ->