From 4cc49f7e96dc0dabaffda4f93a3e70fabd506dfa Mon Sep 17 00:00:00 2001 From: Max Moroz Date: Fri, 12 Jan 2018 20:31:32 +0000 Subject: [PATCH] [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 llvm-svn: 322397 --- tools/llvm-cov/CoverageExporterJson.cpp | 67 +++++++++++++------------ tools/llvm-cov/CoverageExporterJson.h | 6 ++- 2 files changed, 41 insertions(+), 32 deletions(-) diff --git a/tools/llvm-cov/CoverageExporterJson.cpp b/tools/llvm-cov/CoverageExporterJson.cpp index 142c6ee1542..3621f9ab97f 100644 --- a/tools/llvm-cov/CoverageExporterJson.cpp +++ b/tools/llvm-cov/CoverageExporterJson.cpp @@ -209,46 +209,24 @@ 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"); - - // Start List of Segments. - emitArrayStart(); - - for (const auto &Segment : FileCoverage) - renderSegment(Segment); - - // End List of Segments. - emitArrayEnd(); - - emitDictKey("expansions"); - - // Start List of Expansions. - emitArrayStart(); - - for (const auto &Expansion : FileCoverage.getExpansions()) - renderExpansion(Expansion); - - // End List of Expansions. - emitArrayEnd(); + // Calculate and render detailed coverage information for given file. + auto FileCoverage = Coverage.getCoverageForFile(Filename); + renderFileCoverage(FileCoverage, FileReport); } emitDictKey("summary"); @@ -258,6 +236,33 @@ void CoverageExporterJson::renderFile( emitDictEnd(); } + +void CoverageExporterJson::renderFileCoverage( + const coverage::CoverageData &FileCoverage, + const FileCoverageSummary &FileReport) { + emitDictKey("segments"); + + // Start List of Segments. + emitArrayStart(); + + for (const auto &Segment : FileCoverage) + renderSegment(Segment); + + // End List of Segments. + emitArrayEnd(); + + emitDictKey("expansions"); + + // Start List of Expansions. + emitArrayStart(); + + for (const auto &Expansion : FileCoverage.getExpansions()) + renderExpansion(Expansion); + + // End List of Expansions. + emitArrayEnd(); +} + void CoverageExporterJson::renderSegment( const coverage::CoverageSegment &Segment) { // Start Segment. diff --git a/tools/llvm-cov/CoverageExporterJson.h b/tools/llvm-cov/CoverageExporterJson.h index d576196beee..4631e94d535 100644 --- a/tools/llvm-cov/CoverageExporterJson.h +++ b/tools/llvm-cov/CoverageExporterJson.h @@ -74,9 +74,13 @@ class CoverageExporterJson : public CoverageExporter { 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);