Index: docs/CommandGuide/llvm-cov.rst =================================================================== --- docs/CommandGuide/llvm-cov.rst +++ docs/CommandGuide/llvm-cov.rst @@ -382,3 +382,10 @@ It is an error to specify an architecture that is not included in the universal binary or to use an architecture that does not match a non-universal binary. + +.. option:: -summary-only + + Export only summary information for each file in the coverage data. This mode + will not export coverage information for smaller units such as individual + functions or regions. The result will be the same as produced by :program: + `llvm-cov report` command, but presented in JSON format rather than text. Index: test/tools/llvm-cov/showLineExecutionCounts.cpp =================================================================== --- test/tools/llvm-cov/showLineExecutionCounts.cpp +++ test/tools/llvm-cov/showLineExecutionCounts.cpp @@ -39,36 +39,39 @@ // RUN: FileCheck -input-file %t.export.json %S/Inputs/lineExecutionCounts.json // RUN: cat %t.export.json | %python -c "import json, sys; json.loads(sys.stdin.read())" // +// RUN: llvm-cov export %S/Inputs/lineExecutionCounts.covmapping -instr-profile %t.profdata 2>/dev/null -summary-only > %t.export-summary.json +// RUN: not grep '"name":"main"' %t.export-summary.json +// // Test html output. // RUN: llvm-cov show %S/Inputs/lineExecutionCounts.covmapping -format html -o %t.html.dir -instr-profile %t.profdata -path-equivalence=/tmp,%S %s // RUN: llvm-cov show %S/Inputs/lineExecutionCounts.covmapping -format html -o %t.html.filtered.dir -instr-profile %t.profdata -path-equivalence=/tmp,%S -name=main %s // RUN: FileCheck -check-prefixes=HTML,HTML-WHOLE-FILE -input-file %t.html.dir/coverage/tmp/showLineExecutionCounts.cpp.html %s // RUN: FileCheck -check-prefixes=HTML,HTML-FILTER -input-file %t.html.filtered.dir/coverage/tmp/showLineExecutionCounts.cpp.html %s // -// HTML-WHOLE-FILE:
[[@LINE-44]]
// before
-// HTML-FILTER-NOT: 
[[@LINE-45]]
// before
-// HTML: 
[[@LINE-44]]
161
int main() {
-// HTML: 
[[@LINE-44]]
161
  int x = 0
-// HTML: 
[[@LINE-44]]
161
-// HTML: 
[[@LINE-44]]
161
  if (x)
-// HTML: 
[[@LINE-44]]
0
-// HTML: 
[[@LINE-44]]
161
  }
-// HTML: 
[[@LINE-44]]
161
    x = 1;
-// HTML: 
[[@LINE-44]]
161
  }
-// HTML: 
[[@LINE-44]]
161
-// HTML: 
[[@LINE-44]]
16.2k
  for (int i = 0; i < 100; ++i)
-// HTML: 
[[@LINE-44]]
16.1k
    x = 1;
-// HTML: 
[[@LINE-44]]
16.1k
  }
-// HTML: 
[[@LINE-44]]
161
-// HTML: 
[[@LINE-44]]
161
  x = x < 10
-// HTML: 
[[@LINE-44]]
161
  x = x > 10
-// HTML: 
[[@LINE-44]]
0
 x - 1:
-// HTML: 
[[@LINE-44]]
161
        x + 1;
-// HTML: 
[[@LINE-44]]
161
-// HTML: 
[[@LINE-44]]
161
  return 0;
-// HTML: 
[[@LINE-44]]
161
}
-// HTML-WHOLE-FILE: 
[[@LINE-44]]
// after
-// HTML-FILTER-NOT: 
[[@LINE-45]]
// after
+// HTML-WHOLE-FILE: 
[[@LINE-47]]
// before
+// HTML-FILTER-NOT: 
[[@LINE-48]]
// before
+// HTML: 
[[@LINE-47]]
161
int main() {
+// HTML: 
[[@LINE-47]]
161
  int x = 0
+// HTML: 
[[@LINE-47]]
161
+// HTML: 
[[@LINE-47]]
161
  if (x)
+// HTML: 
[[@LINE-47]]
0
+// HTML: 
[[@LINE-47]]
161
  }
+// HTML: 
[[@LINE-47]]
161
    x = 1;
+// HTML: 
[[@LINE-47]]
161
  }
+// HTML: 
[[@LINE-47]]
161
+// HTML: 
[[@LINE-47]]
16.2k
  for (int i = 0; i < 100; ++i)
