Index: tools/llvm-cov/CoverageExporterJson.h =================================================================== --- tools/llvm-cov/CoverageExporterJson.h +++ tools/llvm-cov/CoverageExporterJson.h @@ -74,9 +74,13 @@ ArrayRef 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); Index: tools/llvm-cov/CoverageExporterJson.cpp =================================================================== --- tools/llvm-cov/CoverageExporterJson.cpp +++ tools/llvm-cov/CoverageExporterJson.cpp @@ -209,53 +209,58 @@ 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); + } - // Start List of Segments. - emitArrayStart(); + emitDictKey("summary"); + renderSummary(FileReport); - for (const auto &Segment : FileCoverage) - renderSegment(Segment); + // End File. + emitDictEnd(); +} - // End List of Segments. - emitArrayEnd(); - emitDictKey("expansions"); +void CoverageExporterJson::renderFileCoverage( + const coverage::CoverageData &FileCoverage, + const FileCoverageSummary &FileReport) { + emitDictKey("segments"); + + // Start List of Segments. + emitArrayStart(); - // Start List of Expansions. - emitArrayStart(); + for (const auto &Segment : FileCoverage) + renderSegment(Segment); - for (const auto &Expansion : FileCoverage.getExpansions()) - renderExpansion(Expansion); + // End List of Segments. + emitArrayEnd(); - // End List of Expansions. - emitArrayEnd(); - } + emitDictKey("expansions"); - emitDictKey("summary"); - renderSummary(FileReport); + // Start List of Expansions. + emitArrayStart(); - // End File. - emitDictEnd(); + for (const auto &Expansion : FileCoverage.getExpansions()) + renderExpansion(Expansion); + + // End List of Expansions. + emitArrayEnd(); } void CoverageExporterJson::renderSegment(