Skip to content

Commit c30d88a

Browse files
committed
genhtml: Implement option to show miss counts
Add new command line option --missed that can be used to show the number of missed lines, functions, or branches. Signed-off-by: Peter Oberparleiter <[email protected]>
1 parent 999abf2 commit c30d88a

File tree

4 files changed

+93
-10
lines changed

4 files changed

+93
-10
lines changed

bin/genhtml

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ our @opt_ignore_errors; # Ignore certain error classes during processing
287287
our @ignore;
288288
our $opt_config_file; # User-specified configuration file location
289289
our %opt_rc;
290+
our $opt_missed; # List/sort lines by missed counts
290291
our $charset = "UTF-8"; # Default charset for HTML pages
291292
our @fileview_sortlist;
292293
our @fileview_sortname = ("", "-sort-l", "-sort-f", "-sort-b");
@@ -374,6 +375,7 @@ if ($config || %opt_rc)
374375
"genhtml_charset" => \$charset,
375376
"genhtml_desc_html" => \$rc_desc_html,
376377
"genhtml_demangle_cpp" => \$demangle_cpp,
378+
"genhtml_missed" => \$opt_missed,
377379
"lcov_function_coverage" => \$lcov_func_coverage,
378380
"lcov_branch_coverage" => \$lcov_branch_coverage,
379381
});
@@ -420,6 +422,7 @@ if (!GetOptions("output-directory|o=s" => \$output_directory,
420422
"config-file=s" => \$opt_config_file,
421423
"rc=s%" => \%opt_rc,
422424
"precision=i" => \$default_precision,
425+
"missed" => \$opt_missed,
423426
))
424427
{
425428
print(STDERR "Use $tool_name --help to get usage information\n");
@@ -621,6 +624,7 @@ HTML output:
621624
--(no-)sort Enable (disable) sorted coverage views
622625
--demangle-cpp Demangle C++ function names
623626
--precision NUM Set precision of coverage rate
627+
--missed Show miss counts as negative numbers
624628
625629
For more information see: $lcov_url
626630
END_OF_USAGE
@@ -3732,6 +3736,10 @@ END_OF_HTML
37323736
$class = $rate_name[classify_rate($found, $hit,
37333737
$med, $hi)];
37343738
}
3739+
if ($opt_missed) {
3740+
# Show negative number of items without coverage
3741+
$hit = -($found - $hit);
3742+
}
37353743
write_html($handle, <<END_OF_HTML);
37363744
<td class="coverPer$class">$rate</td>
37373745
<td class="coverNum$class">$hit / $found</td>
@@ -4632,10 +4640,57 @@ END_OF_HTML
46324640
write_header_epilog(*HTML_HANDLE, $base_dir);
46334641
}
46344642

4643+
sub get_sorted_by_rate($$)
4644+
{
4645+
my ($hash, $type) = @_;
4646+
4647+
if ($type == $SORT_LINE) {
4648+
# Sort by line coverage
4649+
return sort({$hash->{$a}[7] <=> $hash->{$b}[7]} keys(%{$hash}));
4650+
} elsif ($type == $SORT_FUNC) {
4651+
# Sort by function coverage;
4652+
return sort({$hash->{$a}[8] <=> $hash->{$b}[8]} keys(%{$hash}));
4653+
} elsif ($type == $SORT_BRANCH) {
4654+
# Sort by br coverage;
4655+
return sort({$hash->{$a}[9] <=> $hash->{$b}[9]} keys(%{$hash}));
4656+
}
4657+
}
4658+
4659+
sub get_sorted_by_missed($$)
4660+
{
4661+
my ($hash, $type) = @_;
4662+
4663+
if ($type == $SORT_LINE) {
4664+
# Sort by number of instrumented lines without coverage
4665+
return sort(
4666+
{
4667+
($hash->{$b}[0] - $hash->{$b}[1]) <=>
4668+
($hash->{$a}[0] - $hash->{$a}[1])
4669+
} keys(%{$hash}));
4670+
} elsif ($type == $SORT_FUNC) {
4671+
# Sort by number of instrumented functions without coverage
4672+
return sort(
4673+
{
4674+
($hash->{$b}[2] - $hash->{$b}[3]) <=>
4675+
($hash->{$a}[2] - $hash->{$a}[3])
4676+
} keys(%{$hash}));
4677+
} elsif ($type == $SORT_BRANCH) {
4678+
# Sort by number of instrumented branches without coverage
4679+
return sort(
4680+
{
4681+
($hash->{$b}[4] - $hash->{$b}[5]) <=>
4682+
($hash->{$a}[4] - $hash->{$a}[5])
4683+
} keys(%{$hash}));
4684+
}
4685+
}
46354686

