From 70b43c34b6b322d34693f475811a9463c86a3dce Mon Sep 17 00:00:00 2001 From: Vedant Kumar Date: Mon, 19 Sep 2016 00:38:29 +0000 Subject: [PATCH] [llvm-cov] Teach the coverage exporter about instantiation coverage 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 --- .../Inputs/binary-formats.canonical.json | 1 + .../llvm-cov/Inputs/highlightedRanges.json | 1 + .../llvm-cov/Inputs/lineExecutionCounts.json | 1 + test/tools/llvm-cov/Inputs/regionMarkers.json | 1 + .../tools/llvm-cov/Inputs/showExpansions.json | 1 + .../llvm-cov/Inputs/universal-binary.json | 1 + tools/llvm-cov/CoverageExporterJson.cpp | 42 ++++++++++++------- 7 files changed, 32 insertions(+), 16 deletions(-) diff --git a/test/tools/llvm-cov/Inputs/binary-formats.canonical.json b/test/tools/llvm-cov/Inputs/binary-formats.canonical.json index cd2b052000c..276bbfa4e30 100644 --- a/test/tools/llvm-cov/Inputs/binary-formats.canonical.json +++ b/test/tools/llvm-cov/Inputs/binary-formats.canonical.json @@ -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 diff --git a/test/tools/llvm-cov/Inputs/highlightedRanges.json b/test/tools/llvm-cov/Inputs/highlightedRanges.json index 4b441ab770f..0ef3cde17d2 100644 --- a/test/tools/llvm-cov/Inputs/highlightedRanges.json +++ b/test/tools/llvm-cov/Inputs/highlightedRanges.json @@ -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 diff --git a/test/tools/llvm-cov/Inputs/lineExecutionCounts.json b/test/tools/llvm-cov/Inputs/lineExecutionCounts.json index 4beab24e689..ff1c8f59dba 100644 --- a/test/tools/llvm-cov/Inputs/lineExecutionCounts.json +++ b/test/tools/llvm-cov/Inputs/lineExecutionCounts.json @@ -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 diff --git a/test/tools/llvm-cov/Inputs/regionMarkers.json b/test/tools/llvm-cov/Inputs/regionMarkers.json index 7565c9fa5d8..5bc506e4071 100644 --- a/test/tools/llvm-cov/Inputs/regionMarkers.json +++ b/test/tools/llvm-cov/Inputs/regionMarkers.json @@ -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 diff --git a/test/tools/llvm-cov/Inputs/showExpansions.json b/test/tools/llvm-cov/Inputs/showExpansions.json index 738c5e1d364..4a5bb9037fa 100644 --- a/test/tools/llvm-cov/Inputs/showExpansions.json +++ b/test/tools/llvm-cov/Inputs/showExpansions.json @@ -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 diff --git a/test/tools/llvm-cov/Inputs/universal-binary.json b/test/tools/llvm-cov/Inputs/universal-binary.json index 75d7a2fa83c..edf09f374f7 100644 --- a/test/tools/llvm-cov/Inputs/universal-binary.json +++ b/test/tools/llvm-cov/Inputs/universal-binary.json @@ -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 diff --git a/tools/llvm-cov/CoverageExporterJson.cpp b/tools/llvm-cov/CoverageExporterJson.cpp index 7941f288597..e2a798f4e69 100644 --- a/tools/llvm-cov/CoverageExporterJson.cpp +++ b/tools/llvm-cov/CoverageExporterJson.cpp @@ -36,10 +36,12 @@ // ---- 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 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 SourceFiles, - FileCoverageSummary &Summary) { + ArrayRef 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. -- 2.50.1