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: 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;