Skip to content

Commit b6a0b6e

Browse files
authored
'genhtml --simplfy-script callback ..' feature. (#436)
Use callback to munge function names for display. Goal is to compress the function detail table by, for example, shortening long template or namespace names. Implemented as a callback rather than, for example, as a list of regexps because any project complicated enough to need simplification is complicated enough that the required regexps will be very, very complicated. A callback is easier and more flexible. See the sample implementation in .../scripts/simplify.pl This feature may go part of the way toward satisfying #164. (Function names will not be collapsed into one entry - but the table entries can be arbitrarily simple.) Signed-off-by: Henry Cox <[email protected]>
1 parent 3ed1c3d commit b6a0b6e

File tree

13 files changed

+478
-110
lines changed

13 files changed

+478
-110
lines changed

README

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ LCOV features and capabilities fall into 7 major categories:
371371
--baseline-title, --baseline-date, --current-date,
372372
--flat, --hierarchical,
373373
--show-owners, --show-noncode, --show-navigation, --show-proportion,
374-
--suppress-aliases
374+
--suppress-aliases --simplify-script
375375

376376
d) Data manipulation
377377

@@ -421,8 +421,10 @@ LCOV features and capabilities fall into 7 major categories:
421421
the changes caused by a particular commit or range of commits,
422422
or to review changes in a particular release.
423423
Sample script: select.pm
424-
vi) keep track of environment and other settings - to aid
424+
vi) keep track of environment and other settings - to aid
425425
infrastructure debugging in more complicated use cases.
426+
vii) compress the 'function detail' table to improve readability
427+
by shortening long C++ template and function names.
426428

427429
The callback may be any desired script or executable - but there
428430
may be performance advantages if it is written as a Perl module.
@@ -436,6 +438,7 @@ LCOV features and capabilities fall into 7 major categories:
436438
Related options:
437439
--annotate-script, --criteria-script, --version-script
438440
--resolve-script, --select-script, --context-script
441+
--simplify-script
439442

440443
f) Performance
441444

bin/genhtml

Lines changed: 105 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,8 @@ sub write_overview(*$$$$);
291291
# External prototype (defined in genpng)
292292
sub gen_png($$$$$@);
293293

294+
sub simplify_function_name($);
295+
294296
package SummaryInfo;
295297

