]> granicus.if.org Git - llvm/commitdiff
[llvm-cov] Unify region marker placement between text/html modes
authorVedant Kumar <vsk@apple.com>
Fri, 8 Sep 2017 18:44:46 +0000 (18:44 +0000)
committerVedant Kumar <vsk@apple.com>
Fri, 8 Sep 2017 18:44:46 +0000 (18:44 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@312813 91177308-0d34-0410-b5e6-96231b3b80d8

test/tools/llvm-cov/deferred-region.cpp
test/tools/llvm-cov/showRegionMarkers.cpp
tools/llvm-cov/CodeCoverage.cpp
tools/llvm-cov/CoverageViewOptions.h
tools/llvm-cov/SourceCoverageView.cpp
tools/llvm-cov/SourceCoverageView.h
tools/llvm-cov/SourceCoverageViewHTML.cpp
tools/llvm-cov/SourceCoverageViewText.cpp

index a11ad64e6001a9dfd5a6040f0841fb6aad4992af..905c78b1c8eb0f2ba19fd0f5b62dd1b186b66f6e 100644 (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
index c1d9e0c9167df29774b9c50fc00793e0830efbfc..b9e9f5c8df91823fcc061cc1068787b6fb766ebf 100644 (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
index f75fcb8884c47bfbbfbdf46e2222d75ecbcb65a4..b99a4189b0180fc5b090050caa82a07ded84a49b 100644 (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;
index 266b380b7d39e93b5e36dd58d328b587548ba350..144b373dc63431c3801fcccb3fcc7d27455148c2 100644 (file)
@@ -27,7 +27,6 @@ struct CoverageViewOptions {
   bool ShowLineNumbers;
   bool ShowLineStats;
   bool ShowRegionMarkers;
-  bool ShowLineStatsOrRegionMarkers;
   bool ShowExpandedRegions;
   bool ShowFunctionInstantiations;
   bool ShowFullFilenames;
index 6630f3333bd98a58f3f441af7a7526471e043e93..3806ee9c795fba24e7f600e40a0982587341bb16 100644 (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.
index c9f0c57b5cb2f1395bbc1dd3356ddd234e297e89..9b1562555a84e2874b1bef8dbe06403feb6f2584 100644 (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;
index 7548a969b9936d3fcbff4bf06106f79076bd1d4e..eecc352f225483520bc3f3f179d5b3612b33f0d5 100644 (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";
     }
   }
 
index 4ad120f642ebab0bcffdfb56cf8b26d0eda0182e..a88558fceca57089a74bc4f09599738411827864 100644 (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)
+    if (getOptions().Debug)
       errs() << "Marker at " << S->Line << ":" << S->Col << " = "
-             << formatCount(S->Count) << (S->IsRegionEntry ? "\n" : " (pop)\n");
+            << formatCount(S->Count) << "\n";
+  }
+  OS << '\n';
 }
 
 void SourceCoverageViewText::renderExpansionSite(