OSDN Git Service

[llvm-cov] Teach the coverage exporter about instantiation coverage
authorVedant Kumar <vsk@apple.com>
Mon, 19 Sep 2016 00:38:29 +0000 (00:38 +0000)
committerVedant Kumar <vsk@apple.com>
Mon, 19 Sep 2016 00:38:29 +0000 (00:38 +0000)
While we're at it, re-use the logic from CoverageReport to compute
summaries.

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

test/tools/llvm-cov/Inputs/binary-formats.canonical.json
test/tools/llvm-cov/Inputs/highlightedRanges.json
test/tools/llvm-cov/Inputs/lineExecutionCounts.json
test/tools/llvm-cov/Inputs/regionMarkers.json
test/tools/llvm-cov/Inputs/showExpansions.json
test/tools/llvm-cov/Inputs/universal-binary.json
tools/llvm-cov/CoverageExporterJson.cpp

index cd2b052..276bbfa 100644 (file)
@@ -32,6 +32,7 @@
 // CHECK-SAME: "totals":{
 // CHECK-SAME: "lines":{"count":1,"covered":1,"percent":100,"noncode":0},
 // CHECK-SAME: "functions":{"count":1,"covered":1,"percent":100},
+// CHECK-SAME: "instantiations":{"count":1,"covered":1,"percent":100},
 // CHECK-SAME: "regions":{"count":1,"covered":1,"notcovered":0,"percent":100}}
 
 // Close the export object, data array, and root object
index 4b441ab..0ef3cde 100644 (file)
@@ -47,6 +47,7 @@
 // CHECK-SAME: "totals":{
 // CHECK-SAME: "lines":{"count":40,"covered":26,"percent":65,"noncode":0},
 // CHECK-SAME: "functions":{"count":4,"covered":4,"percent":100},
+// CHECK-SAME: "instantiations":{"count":4,"covered":4,"percent":100},
 // CHECK-SAME: "regions":{"count":19,"covered":11,"notcovered":8,"percent":57}}
 
 // Close the export object, data array, and root object
index 4beab24..ff1c8f5 100644 (file)
@@ -32,6 +32,7 @@
 // CHECK-SAME: "totals":{
 // CHECK-SAME: "lines":{"count":20,"covered":16,"percent":80,"noncode":0},
 // CHECK-SAME: "functions":{"count":1,"covered":1,"percent":100},
+// CHECK-SAME: "instantiations":{"count":1,"covered":1,"percent":100},
 // CHECK-SAME: "regions":{"count":10,"covered":7,"notcovered":3,"percent":70}}
 
 // Close the export object, data array, and root object
index 7565c9f..5bc506e 100644 (file)
@@ -31,6 +31,7 @@
 // CHECK-SAME: "totals":{
 // CHECK-SAME: "lines":{"count":21,"covered":17,"percent":80,"noncode":0},
 // CHECK-SAME: "functions":{"count":1,"covered":1,"percent":100},
+// CHECK-SAME: "instantiations":{"count":1,"covered":1,"percent":100},
 // CHECK-SAME: "regions":{"count":10,"covered":7,"notcovered":3,"percent":70}}
 
 // Close the export object, data array, and root object
index 738c5e1..4a5bb90 100644 (file)
@@ -45,6 +45,7 @@
 // CHECK-SAME: "totals":{
 // CHECK-SAME: "lines":{"count":17,"covered":15,"percent":88,"noncode":0},
 // CHECK-SAME: "functions":{"count":1,"covered":1,"percent":100},
+// CHECK-SAME: "instantiations":{"count":1,"covered":1,"percent":100},
 // CHECK-SAME: "regions":{"count":13,"covered":12,"notcovered":1,"percent":92}}
 
 // Close the export object, data array, and root object
index 75d7a2f..edf09f3 100644 (file)
@@ -30,6 +30,7 @@
 // CHECK-SAME: "totals":{
 // CHECK-SAME: "lines":{"count":1,"covered":1,"percent":100,"noncode":0},
 // CHECK-SAME: "functions":{"count":1,"covered":1,"percent":100},