296298
our @selectCallbackScript;
@@ -5471,7 +5473,7 @@ sub _computeAge
54715473
if ($then > $now) {
54725474
if (lcovutil::warn_once($lcovutil::ERROR_INCONSISTENT_DATA, $path)) {
54735475
# issue annotation warning at most once per file
5474-
# also attempt to clarify where the date comes from
5476+
# also attempt to clarify where the date comes from
54755477
my $data =
54765478
exists($ENV{SOURCE_DATE_EPOCH}) ?
54775479
(
@@ -6853,10 +6855,14 @@ our @rate_png = ("ruby.png", "amber.png", "emerald.png");
68536855
our $rc_desc_html = 0; # lcovrc: genhtml_desc_html
68546856
our $deprecated_highlight; # ignored former option
68556857

6856-
our $cwd = cwd(); # Current working directory
6858+
# simplify/shorten names in 'function detail table'
6859+
our @simplifyFunctionScript; # the arg list
6860+
our $simplifyFunctionCallback; # the actual callback
6861+
6862+
our $cwd = cwd(); # Current working directory
68576863

68586864
# for debugging
6859-
our $verboseScopeRegexp; # dump categorization processing if match
6865+
our $verboseScopeRegexp; # dump categorization processing if match
68606866

68616867
#
68626868
# Code entry point
@@ -6869,7 +6875,8 @@ STDERR->autoflush;
68696875
STDOUT->autoflush;
68706876

68716877
my @datebins;
6872-
my (@rc_date_bins, @rc_annotate_script, @rc_select_script, @rc_date_labels);
6878+
my (@rc_date_bins, @rc_annotate_script, @rc_select_script, @rc_date_labels,
6879+
@rc_simplifyFunctionScript);
68736880

68746881
my %genhtml_rc_opts = (
68756882
"genhtml_css_file" => \$css_filename,
@@ -6925,6 +6932,7 @@ my %genhtml_rc_opts = (
69256932
'genhtml_annotate_script' => \@rc_annotate_script,
69266933
'genhtml_annotate_tooltip' => \$SourceFile::annotateTooltip,
69276934
"select_script" => \@rc_select_script,
6935+
"simplify_function" => \@rc_simplifyFunctionScript,
69286936
'num_context_lines' => \$InInterestingRegion::num_context_lines,
69296937
'genhtml_date_bins' => \@rc_date_bins,
69306938
'genhtml_date_labels' => \@rc_date_labels,
@@ -6938,60 +6946,62 @@ my $save;
69386946
my $serialize;
69396947
my $validateHTML = exists($ENV{LCOV_VALIDATE});
69406948

6941-
my %genhtml_options = ("output-directory|o=s" => \$output_directory,
6942-
"header-title=s" => \$header_title,
6943-
"footer=s" => \$footer,
6944-
"title|t=s" => \$test_title,
6945-
"description-file|d=s" => \$desc_filename,
6946-
"keep-descriptions|k" => \$keep_descriptions,
6947-
"css-file|c=s" => \$css_filename,
6948-
"baseline-file|b=s" => \@base_filenames,
6949-
"baseline-title=s" => \$baseline_title,
6950-
"baseline-date=s" => \$baseline_date,
6951-
"current-date=s" => \$current_date,
6952-
"diff-file=s" => \$diff_filename,
6953-
"annotate-script=s" => \@SourceFile::annotateScript,
6954-
"select-script=s" => \@selectCallbackScript,
6955-
"new-file-as-baseline" => \$treatNewFileAsBaseline,
6956-
'elide-path-mismatch' => \$elide_path_mismatch,
6957-
'synthesize-missing' => \$synthesizeMissingFile,
6958-
# if 'show-owners' is set: generate the owner table
6959-
# if it is passed a value: show all the owners,
6960-
# regardless of whether they have uncovered code or not
6961-
'show-owners:s' => \$show_ownerBins,
6962-
'show-noncode' => \$show_nonCodeOwners,
6963-
'show-zero-columns' => \$show_zeroTlaColumns,
6964-
'simplified-colors' => \$show_simplifiedColors,
6965-
"date-bins=s" => \@datebins,
6966-
'date-labels=s' => \@SummaryInfo::ageGroupHeader,
6967-
"prefix|p=s" => \@opt_dir_prefix,
6968-
"num-spaces=i" => \$tab_size,
6969-
"no-prefix" => \$no_prefix,
6970-
"no-sourceview" => \$no_sourceview,
6971-
'no-html' => \$no_html,
6972-
"show-details|s" => \$show_details,
6973-
"frames|f" => \$frames,
6974-
"highlight" => \$deprecated_highlight,
6975-
"legend" => \$legend,
6976-
'save' => \$save,
6977-
'serialize=s' => \$serialize,
6978-
'scheduler+' => \$debugScheduler,
6979-
"html-prolog=s" => \$html_prolog_file,
6980-
"html-epilog=s" => \$html_epilog_file,
6981-
"html-extension=s" => \$html_ext,
6982-
"html-gzip" => \$html_gzip,
6983-
"hierarchical" => \$hierarchical,
6984-
"flat" => \$flat,
6985-
"sort-tables" => \$sort_tables,
6986-
"no-sort" => \$no_sort,
6987-
"precision=i" => \$lcovutil::default_precision,
6988-
"missed" => \$opt_missed,
6989-
"dark-mode" => \$dark_mode,
6990-
"show-navigation" => \$show_tla,
6991-
"show-proportion" => \$show_functionProportions,
6992-
"merge-aliases" => \$merge_function_aliases,
6993-
"suppress-aliases" => \$suppress_function_aliases,
6994-
'validate' => \$validateHTML,);
6949+
my %genhtml_options = (
6950+
"output-directory|o=s" => \$output_directory,
6951+
"header-title=s" => \$header_title,
6952+
"footer=s" => \$footer,
6953+
"title|t=s" => \$test_title,
6954+
"description-file|d=s" => \$desc_filename,
6955+
"keep-descriptions|k" => \$keep_descriptions,
6956+
"css-file|c=s" => \$css_filename,
6957+
"baseline-file|b=s" => \@base_filenames,
6958+
"baseline-title=s" => \$baseline_title,
6959+
"baseline-date=s" => \$baseline_date,
6960+
"current-date=s" => \$current_date,
6961+
"diff-file=s" => \$diff_filename,
6962+
"annotate-script=s" => \@SourceFile::annotateScript,
6963+
"select-script=s" => \@SummaryInfo::selectCallbackScript,
6964+
"simplify-script=s" => \@simplifyFunctionScript,
6965+
"new-file-as-baseline" => \$treatNewFileAsBaseline,
6966+
'elide-path-mismatch' => \$elide_path_mismatch,
6967+
'synthesize-missing' => \$synthesizeMissingFile,
6968+
# if 'show-owners' is set: generate the owner table
6969+
# if it is passed a value: show all the owners,
6970+
# regardless of whether they have uncovered code or not
6971+
'show-owners:s' => \$show_ownerBins,
6972+
'show-noncode' => \$show_nonCodeOwners,
6973+
'show-zero-columns' => \$show_zeroTlaColumns,
6974+
'simplified-colors' => \$show_simplifiedColors,
6975+
"date-bins=s" => \@datebins,
6976+
'date-labels=s' => \@SummaryInfo::ageGroupHeader,
6977+
"prefix|p=s" => \@opt_dir_prefix,
6978+
"num-spaces=i" => \$tab_size,
6979+
"no-prefix" => \$no_prefix,
6980+
"no-sourceview" => \$no_sourceview,
6981+
'no-html' => \$no_html,
6982+
"show-details|s" => \$show_details,
6983+
"frames|f" => \$frames,
6984+
"highlight" => \$deprecated_highlight,
6985+
"legend" => \$legend,
6986+
'save' => \$save,
6987+
'serialize=s' => \$serialize,
6988+
'scheduler+' => \$debugScheduler,
6989+
"html-prolog=s" => \$html_prolog_file,
6990+
"html-epilog=s" => \$html_epilog_file,
6991+
"html-extension=s" => \$html_ext,
6992+
"html-gzip" => \$html_gzip,
6993+
"hierarchical" => \$hierarchical,
6994+
"flat" => \$flat,
6995+
"sort-tables" => \$sort_tables,
6996+
"no-sort" => \$no_sort,
6997+
"precision=i" => \$lcovutil::default_precision,
6998+
"missed" => \$opt_missed,
6999+
"dark-mode" => \$dark_mode,
7000+
"show-navigation" => \$show_tla,
7001+
"show-proportion" => \$show_functionProportions,
7002+
"merge-aliases" => \$merge_function_aliases,
7003+
"suppress-aliases" => \$suppress_function_aliases,
7004+
'validate' => \$validateHTML,);
69957005

69967006
# remove ambiguous entry from common table -
69977007
# (genhtml has '--sort-inputs' and '--sort-tables')
@@ -7041,18 +7051,28 @@ $frames = undef unless (defined($frames) && $frames);
70417051
foreach my $rc ([\@datebins, \@rc_date_bins],
70427052
[\@SummaryInfo::ageGroupHeader, \@rc_date_labels],
70437053
[\@SourceFile::annotateScript, \@rc_annotate_script],
7044-
[\@selectCallbackScript, \@rc_select_script]
7054+
[\@SummaryInfo::selectCallbackScript, \@rc_select_script],
7055+
[\@simplifyFunctionScript, \@rc_simplifyFunctionScript],
70457056

70467057
) {
70477058
@{$rc->[0]} = @{$rc->[1]} unless (@{$rc->[0]});
70487059
}
70497060

70507061
foreach my $cb ([\$SourceFile::annotateCallback, \@SourceFile::annotateScript],
7051-
[\$selectCallback, \@selectCallbackScript]) {
7062+
[\$SummaryInfo::selectCallback,
7063+
\@SummaryInfo::selectCallbackScript
7064+
],
7065+
[\$simplifyFunctionCallback, \@simplifyFunctionScript],
7066+
) {
70527067
lcovutil::configure_callback($cb->[0], @{$cb->[1]})
70537068
if scalar(@{$cb->[1]});
70547069
}
70557070

7071+
# we won't apply simplifications if we don't generate the table
7072+
# (we still check that the callback is valid - even though we don't use it)
7073+
$simplifyFunctionCallback = undef
7074+
if $no_sourceview;
7075+
70567076
if (defined($lcovutil::stop_on_error) &&
70577077
!$lcovutil::stop_on_error) {
70587078
# in the spirit of "don't stop" - don't worry about missing files.
@@ -8384,7 +8404,7 @@ sub read_testfile($)
83848404
local *TEST_HANDLE;
83858405

83868406
open(TEST_HANDLE, "<", $file) or
8387-
die("cannot open $file]: $!\n");
8407+
die("cannot open description file '$file': $!\n");
83888408

83898409
while (<TEST_HANDLE>) {
83908410
chomp($_);
@@ -13322,7 +13342,7 @@ sub write_source($$$$$$$$)
1332213342
my $cbdata = PrintCallback->new($srcfile, $fileCovInfo);
1332313343

1332413344
my ($region, $empty);
13325-
if ($selectCallback) {
13345+
if ($SummaryInfo::selectCallback) {
1332613346
$region = InInterestingRegion->new($srcfile, $fileCovInfo->lineMap());
1332713347
$empty = '';
1332813348
if ($srcfile->isProjectFile()) {
@@ -13583,7 +13603,7 @@ END_OF_HTML
1358313603
next
1358413604
if grep(/^$tla$/, ('DUB', 'DCB')); # don't display deleted functions
1358513605
my $startline = $funcEntry->line() - $func_offset;
13586-
my $name = $func;
13606+
my $name = simplify_function_name($func);
1358713607
my $countstyle;
1358813608

1358913609
# Escape special characters
@@ -13701,7 +13721,7 @@ END_OF_HTML
1370113721
}
1370213722

1370313723
# Escape special characters
13704-
$alias = escape_html($alias);
13724+
$alias = escape_html(simplify_function_name($alias));
1370513725

1370613726
write_html(*HTML_HANDLE, <<END_OF_HTML);
1370713727
<tr>
@@ -13878,3 +13898,24 @@ sub parse_dir_prefix(@)
1387813898
}
1387913899
}
1388013900
}
13901+
13902+
#
13903+
# simplify_function_name($name)
13904+
#
13905+
# apply @function_simplify_patterns to $name and return
13906+
# goal is to shorten really long demangled names/template expansions
13907+
#
13908+
sub simplify_function_name($)
13909+
{
13910+
my $name = shift;
13911+
if ($simplifyFunctionCallback) {
13912+
13913+
eval { $name = $simplifyFunctionCallback->simplify($name); };
13914+
if ($@) {
13915+
my $context = MessageContext::context();
13916+
lcovutil::ignorable_error($lcovutil::ERROR_CALLBACK,
13917+
"simplify($name) failed$context: $@");
13918+
}
13919+
}
13920+
return $name;
13921+
}

bin/llvm2lcov

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,8 @@ sub parse
239239
}
240240
if ($mcdc && $json_version < version->parse("3.0.1")) {
241241
my $mcdcData = $fileInfo->testcase_mcdc($testname);
242-
my @mcdcBranches; # array (start line, start column, expression)
242+
my @mcdcBranches
243+
; # array (start line, start column, expression)
243244
foreach my $branch (@$branches) {
244245
die("unexpected branch data")
245246
unless scalar(@$branch) == 9;
@@ -273,8 +274,8 @@ sub parse
273274
if (($brLine > $line ||
274275
($brLine == $line && $brCol >= $startCol))
275276
&&
276-
($brLine < $endLine ||
277-
($brLine == $endLine && $brCol <= $endCol))
277+
( $brLine < $endLine ||
278+
($brLine == $endLine && $brCol <= $endCol))
278279
) {
279280
push(@brExprs, [$brLine, $brCol, $brExpr]);
280281
}
@@ -344,8 +345,10 @@ sub parse
344345
$functionMap->add_count($name, $count);
345346
}
346347

347-
my @mcdcBranches; # array (fileId, start line, start column, expression)
348-
my %expanded_mcdcBranches; # hash of branch's fileId -> branch's start line
348+
my @mcdcBranches
349+
; # array (fileId, start line, start column, expression)
350+
my %expanded_mcdcBranches
351+
; # hash of branch's fileId -> branch's start line
349352

350353
if ($branchData) {
351354
my $funcBranchData = BranchData->new();
@@ -451,15 +454,17 @@ sub parse
451454
if (($brLine > $line ||
452455
($brLine == $line && $brCol >= $col))
453456
&&
454-
($brLine < $endLine ||
455-
($brLine == $endLine && $brCol <= $endCol))
457+
( $brLine < $endLine ||
458+
($brLine == $endLine &&
459+
$brCol <= $endCol))
456460
) {
457461
push(@brExprs, [$brLine, $brCol, $brExpr]);
458462
}
459463
}
460-
@brExprs = sort {$a->[0] <=> $b->[0] ||
461-
$a->[1] <=> $b->[1]
462-
} @brExprs;
464+
@brExprs = sort {
465+
$a->[0] <=> $b->[0] ||
466+
$a->[1] <=> $b->[1]
467+
} @brExprs;
463468
$expr =
464469
$srcReader->getExpr($line, $col,
465470
$endLine, $endCol)

0 commit comments

Comments
 (0)