Skip to content

Commit abdd369

Browse files
committed
Add option to filter blank lines 'aggressively': ignore them regardless
of whether their 'hit' count is zero or not. This may be useful in LLVM-generated coverage data which tends to contain large number of these - distorting statistics. Signed-off-by: Henry Cox <[email protected]>
1 parent 39dc203 commit abdd369

File tree

4 files changed

+45
-6
lines changed

4 files changed

+45
-6
lines changed

lcovrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ max_message_count = 100
8282
# if nonzero, bitwise operators '|', '&', '~' indicate conditional expressions
8383
#filter_bitwise_conditional = 1
8484

85+
# if nonzero, '--filter blank' is applied to blank lines, regardless
86+
# of their hit count
87+
#filter_blank_aggressive = 1
88+
8589
# Width of line coverage field in source code view
8690
genhtml_line_field_width = 12
8791

lib/lcovutil.pm

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ our @EXPORT_OK = qw($tool_name $tool_dir $lcov_version $lcov_url
6666
$exclude_exception_branch
6767
$derive_function_end_line $derive_function_end_line_all_files
6868
$trivial_function_threshold
69+
$filter_blank_aggressive
6970
7071
$lcov_filter_parallel $lcov_filter_chunk_size
7172
@@ -312,6 +313,8 @@ our $source_filter_lookahead = 10;
312313
# by default, don't treat expressions containing bitwise operators '|', '&', '~'
313314
# as conditional in bogus branch filtering
314315
our $source_filter_bitwise_are_conditional = 0;
316+
# filter out blank lines whether they are hit or not
317+
our $filter_blank_aggressive = 0;
315318

316319
our %dark_palette = ('COLOR_00' => "e4e4e4",
317320
'COLOR_01' => "58a6ff",
@@ -1064,11 +1067,12 @@ my %rc_common = (
10641067
"filter_lookahead" => \$lcovutil::source_filter_lookahead,
10651068
"filter_bitwise_conditional" =>
10661069
\$lcovutil::source_filter_bitwise_are_conditional,
1067-
"profile" => \$lcovutil::profile,
1068-
"parallel" => \$lcovutil::maxParallelism,
1069-
"memory" => \$lcovutil::maxMemory,
1070-
"memory_percentage" => \$lcovutil::memoryPercentage,
1071-
'source_directory' => \@rc_source_directories,
1070+
'filter_blank_aggressive' => \$filter_blank_aggressive,
1071+
"profile" => \$lcovutil::profile,
1072+
"parallel" => \$lcovutil::maxParallelism,
1073+
"memory" => \$lcovutil::maxMemory,
1074+
"memory_percentage" => \$lcovutil::memoryPercentage,
1075+
'source_directory' => \@rc_source_directories,
10721076

10731077
"no_exception_branch" => \$lcovutil::exclude_exception_branch,
10741078
'filter' => \@rc_filter,
@@ -5774,7 +5778,9 @@ sub _filterFile
57745778
unless $outOfRange ||
57755779
$excluded;
57765780
my $isBlank =
5777-
($blank_histogram && $l_hit == 0 && $srcReader->isBlank($line))
5781+
($blank_histogram &&
5782+
($lcovutil::filter_blank_aggressive || $l_hit == 0) &&
5783+
$srcReader->isBlank($line))
57785784
unless $outOfRange ||
57795785
$excluded;
57805786
next

man/genhtml.1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1934,6 +1934,10 @@ These lines seem to appear and disappear in gcov output - and cause differential
19341934

19351935
.IP blank: 3
19361936
ignore lines which contain only whitespace (or whitespace + comments) whose 'hit' count is zero. These appear to be a 'gcov' artifact related to compiler-generated code - such as exception handlers and destructor calls at the end of scope - and can confuse differential coverage criteria.
1937+
.br
1938+
If lcovrc option
1939+
.I filter_blank_aggressive = 1
1940+
is enabled, then blank lines will be ignored whether their 'hit' count is zero or not. Aggressive filtering may be useful in LLVM-generated coverage data, which tends to include large numbers of such lines.
19371941
.PP
19381942

19391943
.IP directive: 3

man/lcovrc.5

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,14 @@ max_message_count = 100
216216
.br
217217
#filter_bitwise_conditional = 1
218218
.br
219+
.br
220+
# if nonzero, '--filter blank' is applied to blank lines, regardless
221+
.br
222+
# of their hit count
223+
.br
224+
#filter_blank_aggressive = 1
225+
.br
226+
.br
219227

220228
# Width of line coverage field in source code view
221229
.br
@@ -868,6 +876,23 @@ This option is used by genhtml and lcov.
868876

869877
.PP
870878

879+
.BR filter_blank_aggressive " ="
880+
.IR 0|1
881+
.IP
882+
If set to non-zero value, then blank source lines will be ignored whether
883+
or not their 'hit' count is zero.
884+
See the
885+
.I \-\-filter blank
886+
section in man
887+
.B genhtml(1).
888+
.br
889+
890+
If not specified, the default set is 0 (filter blank lines only if they are not hit).
891+
.br
892+
There is no command line option equivalent.
893+
894+
.PP
895+
871896
.BR ignore_errors " ="
872897
.IR message_type(,message_type)*
873898
.IP

0 commit comments

Comments
 (0)