Skip to content

Commit ab43548

Browse files
committed
[cover] Improve performance
Add functions for cover compilation and analysis on multiple files. This allows for more parallelisation. All functions for cover compilation can now take a list of modules/files. cover:analyse/analyze and cover:analyse_to_file/analyze_to_file can be called without the Modules arguement in order to analyse all cover compiled and imported modules, or with a list of modules. Also, the number of lookups in ets tables is reduced, which has also improved the performance when analysing and resetting cover data.
1 parent 73996f6 commit ab43548

3 files changed

Lines changed: 863 additions & 367 deletions

File tree

lib/tools/doc/src/cover.xml

Lines changed: 69 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<header>
66
<copyright>
77
<year>2001</year>
8-
<year>2013</year>
8+
<year>2015</year>
99
<holder>Ericsson AB, All Rights Reserved</holder>
1010
</copyright>
1111
<legalnotice>
@@ -138,17 +138,18 @@
138138
</desc>
139139
</func>
140140
<func>
141-
<name>compile(ModFile) -> Result</name>
142-
<name>compile(ModFile, Options) -> Result</name>
143-
<name>compile_module(ModFile) -> Result</name>
144-
<name>compile_module(ModFile, Options) -> Result</name>
145-
<fsummary>Compile a module for Cover analysis.</fsummary>
141+
<name>compile(ModFiles) -> Result | [Result]</name>
142+
<name>compile(ModFiles, Options) -> Result | [Result]</name>
143+
<name>compile_module(ModFiles) -> Result | [Result]</name>
144+
<name>compile_module(ModFiles, Options) -> Result | [Result]</name>
145+
<fsummary>Compile one or more modules for Cover analysis.</fsummary>
146146
<type>
147+
<v>ModFiles = ModFile | [ModFile]</v>
147148
<v>ModFile = Module | File</v>
148149
<v>&nbsp;Module = atom()</v>
149150
<v>&nbsp;File = string()</v>
150151
<v>Options = [Option]</v>
151-
<v>&nbsp;Option = {i,Dir} | {d,Macro} | {d,Macro,Value}</v>
152+
<v>&nbsp;Option = {i,Dir} | {d,Macro} | {d,Macro,Value} | export_all</v>
152153
<d>See <c>compile:file/2.</c></d>
153154
<v>Result = {ok,Module} | {error,File} | {error,not_main_node}</v>
154155
</type>
@@ -165,6 +166,9 @@
165166
returns <c>{ok,Module}</c>. Otherwise the function returns
166167
<c>{error,File}</c>. Errors and warnings are printed as they
167168
occur.</p>
169+
<p>If a list of <c>ModFiles</c> is given as input, a list
170+
of <c>Result</c> will be returned. The order of the returned
171+
list is undefined.</p>
168172
<p>Note that the internal database is (re-)initiated during
169173
the compilation, meaning any previously collected coverage data
170174
for the module will be lost.</p>
@@ -194,9 +198,10 @@
194198
</desc>
195199
</func>
196200
<func>
197-
<name>compile_beam(ModFile) -> Result</name>
198-
<fsummary>Compile a module for Cover analysis, using an existing beam.</fsummary>
201+
<name>compile_beam(ModFiles) -> Result | [Result]</name>
202+
<fsummary>Compile one or more modules for Cover analysis, using existing beam(s).</fsummary>
199203
<type>
204+
<v>ModFiles = ModFile | [ModFile]</v>
200205
<v>ModFile = Module | BeamFile</v>
201206
<v>&nbsp;Module = atom()</v>
202207
<v>&nbsp;BeamFile = string()</v>
@@ -229,6 +234,9 @@
229234
returned.</p>
230235
<p><c>{error,BeamFile}</c> is returned if the compiled code
231236
can not be loaded on the node.</p>
237+
<p>If a list of <c>ModFiles</c> is given as input, a list
238+
of <c>Result</c> will be returned. The order of the returned
239+
list is undefined.</p>
232240
</desc>
233241
</func>
234242
<func>
@@ -251,16 +259,21 @@
251259
</desc>
252260
</func>
253261
<func>
254-
<name>analyse(Module) -> {ok,Answer} | {error,Error}</name>
255-
<name>analyse(Module, Analysis) -> {ok,Answer} | {error,Error}</name>
256-
<name>analyse(Module, Level) -> {ok,Answer} | {error,Error}</name>
257-
<name>analyse(Module, Analysis, Level) -> {ok,Answer} | {error,Error}</name>
258-
<fsummary>Analyse a Cover compiled module.</fsummary>
262+
<name>analyse() -> {result,Ok,Fail} | {error,not_main_node}</name>
263+
<name>analyse(Modules) -> OneResult | {result,Ok,Fail} | {error,not_main_node}</name>
264+
<name>analyse(Analysis) -> {result,Ok,Fail} | {error,not_main_node}</name>
265+
<name>analyse(Level) -> {result,Ok,Fail} | {error,not_main_node}</name>
266+
<name>analyse(Modules, Analysis) -> OneResult | {result,Ok,Fail} | {error,not_main_node}</name>
267+
<name>analyse(Modules, Level) -> OneResult | {result,Ok,Fail} | {error,not_main_node}</name>
268+
<name>analyse(Analysis, Level) -> {result,Ok,Fail} | {error,not_main_node}</name>
269+
<name>analyse(Modules, Analysis, Level) -> OneResult | {result,Ok,Fail} | {error,not_main_node}</name>
270+
<fsummary>Analyse one or more Cover compiled modules.</fsummary>
259271
<type>
260-
<v>Module = atom()</v>
272+
<v>Modules = Module | [Module]</v>
273+
<v>Module = atom() </v>
261274
<v>Analysis = coverage | calls</v>
262275
<v>Level = line | clause | function | module</v>
263-
<v>Answer = {Module,Value} | [{Item,Value}]</v>
276+
<v>OneResult = {ok,{Module,Value}} | {ok,[{Item,Value}]} | {error, Error}</v>
264277
<v>&nbsp;Item = Line | Clause | Function</v>
265278
<v>&nbsp;&nbsp;Line = {M,N}</v>
266279
<v>&nbsp;&nbsp;Clause = {M,F,A,C}</v>
@@ -269,49 +282,67 @@
269282
<v>&nbsp;&nbsp;&nbsp;N = A = C = integer()</v>
270283
<v>&nbsp;Value = {Cov,NotCov} | Calls</v>
271284
<v>&nbsp;&nbsp;Cov = NotCov = Calls = integer()</v>
272-
<v>Error = {not_cover_compiled,Module} | not_main_node</v>
285+
<v>&nbsp;Error = {not_cover_compiled,Module}</v>
286+
<v>Ok = [{Module,Value}] | [{Item,Value}]</v>
287+
<v>Fail = [Error]</v>
273288
</type>
274289
<desc>
275-
<p>Performs analysis of a Cover compiled module <c>Module</c>, as
290+
<p>Performs analysis of one or more Cover compiled modules, as
276291
specified by <c>Analysis</c> and <c>Level</c> (see above), by
277292
examining the contents of the internal database.</p>
278293
<p><c>Analysis</c> defaults to <c>coverage</c> and <c>Level</c>
279294
defaults to <c>function</c>.</p>
280-
<p>If <c>Module</c> is not Cover compiled, the function returns
281-
<c>{error,{not_cover_compiled,Module}}</c>.</p>
282-
<p>HINT: It is possible to issue multiple analyse_to_file commands at
283-
the same time. </p>
295+
<p>If <c>Modules</c> is an atom (one module), the return will
296+
be <c>OneResult</c>, else the return will be
297+
<c>{result,Ok,Fail}</c>.</p>
298+
<p>If <c>Modules</c> is not given, all modules that have data
299+
in the cover data table, are analysed. Note that this
300+
includes both cover compiled modules and imported
301+
modules.</p>
302+
<p>If a given module is not Cover compiled, this is indicated
303+
by the error reason <c>{not_cover_compiled,Module}</c>.</p>
284304
</desc>
285305
</func>
286306
<func>
287-
<name>analyse_to_file(Module) -> </name>
288-
<name>analyse_to_file(Module,Options) -> </name>
289-
<name>analyse_to_file(Module, OutFile) -> </name>
290-
<name>analyse_to_file(Module, OutFile, Options) -> {ok,OutFile} | {error,Error}</name>
291-
<fsummary>Detailed coverage analysis of a Cover compiled module.</fsummary>
307+
<name>analyse_to_file() -> {result,Ok,Fail} | {error,not_main_node}</name>
308+
<name>analyse_to_file(Modules) -> Answer | {result,Ok,Fail} | {error,not_main_node}</name>
309+
<name>analyse_to_file(Options) -> {result,Ok,Fail} | {error,not_main_node}</name>
310+
<name>analyse_to_file(Modules,Options) -> Answer | {result,Ok,Fail} | {error,not_main_node}</name>
311+
<fsummary>Detailed coverage analysis of one or more Cover compiled modules.</fsummary>
292312
<type>
313+
<v>Modules = Module | [Module]</v>
293314
<v>Module = atom()</v>
294-
<v>OutFile = string()</v>
315+
<v>OutFile = OutDir = string()</v>
295316
<v>Options = [Option]</v>
296-
<v>Option = html</v>
297-
<v>Error = {not_cover_compiled,Module} | {file,File,Reason} | no_source_code_found | not_main_node</v>
317+
<v>Option = html | {outfile,OutFile} | {outdir,OutDir}</v>
318+
<v>Answer = {ok,OutFile} | {error,Error}</v>
319+
<v>Ok = [OutFile]</v>
320+
<v>Fail = [Error]</v>
321+
<v>Error = {not_cover_compiled,Module} | {file,File,Reason} | {no_source_code_found,Module}</v>
298322
<v>&nbsp;File = string()</v>
299323
<v>&nbsp;Reason = term()</v>
300324
</type>
301325
<desc>
302-
<p>Makes a copy <c>OutFile</c> of the source file for a module
303-
<c>Module</c>, where it for each executable line is specified
326+
<p>Makes copies of the source file for the given modules,
327+
where it for each executable line is specified
304328
how many times it has been executed.</p>
305329
<p>The output file <c>OutFile</c> defaults to
306330
<c>Module.COVER.out</c>, or <c>Module.COVER.html</c> if the
307331
option <c>html</c> was used.</p>
308-
<p>If <c>Module</c> is not Cover compiled, the function returns
309-
<c>{error,{not_cover_compiled,Module}}</c>.</p>
332+
<p>If <c>Modules</c> is an atom (one module), the return will
333+
be <c>Answer</c>, else the return will be a
334+
list, <c>{result,Ok,Fail}</c>.</p>
335+
<p>If <c>Modules</c> is not given, all modules that have data
336+
in the cover data table, are analysed. Note that this
337+
includes both cover compiled modules and imported
338+
modules.</p>
339+
<p>If a module is not Cover compiled, this is indicated by the
340+
error reason <c>{not_cover_compiled,Module}</c>.</p>
310341
<p>If the source file and/or the output file cannot be opened using
311342
<c>file:open/2</c>, the function returns
312343
<c>{error,{file,File,Reason}}</c> where <c>File</c> is the file
313344
name and <c>Reason</c> is the error reason.</p>
314-
<p>If the module was cover compiled from the <c>.beam</c>
345+
<p>If a module was cover compiled from the <c>.beam</c>
315346
file, i.e. using <c>compile_beam/1</c> or
316347
<c>compile_beam_directory/0,1</c>, it is assumed that the
317348
source code can be found in the same directory as the
@@ -322,10 +353,8 @@
322353
joining <c>../src</c> and the tail of the compiled path
323354
below a trailing <c>src</c> component, then the compiled
324355
path itself.
325-
If no source code is found,
326-
<c>{error,no_source_code_found}</c> is returned.</p>
327-
<p>HINT: It is possible to issue multiple analyse_to_file commands at
328-
the same time. </p>
356+
If no source code is found, this is indicated by the error reason
357+
<c>{no_source_code_found,Module}</c>.</p>
329358
</desc>
330359
</func>
331360
<func>
@@ -339,7 +368,7 @@
339368
<v>OutFile = string()</v>
340369
<v>Options = [Option]</v>
341370
<v>Option = html</v>
342-
<v>Error = {not_cover_compiled,Module} | {file,File,Reason} | no_source_code_found | not_main_node</v>
371+
<v>Error = {not_cover_compiled,Module} | {file,File,Reason} | {no_source_code_found,Module} | not_main_node</v>
343372
<v>&nbsp;File = string()</v>
344373
<v>&nbsp;Reason = term()</v>
345374
</type>

0 commit comments

Comments
 (0)