46364687
#
46374688
# get_sorted_keys(hash_ref, sort_type)
46384689
#
4690+
# hash_ref: filename -> stats
4691+
# stats: [ lines_found, lines_hit, fn_found, fn_hit, br_found, br_hit,
4692+
# link_name, line_rate, fn_rate, br_rate ]
4693+
#
46394694

46404695
sub get_sorted_keys($$)
46414696
{
@@ -4644,15 +4699,10 @@ sub get_sorted_keys($$)
46444699
if ($type == $SORT_FILE) {
46454700
# Sort by name
46464701
return sort(keys(%{$hash}));
4647-
} elsif ($type == $SORT_LINE) {
4648-
# Sort by line coverage
4649-
return sort({$hash->{$a}[7] <=> $hash->{$b}[7]} keys(%{$hash}));
4650-
} elsif ($type == $SORT_FUNC) {
4651-
# Sort by function coverage;
4652-
return sort({$hash->{$a}[8] <=> $hash->{$b}[8]} keys(%{$hash}));
4653-
} elsif ($type == $SORT_BRANCH) {
4654-
# Sort by br coverage;
4655-
return sort({$hash->{$a}[9] <=> $hash->{$b}[9]} keys(%{$hash}));
4702+
} elsif ($opt_missed) {
4703+
return get_sorted_by_missed($hash, $type);
4704+
} else {
4705+
return get_sorted_by_rate($hash, $type);
46564706
}
46574707
}
46584708

lcovrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ genhtml_desc_html=0
9696
# Specify the precision for coverage rates
9797
#genhtml_precision=1
9898

99+
# Show missed counts instead of hit counts
100+
#genhtml_missed=1
101+
99102
# Demangle C++ symbols
100103
#genhtml_demangle_cpp=1
101104

man/genhtml.1

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ genhtml \- Generate HTML view from LCOV coverage data files
6565
.IR keyword = value ]
6666
.br
6767
.RB [ \-\-precision
68-
.IR num ]
68+
.RB [ \-\-missed ]
6969
.br
7070
.IR tracefile(s)
7171
.RE
@@ -561,6 +561,21 @@ option
561561
.IR genhtml_precision .
562562
.RE
563563

564+
.B \-\-missed
565+
.RS
566+
Show counts of missed lines, functions, or branches
567+
568+
Use this option to change overview pages to show the count of lines, functions,
569+
or branches that were not hit. These counts are represented by negative numbers.
570+
571+
When specified together with \-\-sort, file and directory views will be sorted
572+
by missed counts.
573+
574+
This option can also be configured permanently using the configuration file
575+
option
576+
.IR genhtml_missed .
577+
.RE
578+
564579
.SH FILES
565580

566581
.I /etc/lcovrc

man/lcovrc.5

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ genhtml_desc_html=0
159159
#genhtml_precision=1
160160
.br
161161

162+
# Show missed counts instead of hit counts
163+
.br
164+
#genhtml_missed=1
165+
.br
166+
162167
# Demangle C++ symbols
163168
.br
164169
#genhtml_demangle_cpp=1
@@ -604,6 +609,16 @@ displaying coverage rates.
604609

605610
Default is 1.
606611
.PP
612+
.BR genhtml_missed " ="
613+
.IR 0 | 1
614+
.IP
615+
If non-zero, the count of missed lines, functions, or branches is shown
616+
as negative numbers in overview pages.
617+
.br
618+
619+
Default is 0.
620+
.PP
621+
607622
.
608623
.BR geninfo_gcov_tool " ="
609624
.I path_to_gcov

0 commit comments

Comments
 (0)