Skip to content

Commit d202cc8

Browse files
committed
Add hyperlink to profile data to HTML report.
Signed-off-by: Henry Cox <[email protected]>
1 parent a6849bd commit d202cc8

File tree

3 files changed

+53
-5
lines changed

3 files changed

+53
-5
lines changed

bin/genhtml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6705,7 +6705,9 @@ if ($serialize) {
67056705
}
67066706

67076707
lcovutil::cleanup_callbacks();
6708-
lcovutil::save_profile(File::Spec->catfile($output_directory, 'genhtml'));
6708+
lcovutil::save_profile(File::Spec->catfile($output_directory, 'genhtml'),
6709+
File::Spec->catfile($output_directory, 'profile.html'));
6710+
67096711
# exit with non-zero status if --keep-going and some errors detected
67106712
$exit_status = 1
67116713
if (0 == $exit_status && lcovutil::saw_error());
@@ -8926,7 +8928,7 @@ sub write_header_line(*@)
89268928
$str .= $text
89278929
if defined($text);
89288930
$str .= "</td>\n";
8929-
# so 'str' looke like '<td width="value" colspan="value">whatever</td>'
8931+
# so 'str' looked like '<td width="value" colspan="value">whatever</td>'
89308932
write_html($handle, $str);
89318933
}
89328934
write_html($handle, " </tr>\n"); # then end the row
@@ -11058,6 +11060,24 @@ sub write_header(*$$$$$$)
1105811060
[undef, "headerValue", $baseline_date]
1105911061
]);
1106011062
}
11063+
# if top-level page, link to command line and profile
11064+
if ($summary->type() eq 'top' &&
11065+
$bin_type eq '' &&
11066+
$primary_key eq 'name' &&
11067+
defined($lcovutil::profile)) {
11068+
11069+
push(@row_left,
11070+
[[undef, 'headerItem', 'genhtml Process:'],
11071+
[undef, 'headerValue',
11072+
'<span><a href="cmdline.html">Command Line</a></span>'
11073+
]
11074+
],
11075+
[[undef, 'headerItem', ''], #blank
11076+
[undef, 'headerValue',
11077+
'<span><a href="profile.html">Profile Data</a></span>'
11078+
]
11079+
]);
11080+
}
1106111081
if ($type != $HDR_SOURCE &&
1106211082
$type != $HDR_FUNC &&
1106311083
(defined($main::show_ownerBins) ||

lib/lcovutil.pm

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -819,9 +819,9 @@ sub save_cmd_line($$)
819819
$lcovutil::profileData{config}{buildDir} = Cwd::getcwd();
820820
}
821821

822-
sub save_profile($)
822+
sub save_profile($@)
823823
{
824-
my ($dest) = @_;
824+
my ($dest, $html) = @_;
825825

826826
if (defined($lcovutil::profile)) {
827827
$lcovutil::profileData{config}{maxParallel} = $maxParallelism;
@@ -852,6 +852,34 @@ sub save_profile($)
852852
} else {
853853
warn("unable to open profile output $dest: '$!'\n");
854854
}
855+
856+
# only generate the extra data if profile enabled
857+
if ($html) {
858+
859+
my $leader =
860+
'<object data="https://www.w3.org/TR/PNG/iso_8859-1.txt" width="300" height="200">'
861+
. "\n";
862+
my $tail = "</object>\n";
863+
864+
my $outDir = File::Basename::dirname($html);
865+
open(CMD, '>', File::Spec->catfile($outDir, 'cmdline.html')) or
866+
die("unable to create cmdline.html: $!");
867+
print(CMD $leader, $lcovutil::profileData{config}{cmdLine},
868+
"\n", $tail);
869+
close(CMD) or die("unable to close cmdline.html: $!");
870+
871+
# and the profile data
872+
open(PROF, '>', $html) or die("unable to create $html: $!");
873+
print(PROF $leader);
874+
875+
open(IN, '<', $dest) or die("unable to open $dest: $!");
876+
while (<IN>) {
877+
print(PROF $_);
878+
}
879+
close(IN) or die("unable to close $dest: $!");
880+
print(PROF "\n", $tail);
881+
close(PROF) or die("unable to close cmdline.html: $!");
882+
}
855883
}
856884
}
857885

tests/gendiffcov/simple/script.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1278,7 +1278,7 @@ if [ 0 != $? ] ; then
12781278
fi
12791279
fi
12801280
1281-
NAME=`(cd select2 ; ls *.html)`
1281+
NAME=`(cd select2 ; ls *.html | grep -v -E '(cmdline|profile)')`
12821282
if [ "index.html" != "$NAME" ] ; then
12831283
echo "ERROR: expected to find only one HTML file"
12841284
status=1

0 commit comments

Comments
 (0)