diff options
-rw-r--r-- | docs/CommandGuide/llvm-cov.rst | 7 | ||||
-rw-r--r-- | test/tools/llvm-cov/showLineExecutionCounts.cpp | 51 | ||||
-rw-r--r-- | tools/llvm-cov/CodeCoverage.cpp | 5 | ||||
-rw-r--r-- | tools/llvm-cov/CoverageExporterJson.cpp | 39 | ||||
-rw-r--r-- | tools/llvm-cov/CoverageViewOptions.h | 1 |
5 files changed, 63 insertions, 40 deletions
diff --git a/docs/CommandGuide/llvm-cov.rst b/docs/CommandGuide/llvm-cov.rst index 6ee05ee1a0a..478ba0fb15e 100644 --- a/docs/CommandGuide/llvm-cov.rst +++ b/docs/CommandGuide/llvm-cov.rst @@ -382,3 +382,10 @@ OPTIONS 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. diff --git a/test/tools/llvm-cov/showLineExecutionCounts.cpp b/test/tools/llvm-cov/showLineExecutionCounts.cpp index c4b76824aac..f4f381a5e83 100644 --- a/test/tools/llvm-cov/showLineExecutionCounts.cpp +++ b/test/tools/llvm-cov/showLineExecutionCounts.cpp @@ -39,36 +39,39 @@ int main() { // TEXT: [[@LINE]]| 161|int main( // 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: <td class='line-number'><a name='L[[@LINE-44]]' href='#L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='uncovered-line'></td><td class='code'><pre>// before -// HTML-FILTER-NOT: <td class='line-number'><a name='L[[@LINE-45]]' href='#L[[@LINE-45]]'><pre>[[@LINE-45]]</pre></a></td><td class='uncovered-line'></td><td class='code'><pre>// before -// HTML: <td class='line-number'><a name='L[[@LINE-44]]' href='#L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre>int main() { -// HTML: <td class='line-number'><a name='L[[@LINE-44]]' href='#L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre> int x = 0 -// HTML: <td class='line-number'><a name='L[[@LINE-44]]' href='#L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre> -// HTML: <td class='line-number'><a name='L[[@LINE-44]]' href='#L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre> if (x) -// HTML: <td class='line-number'><a name='L[[@LINE-44]]' href='#L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='uncovered-line'><pre>0</pre></td><td class='code'><pre> -// HTML: <td class='line-number'><a name='L[[@LINE-44]]' href='#L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre><span class='red'> }</span> -// HTML: <td class='line-number'><a name='L[[@LINE-44]]' href='#L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre> x = 1; -// HTML: <td class='line-number'><a name='L[[@LINE-44]]' href='#L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre> } -// HTML: <td class='line-number'><a name='L[[@LINE-44]]' href='#L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre> -// HTML: <td class='line-number'><a name='L[[@LINE-44]]' href='#L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>16.2k</pre></td><td class='code'><pre> for (int i = 0; i < 100; ++i) -// HTML: <td class='line-number'><a name='L[[@LINE-44]]' href='#L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>16.1k</pre></td><td class='code'><pre> x = 1; -// HTML: <td class='line-number'><a name='L[[@LINE-44]]' href='#L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>16.1k</pre></td><td class='code'><pre> } -// HTML: <td class='line-number'><a name='L[[@LINE-44]]' href='#L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre> -// HTML: <td class='line-number'><a name='L[[@LINE-44]]' href='#L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre> x = x < 10 -// HTML: <td class='line-number'><a name='L[[@LINE-44]]' href='#L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre> x = x > 10 -// HTML: <td class='line-number'><a name='L[[@LINE-44]]' href='#L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='uncovered-line'><pre>0</pre></td><td class='code'><pre> <span class='red'>x - 1</span>: -// HTML: <td class='line-number'><a name='L[[@LINE-44]]' href='#L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre> x + 1; -// HTML: <td class='line-number'><a name='L[[@LINE-44]]' href='#L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre> -// HTML: <td class='line-number'><a name='L[[@LINE-44]]' href='#L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre> return 0; -// HTML: <td class='line-number'><a name='L[[@LINE-44]]' href='#L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre>} -// HTML-WHOLE-FILE: <td class='line-number'><a name='L[[@LINE-44]]' href='#L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='uncovered-line'></td><td class='code'><pre>// after -// HTML-FILTER-NOT: <td class='line-number'><a name='L[[@LINE-45]]' href='#L[[@LINE-45]]'><pre>[[@LINE-45]]</pre></a></td><td class='uncovered-line'></td><td class='code'><pre>// after +// HTML-WHOLE-FILE: <td class='line-number'><a name='L[[@LINE-47]]' href='#L[[@LINE-47]]'><pre>[[@LINE-47]]</pre></a></td><td class='uncovered-line'></td><td class='code'><pre>// before +// HTML-FILTER-NOT: <td class='line-number'><a name='L[[@LINE-48]]' href='#L[[@LINE-48]]'><pre>[[@LINE-48]]</pre></a></td><td class='uncovered-line'></td><td class='code'><pre>// before +// HTML: <td class='line-number'><a name='L[[@LINE-47]]' href='#L[[@LINE-47]]'><pre>[[@LINE-47]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre>int main() { +// HTML: <td class='line-number'><a name='L[[@LINE-47]]' href='#L[[@LINE-47]]'><pre>[[@LINE-47]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre> int x = 0 +// HTML: <td class='line-number'><a name='L[[@LINE-47]]' href='#L[[@LINE-47]]'><pre>[[@LINE-47]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre> +// HTML: <td class='line-number'><a name='L[[@LINE-47]]' href='#L[[@LINE-47]]'><pre>[[@LINE-47]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre> if (x) +// HTML: <td class='line-number'><a name='L[[@LINE-47]]' href='#L[[@LINE-47]]'><pre>[[@LINE-47]]</pre></a></td><td class='uncovered-line'><pre>0</pre></td><td class='code'><pre> +// HTML: <td class='line-number'><a name='L[[@LINE-47]]' href='#L[[@LINE-47]]'><pre>[[@LINE-47]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre><span class='red'> }</span> +// HTML: <td class='line-number'><a name='L[[@LINE-47]]' href='#L[[@LINE-47]]'><pre>[[@LINE-47]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre> x = 1; +// HTML: <td class='line-number'><a name='L[[@LINE-47]]' href='#L[[@LINE-47]]'><pre>[[@LINE-47]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre> } +// HTML: <td class='line-number'><a name='L[[@LINE-47]]' href='#L[[@LINE-47]]'><pre>[[@LINE-47]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre> +// HTML: <td class='line-number'><a name='L[[@LINE-47]]' href='#L[[@LINE-47]]'><pre>[[@LINE-47]]</pre></a></td><td class='covered-line'><pre>16.2k</pre></td><td class='code'><pre> for (int i = 0; i < 100; ++i) +// HTML: <td class='line-number'><a name='L[[@LINE-47]]' href='#L[[@LINE-47]]'><pre>[[@LINE-47]]</pre></a></td><td class='covered-line'><pre>16.1k</pre></td><td class='code'><pre> x = 1; +// HTML: <td class='line-number'><a name='L[[@LINE-47]]' href='#L[[@LINE-47]]'><pre>[[@LINE-47]]</pre></a></td><td class='covered-line'><pre>16.1k</pre></td><td class='code'><pre> } +// HTML: <td class='line-number'><a name='L[[@LINE-47]]' href='#L[[@LINE-47]]'><pre>[[@LINE-47]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre> +// HTML: <td class='line-number'><a name='L[[@LINE-47]]' href='#L[[@LINE-47]]'><pre>[[@LINE-47]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre> x = x < 10 +// HTML: <td class='line-number'><a name='L[[@LINE-47]]' href='#L[[@LINE-47]]'><pre>[[@LINE-47]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre> x = x > 10 +// HTML: <td class='line-number'><a name='L[[@LINE-47]]' href='#L[[@LINE-47]]'><pre>[[@LINE-47]]</pre></a></td><td class='uncovered-line'><pre>0</pre></td><td class='code'><pre> <span class='red'>x - 1</span>: +// HTML: <td class='line-number'><a name='L[[@LINE-47]]' href='#L[[@LINE-47]]'><pre>[[@LINE-47]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre> x + 1; +// HTML: <td class='line-number'><a name='L[[@LINE-47]]' href='#L[[@LINE-47]]'><pre>[[@LINE-47]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre> +// HTML: <td class='line-number'><a name='L[[@LINE-47]]' href='#L[[@LINE-47]]'><pre>[[@LINE-47]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre> return 0; +// HTML: <td class='line-number'><a name='L[[@LINE-47]]' href='#L[[@LINE-47]]'><pre>[[@LINE-47]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre>} +// HTML-WHOLE-FILE: <td class='line-number'><a name='L[[@LINE-47]]' href='#L[[@LINE-47]]'><pre>[[@LINE-47]]</pre></a></td><td class='uncovered-line'></td><td class='code'><pre>// after +// HTML-FILTER-NOT: <td class='line-number'><a name='L[[@LINE-48]]' href='#L[[@LINE-48]]'><pre>[[@LINE-48]]</pre></a></td><td class='uncovered-line'></td><td class='code'><pre>// after // // Test index creation. // RUN: FileCheck -check-prefix=TEXT-INDEX -input-file %t.dir/index.txt %s diff --git a/tools/llvm-cov/CodeCoverage.cpp b/tools/llvm-cov/CodeCoverage.cpp index 2ecd7ea6b90..00258f2a1b3 100644 --- a/tools/llvm-cov/CodeCoverage.cpp +++ b/tools/llvm-cov/CodeCoverage.cpp @@ -631,6 +631,10 @@ int CodeCoverageTool::run(Command Cmd, int argc, const char **argv) { "show-instantiation-summary", cl::Optional, cl::desc("Show instantiation statistics in summary table")); + cl::opt<bool> 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 @@ int CodeCoverageTool::run(Command Cmd, int argc, const char **argv) { ViewOpts.ShowRegionSummary = RegionSummary; ViewOpts.ShowInstantiationSummary = InstantiationSummary; + ViewOpts.ExportSummaryOnly = SummaryOnly; return 0; }; diff --git a/tools/llvm-cov/CoverageExporterJson.cpp b/tools/llvm-cov/CoverageExporterJson.cpp index 5b6b09f048e..7b700908968 100644 --- a/tools/llvm-cov/CoverageExporterJson.cpp +++ b/tools/llvm-cov/CoverageExporterJson.cpp @@ -177,8 +177,11 @@ class CoverageExporterJson { 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 @@ class CoverageExporterJson { 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); diff --git a/tools/llvm-cov/CoverageViewOptions.h b/tools/llvm-cov/CoverageViewOptions.h index a071c0aca9e..17614c4e9ba 100644 --- a/tools/llvm-cov/CoverageViewOptions.h +++ b/tools/llvm-cov/CoverageViewOptions.h @@ -32,6 +32,7 @@ struct CoverageViewOptions { bool ShowFullFilenames; bool ShowRegionSummary; bool ShowInstantiationSummary; + bool ExportSummaryOnly; OutputFormat Format; std::string ShowOutputDirectory; std::vector<std::string> DemanglerOpts; |