+// CHECK-SAME: "instantiations":{"count":1,"covered":1,"percent":100},
 // CHECK-SAME: "regions":{"count":1,"covered":1,"notcovered":0,"percent":100}
 
 // Close the export object, data array, and root object
index 7941f28..e2a798f 100644 (file)
 // ---- Summary: dict => Object summarizing the coverage for the entire binary
 // ------ LineCoverage: dict => Object summarizing line coverage
 // ------ FunctionCoverage: dict => Object summarizing function coverage
+// ------ InstantiationCoverage: dict => Object summarizing inst. coverage
 // ------ RegionCoverage: dict => Object summarizing region coverage
 //
 //===----------------------------------------------------------------------===//
 
+#include "CoverageReport.h"
 #include "CoverageSummaryInfo.h"
 #include "CoverageViewOptions.h"
 #include "llvm/ProfileData/Coverage/CoverageMapping.h"
@@ -180,8 +182,12 @@ class CoverageExporterJson {
     emitDictElement("object", getObjectFilename());
 
     emitDictKey("files");
+
     FileCoverageSummary Totals = FileCoverageSummary("Totals");
-    renderFiles(Coverage.getUniqueSourceFiles(), Totals);
+    std::vector<StringRef> SourceFiles = Coverage.getUniqueSourceFiles();
+    auto FileReports =
+        CoverageReport::prepareFileReports(Coverage, Totals, SourceFiles);
+    renderFiles(SourceFiles, FileReports);
 
     emitDictKey("functions");
     renderFunctions(Coverage.getCoveredFunctions());
@@ -239,16 +245,14 @@ class CoverageExporterJson {
 
   /// \brief Render an array of all the source files, also pass back a Summary.
   void renderFiles(ArrayRef<StringRef> SourceFiles,
-                   FileCoverageSummary &Summary) {
+                   ArrayRef<FileCoverageSummary> FileReports) {
     // Start List of Files.
     emitArrayStart();
-    for (const auto &SourceFile : SourceFiles) {
-      // Render the file.
-      auto FileCoverage = Coverage.getCoverageForFile(SourceFile);
-      renderFile(FileCoverage);
 
-      for (const auto &F : Coverage.getCoveredFunctions(SourceFile))
-        Summary.addFunction(FunctionCoverageSummary::get(F));
+    for (unsigned I = 0, E = SourceFiles.size(); I < E; ++I) {
+      // Render the file.
+      auto FileCoverage = Coverage.getCoverageForFile(SourceFiles[I]);
+      renderFile(FileCoverage, FileReports[I]);
     }
 
     // End List of Files.
@@ -256,7 +260,8 @@ class CoverageExporterJson {
   }
 
   /// \brief Render a single file.
-  void renderFile(const CoverageData &FileCoverage) {
+  void renderFile(const CoverageData &FileCoverage,
+                  const FileCoverageSummary &FileReport) {
     // Start File.
     emitDictStart();
 
@@ -283,14 +288,8 @@ class CoverageExporterJson {
     // End List of Expansions.
     emitArrayEnd();
 
-    FileCoverageSummary Summary =
-        FileCoverageSummary(FileCoverage.getFilename());
-    for (const auto &F :
-         Coverage.getCoveredFunctions(FileCoverage.getFilename()))
-      Summary.addFunction(FunctionCoverageSummary::get(F));
-
     emitDictKey("summary");
-    renderSummary(Summary);
+    renderSummary(FileReport);
 
     // End File.
     emitDictEnd();
@@ -392,6 +391,17 @@ class CoverageExporterJson {
     // End Function Coverage Summary.
     emitDictEnd();
 
+    emitDictKey("instantiations");
+
+    // Start Instantiation Coverage Summary.
+    emitDictStart();
+    emitDictElement("count", Summary.InstantiationCoverage.NumFunctions);
+    emitDictElement("covered", Summary.InstantiationCoverage.Executed);
+    emitDictElement("percent",
+                    Summary.InstantiationCoverage.getPercentCovered());
+    // End Function Coverage Summary.
+    emitDictEnd();
+
     emitDictKey("regions");
 
     // Start Region Coverage Summary.