[llvm] r322397 - [llvm-cov] Skip unnecessary coverage computations for "export -summary-only".

Max Moroz via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 12 12:31:33 PST 2018


Author: dor1s
Date: Fri Jan 12 12:31:32 2018
New Revision: 322397

URL: http://llvm.org/viewvc/llvm-project?rev=322397&view=rev
Log:
[llvm-cov] Skip unnecessary coverage computations for "export -summary-only".

Summary:
This speeds up export "summary-only" execution by an order of magnitude or two,
depending on number of threads used for prepareFileReports execution.

Also includes minor refactoring for splitting render of summary and detailed data
in two independent methods.

Reviewers: vsk, morehouse

Reviewed By: vsk

Subscribers: llvm-commits, kcc

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

Modified:
    llvm/trunk/tools/llvm-cov/CoverageExporterJson.cpp
    llvm/trunk/tools/llvm-cov/CoverageExporterJson.h

Modified: llvm/trunk/tools/llvm-cov/CoverageExporterJson.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/CoverageExporterJson.cpp?rev=322397&r1=322396&r2=322397&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/CoverageExporterJson.cpp (original)
+++ llvm/trunk/tools/llvm-cov/CoverageExporterJson.cpp Fri Jan 12 12:31:32 2018
@@ -209,53 +209,58 @@ void CoverageExporterJson::renderFiles(
   emitArrayStart();
 
   for (unsigned I = 0, E = SourceFiles.size(); I < E; ++I) {
-    // Render the file.
-    auto FileCoverage = Coverage.getCoverageForFile(SourceFiles[I]);
-    renderFile(FileCoverage, FileReports[I]);
+    renderFile(SourceFiles[I], FileReports[I]);
   }
 
   // End List of Files.
   emitArrayEnd();
 }
 
-void CoverageExporterJson::renderFile(
-    const coverage::CoverageData &FileCoverage,
-    const FileCoverageSummary &FileReport) {
-  // Start File.
+void CoverageExporterJson::renderFile(const std::string &Filename,
+                                      const FileCoverageSummary &FileReport) {
+   // Start File.
   emitDictStart();
 
-  emitDictElement("filename", FileCoverage.getFilename());
-
-  // Skip segments and expansions for summary-only export mode.
+  emitDictElement("filename", Filename);
+  
   if (!Options.ExportSummaryOnly) {
-    emitDictKey("segments");
+    // Calculate and render detailed coverage information for given file.
+    auto FileCoverage = Coverage.getCoverageForFile(Filename);
+    renderFileCoverage(FileCoverage, FileReport);
+  }
+
+  emitDictKey("summary");
+  renderSummary(FileReport);
+
+  // End File.
+  emitDictEnd();
+}
 
-    // Start List of Segments.
-    emitArrayStart();
 
-    for (const auto &Segment : FileCoverage)
-      renderSegment(Segment);
+void CoverageExporterJson::renderFileCoverage(
+    const coverage::CoverageData &FileCoverage,
+    const FileCoverageSummary &FileReport) {
+  emitDictKey("segments");
 
-    // End List of Segments.
-    emitArrayEnd();
+  // Start List of Segments.
+  emitArrayStart();
 
-    emitDictKey("expansions");
+  for (const auto &Segment : FileCoverage)
+    renderSegment(Segment);
 
-    // Start List of Expansions.
-    emitArrayStart();
+  // End List of Segments.
+  emitArrayEnd();
 
-    for (const auto &Expansion : FileCoverage.getExpansions())
-      renderExpansion(Expansion);
+  emitDictKey("expansions");
 
-    // End List of Expansions.
-    emitArrayEnd();
-  }
+  // Start List of Expansions.
+  emitArrayStart();
 
-  emitDictKey("summary");
-  renderSummary(FileReport);
+  for (const auto &Expansion : FileCoverage.getExpansions())
+    renderExpansion(Expansion);
 
-  // End File.
-  emitDictEnd();
+  // End List of Expansions.
+  emitArrayEnd();
 }
 
 void CoverageExporterJson::renderSegment(

Modified: llvm/trunk/tools/llvm-cov/CoverageExporterJson.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/CoverageExporterJson.h?rev=322397&r1=322396&r2=322397&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/CoverageExporterJson.h (original)
+++ llvm/trunk/tools/llvm-cov/CoverageExporterJson.h Fri Jan 12 12:31:32 2018
@@ -74,9 +74,13 @@ class CoverageExporterJson : public Cove
                    ArrayRef<FileCoverageSummary> FileReports);
 
   /// \brief Render a single file.
-  void renderFile(const coverage::CoverageData &FileCoverage,
+  void renderFile(const std::string &Filename,
                   const FileCoverageSummary &FileReport);
 
+  /// \brief Render summary for a single file.
+  void renderFileCoverage(const coverage::CoverageData &FileCoverage,
+                          const FileCoverageSummary &FileReport);
+
   /// \brief Render a CoverageSegment.
   void renderSegment(const coverage::CoverageSegment &Segment);
 




More information about the llvm-commits mailing list