1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 20:51:52 +01:00

[llvm-cov] Unify region marker placement between text/html modes

Make sure that the text and html emitters always emit the same set of
region markers, and avoid emitting redundant markers for line segments
which don't end on the line they start on.

This is related to D35925, and depends on D36014

Differential Revision: https://reviews.llvm.org/D36020

llvm-svn: 312813
This commit is contained in:
Vedant Kumar 2017-09-08 18:44:46 +00:00
parent 83bc5cad3a
commit 3431ecb291
8 changed files with 79 additions and 31 deletions

View File

@ -1,4 +1,4 @@
// RUN: llvm-cov show %S/Inputs/deferred-regions.covmapping -instr-profile %S/Inputs/deferred-regions.profdata -show-line-counts-or-regions -dump -path-equivalence=/Users/vk/src/llvm.org-coverage-braces/llvm/test/tools,%S/.. %s 2>&1 | FileCheck %s
// RUN: llvm-cov show %S/Inputs/deferred-regions.covmapping -instr-profile %S/Inputs/deferred-regions.profdata -show-line-counts-or-regions -dump -path-equivalence=/Users/vk/src/llvm.org-coverage-braces/llvm/test/tools,%S/.. %s &> %t.out && FileCheck %s -input-file %t.out && FileCheck %s -input-file %t.out -check-prefix=MARKER
void foo(int x) {
if (x == 0) {
@ -77,3 +77,45 @@ int main() {
gotos();
return 0;
}
// MARKER: Marker at 4:7 = 2
// MARKER-NEXT: Highlighted line 17, 5 -> 11
// MARKER-NEXT: Marker at 17:5 = 0
// MARKER-NEXT: Marker at 19:3 = 1
// MARKER-NEXT: Marker at 19:19 = 2
// MARKER-NEXT: Marker at 19:27 = 1
// MARKER-NEXT: Marker at 21:7 = 1
// MARKER-NEXT: Marker at 23:5 = 1
// MARKER-NEXT: Marker at 23:9 = 1
// MARKER-NEXT: Highlighted line 24, 7 -> 12
// MARKER-NEXT: Marker at 24:7 = 0
// MARKER-NEXT: Highlighted line 36, 5 -> 11
// MARKER-NEXT: Marker at 36:5 = 0
// MARKER-NEXT: Marker at 39:10 = 3
// MARKER-NEXT: Marker at 41:7 = 1
// MARKER-NEXT: Marker at 43:5 = 1
// MARKER-NEXT: Marker at 43:12 = 1
// MARKER-NEXT: Highlighted line 45, 14 -> ?
// MARKER-NEXT: Marker at 45:9 = 1
// MARKER-NEXT: Highlighted line 46, 1 -> ?
// MARKER-NEXT: Highlighted line 47, 1 -> 7
// MARKER-NEXT: Highlighted line 47, 7 -> 14
// MARKER-NEXT: Highlighted line 47, 14 -> 21
// MARKER-NEXT: Highlighted line 47, 21 -> 23
// MARKER-NEXT: Highlighted line 47, 23 -> 25
// MARKER-NEXT: Highlighted line 47, 25 -> ?
// MARKER-NEXT: Marker at 47:7 = 0
// MARKER-NEXT: Marker at 47:14 = 0
// MARKER-NEXT: Marker at 47:23 = 0
// MARKER-NEXT: Highlighted line 48, 1 -> 6
// MARKER-NEXT: Highlighted line 51, 7 -> 20
// MARKER-NEXT: Marker at 51:7 = 0
// MARKER-NEXT: Marker at 53:5 = 1
// MARKER-NEXT: Marker at 53:12 = 6
// MARKER-NEXT: Highlighted line 55, 9 -> 14
// MARKER-NEXT: Highlighted line 63, 5 -> 13
// MARKER-NEXT: Marker at 63:5 = 0
// MARKER-NEXT: Highlighted line 67, 1 -> ?
// MARKER-NEXT: Highlighted line 68, 1 -> 8
// MARKER-NEXT: Highlighted line 68, 8 -> ?
// MARKER-NEXT: Highlighted line 69, 1 -> 2

View File

@ -1,27 +1,28 @@
// RUN: llvm-profdata merge %S/Inputs/regionMarkers.proftext -o %t.profdata
int main() { // CHECK: Marker at [[@LINE]]:12 = 1.11M
int main() { // CHECK-NOT: Marker at [[@LINE]]:12
int x = 0;
if (x) { // CHECK: Marker at [[@LINE]]:10 = 0
if (x) { // CHECK-NOT: Marker at [[@LINE]]:10
x = 0;
} else { // CHECK: Marker at [[@LINE]]:10 = 1.11M
} else { // CHECK-NOT: Marker at [[@LINE]]:10
x = 1;
}
// CHECK: Marker at [[@LINE+2]]:19 = 112M
// CHECK: Marker at [[@LINE+1]]:28 = 111M
for (int i = 0; i < 100; ++i) { // CHECK: Marker at [[@LINE]]:33 = 111M
for (int i = 0; i < 100; ++i) { // CHECK-NOT: Marker at [[@LINE]]:33
x = 1;
}
// CHECK: Marker at [[@LINE+1]]:16 = 1.11M
x = x < 10 ? x + 1 : x - 1; // CHECK: Marker at [[@LINE]]:24 = 0
x = x > 10 ?
x - 1: // CHECK: Marker at [[@LINE]]:9 = 0
x + 1; // CHECK: Marker at [[@LINE]]:9 = 1.11M
x - 1: // CHECK-NOT: Marker at [[@LINE]]:9
x + 1; // CHECK-NOT: Marker at [[@LINE]]:9
return 0;
}
// RUN: llvm-cov show %S/Inputs/regionMarkers.covmapping -instr-profile %t.profdata -show-regions -dump -path-equivalence=/Users/bogner/code/llvm/test/tools,%S/.. %s 2>&1 | FileCheck %s
// RUN: llvm-cov show %S/Inputs/regionMarkers.covmapping -instr-profile %t.profdata -show-regions -format=html -dump -path-equivalence=/Users/bogner/code/llvm/test/tools,%S/.. %s 2>&1 | FileCheck %s
// RUN: llvm-cov export %S/Inputs/regionMarkers.covmapping -instr-profile %t.profdata 2>&1 | FileCheck %S/Inputs/regionMarkers.json

View File

@ -789,7 +789,6 @@ int CodeCoverageTool::show(int argc, const char **argv,
ViewOpts.ShowLineStats = ShowLineExecutionCounts.getNumOccurrences() != 0 ||
!ShowRegions || ShowBestLineRegionsCounts;
ViewOpts.ShowRegionMarkers = ShowRegions || ShowBestLineRegionsCounts;
ViewOpts.ShowLineStatsOrRegionMarkers = ShowBestLineRegionsCounts;
ViewOpts.ShowExpandedRegions = ShowExpansions;
ViewOpts.ShowFunctionInstantiations = ShowInstantiations;
ViewOpts.ShowOutputDirectory = ShowOutputDirectory;

View File

@ -27,7 +27,6 @@ struct CoverageViewOptions {
bool ShowLineNumbers;
bool ShowLineStats;
bool ShowRegionMarkers;
bool ShowLineStatsOrRegionMarkers;
bool ShowExpandedRegions;
bool ShowFunctionInstantiations;
bool ShowFullFilenames;

View File

@ -153,9 +153,17 @@ std::string SourceCoverageView::formatCount(uint64_t N) {
}
bool SourceCoverageView::shouldRenderRegionMarkers(
bool LineHasMultipleRegions) const {
return getOptions().ShowRegionMarkers &&
(!getOptions().ShowLineStatsOrRegionMarkers || LineHasMultipleRegions);
CoverageSegmentArray Segments) const {
if (!getOptions().ShowRegionMarkers)
return false;
// Render the region markers if there's more than one count to show.
unsigned RegionCount = 0;
for (const auto *S : Segments)
if (S->IsRegionEntry)
if (++RegionCount > 1)
return true;
return false;
}
bool SourceCoverageView::hasSubViews() const {
@ -261,7 +269,7 @@ void SourceCoverageView::print(raw_ostream &OS, bool WholeFile,
ExpansionColumn, ViewDepth);
// Show the region markers.
if (shouldRenderRegionMarkers(LineCount.hasMultipleRegions()))
if (shouldRenderRegionMarkers(LineSegments))
renderRegionMarkers(OS, LineSegments, ViewDepth);
// Show the expansions and instantiations for this line.

View File

@ -236,7 +236,7 @@ protected:
static std::string formatCount(uint64_t N);
/// \brief Check if region marker output is expected for a line.
bool shouldRenderRegionMarkers(bool LineHasMultipleRegions) const;
bool shouldRenderRegionMarkers(CoverageSegmentArray Segments) const;
/// \brief Check if there are any sub-views attached to this view.
bool hasSubViews() const;

View File

@ -547,25 +547,21 @@ void SourceCoverageViewHTML::renderLine(
// 4. Snippets[1:N+1] correspond to \p Segments[0:N]: use these to generate
// sub-line region count tooltips if needed.
bool HasMultipleRegions = [&] {
unsigned RegionCount = 0;
for (const auto *S : Segments)
if (S->HasCount && S->IsRegionEntry)
if (++RegionCount > 1)
return true;
return false;
}();
if (shouldRenderRegionMarkers(HasMultipleRegions)) {
for (unsigned I = 0, E = Segments.size(); I < E; ++I) {
if (shouldRenderRegionMarkers(Segments)) {
// Just consider the segments which start *and* end on this line.
for (unsigned I = 0, E = Segments.size() - 1; I < E; ++I) {
const auto *CurSeg = Segments[I];
if (!CurSeg->IsRegionEntry || !CurSeg->HasCount)
if (!CurSeg->IsRegionEntry)
continue;
Snippets[I + 1] =
tag("div", Snippets[I + 1] + tag("span", formatCount(CurSeg->Count),
"tooltip-content"),
"tooltip");
if (getOptions().Debug)
errs() << "Marker at " << CurSeg->Line << ":" << CurSeg->Col << " = "
<< formatCount(CurSeg->Count) << "\n";
}
}

View File

@ -171,6 +171,10 @@ void SourceCoverageViewText::renderRegionMarkers(
renderLinePrefix(OS, ViewDepth);
OS.indent(getCombinedColumnWidth(getOptions()));
// Just consider the segments which start *and* end on this line.
if (Segments.size() > 1)
Segments = Segments.drop_back();
unsigned PrevColumn = 1;
for (const auto *S : Segments) {
if (!S->IsRegionEntry)
@ -182,13 +186,12 @@ void SourceCoverageViewText::renderRegionMarkers(
std::string C = formatCount(S->Count);
PrevColumn += C.size();
OS << '^' << C;
}
OS << '\n';
if (getOptions().Debug)
for (const auto *S : Segments)
errs() << "Marker at " << S->Line << ":" << S->Col << " = "
<< formatCount(S->Count) << (S->IsRegionEntry ? "\n" : " (pop)\n");
<< formatCount(S->Count) << "\n";
}
OS << '\n';
}
void SourceCoverageViewText::renderExpansionSite(