+// HTML: 
[[@LINE-47]]
16.1k
    x = 1;
+// HTML: 
[[@LINE-47]]
16.1k
  }
+// HTML: 
[[@LINE-47]]
161
+// HTML: 
[[@LINE-47]]
161
  x = x < 10
+// HTML: 
[[@LINE-47]]
161
  x = x > 10
+// HTML: 
[[@LINE-47]]
0
 x - 1:
+// HTML: 
[[@LINE-47]]
161
        x + 1;
+// HTML: 
[[@LINE-47]]
161
+// HTML: 
[[@LINE-47]]
161
  return 0;
+// HTML: 
[[@LINE-47]]
161
}
+// HTML-WHOLE-FILE: 
[[@LINE-47]]
// after
+// HTML-FILTER-NOT: 
[[@LINE-48]]
// after
 //
 // Test index creation.
 // RUN: FileCheck -check-prefix=TEXT-INDEX -input-file %t.dir/index.txt %s
Index: tools/llvm-cov/CodeCoverage.cpp
===================================================================
--- tools/llvm-cov/CodeCoverage.cpp
+++ tools/llvm-cov/CodeCoverage.cpp
@@ -631,6 +631,10 @@
       "show-instantiation-summary", cl::Optional,
       cl::desc("Show instantiation statistics in summary table"));
 
+  cl::opt SummaryOnly(
+      "summary-only", cl::Optional,
+      cl::desc("Export only summary information for each source file"));
+
   auto commandLineParser = [&, this](int argc, const char **argv) -> int {
     cl::ParseCommandLineOptions(argc, argv, "LLVM code coverage tool\n");
     ViewOpts.Debug = DebugDump;
@@ -743,6 +747,7 @@
 
     ViewOpts.ShowRegionSummary = RegionSummary;
     ViewOpts.ShowInstantiationSummary = InstantiationSummary;
+    ViewOpts.ExportSummaryOnly = SummaryOnly;
 
     return 0;
   };
Index: tools/llvm-cov/CoverageExporterJson.cpp
===================================================================
--- tools/llvm-cov/CoverageExporterJson.cpp
+++ tools/llvm-cov/CoverageExporterJson.cpp
@@ -177,8 +177,11 @@
                                                           SourceFiles, Options);
     renderFiles(SourceFiles, FileReports);
 
-    emitDictKey("functions");
-    renderFunctions(Coverage.getCoveredFunctions());
+    // Skip functions-level information for summary-only export mode.
+    if (!Options.ExportSummaryOnly) {
+      emitDictKey("functions");
+      renderFunctions(Coverage.getCoveredFunctions());
+    }
 
     emitDictKey("totals");
     renderSummary(Totals);
@@ -254,27 +257,31 @@
     emitDictStart();
 
     emitDictElement("filename", FileCoverage.getFilename());
-    emitDictKey("segments");
 
-    // Start List of Segments.
-    emitArrayStart();
+    // Skip segments and expansions for summary-only export mode.
+    if (!Options.ExportSummaryOnly) {
+      emitDictKey("segments");
 
-    for (const auto &Segment : FileCoverage)
-      renderSegment(Segment);
+      // Start List of Segments.
+      emitArrayStart();
 
-    // End List of Segments.
-    emitArrayEnd();
+      for (const auto &Segment : FileCoverage)
+        renderSegment(Segment);
+
+      // End List of Segments.
+      emitArrayEnd();
 
-    emitDictKey("expansions");
+      emitDictKey("expansions");
 
-    // Start List of Expansions.
-    emitArrayStart();
+      // Start List of Expansions.
+      emitArrayStart();
 
-    for (const auto &Expansion : FileCoverage.getExpansions())
-      renderExpansion(Expansion);
+      for (const auto &Expansion : FileCoverage.getExpansions())
+        renderExpansion(Expansion);
 
-    // End List of Expansions.
-    emitArrayEnd();
+      // End List of Expansions.
+      emitArrayEnd();
+    }
 
     emitDictKey("summary");
     renderSummary(FileReport);
Index: tools/llvm-cov/CoverageViewOptions.h
===================================================================
--- tools/llvm-cov/CoverageViewOptions.h
+++ tools/llvm-cov/CoverageViewOptions.h
@@ -32,6 +32,7 @@
   bool ShowFullFilenames;
   bool ShowRegionSummary;
   bool ShowInstantiationSummary;
+  bool ExportSummaryOnly;
   OutputFormat Format;
   std::string ShowOutputDirectory;
   std::vector DemanglerOpts;