[llvm] r314310 - [llvm-cov] Create directory structure when filtering using -name*= options

Sean Eveson via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 27 08:37:40 PDT 2017


Author: seaneveson
Date: Wed Sep 27 08:37:40 2017
New Revision: 314310

URL: http://llvm.org/viewvc/llvm-project?rev=314310&view=rev
Log:
[llvm-cov] Create directory structure when filtering using -name*= options

Before this change using any of the -name*= command line options with an output
directory would result in a single file (functions.txt/functions.html)
containing the coverage for those specific functions. Now you get the same
directory structure as when not using any -name*= options.

Differential Revision: https://reviews.llvm.org/D38280

Added:
    llvm/trunk/test/tools/llvm-cov/Inputs/dir-with-filtering.covmapping   (with props)
    llvm/trunk/test/tools/llvm-cov/Inputs/dir-with-filtering.proftext
    llvm/trunk/test/tools/llvm-cov/Inputs/dir-with-filtering1.cpp
    llvm/trunk/test/tools/llvm-cov/Inputs/dir-with-filtering2.cpp
    llvm/trunk/test/tools/llvm-cov/dir-with-filtering.test
Modified:
    llvm/trunk/test/tools/llvm-cov/showLineExecutionCounts.cpp
    llvm/trunk/test/tools/llvm-cov/showTemplateInstantiations.cpp
    llvm/trunk/test/tools/llvm-cov/style.test
    llvm/trunk/tools/llvm-cov/CodeCoverage.cpp
    llvm/trunk/tools/llvm-cov/CoverageReport.cpp
    llvm/trunk/tools/llvm-cov/CoverageReport.h
    llvm/trunk/tools/llvm-cov/SourceCoverageView.cpp
    llvm/trunk/tools/llvm-cov/SourceCoverageView.h
    llvm/trunk/tools/llvm-cov/SourceCoverageViewHTML.cpp
    llvm/trunk/tools/llvm-cov/SourceCoverageViewHTML.h
    llvm/trunk/tools/llvm-cov/SourceCoverageViewText.cpp
    llvm/trunk/tools/llvm-cov/SourceCoverageViewText.h

Added: llvm/trunk/test/tools/llvm-cov/Inputs/dir-with-filtering.covmapping
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/Inputs/dir-with-filtering.covmapping?rev=314310&view=auto
==============================================================================
Binary file - no diff available.

Propchange: llvm/trunk/test/tools/llvm-cov/Inputs/dir-with-filtering.covmapping
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: llvm/trunk/test/tools/llvm-cov/Inputs/dir-with-filtering.proftext
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/Inputs/dir-with-filtering.proftext?rev=314310&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-cov/Inputs/dir-with-filtering.proftext (added)
+++ llvm/trunk/test/tools/llvm-cov/Inputs/dir-with-filtering.proftext Wed Sep 27 08:37:40 2017
@@ -0,0 +1,32 @@
+main
+# Func Hash:
+0
+# Num Counters:
+1
+# Counter Values:
+1
+
+_Z2f1v
+# Func Hash:
+0
+# Num Counters:
+1
+# Counter Values:
+1
+
+_Z2f2v
+# Func Hash:
+0
+# Num Counters:
+1
+# Counter Values:
+0
+
+_Z2f3v
+# Func Hash:
+0
+# Num Counters:
+1
+# Counter Values:
+0
+

Added: llvm/trunk/test/tools/llvm-cov/Inputs/dir-with-filtering1.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/Inputs/dir-with-filtering1.cpp?rev=314310&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-cov/Inputs/dir-with-filtering1.cpp (added)
+++ llvm/trunk/test/tools/llvm-cov/Inputs/dir-with-filtering1.cpp Wed Sep 27 08:37:40 2017
@@ -0,0 +1,8 @@
+int f1() {
+  return 1;
+}
+
+int main() {
+  f1();
+  return 0;
+}

Added: llvm/trunk/test/tools/llvm-cov/Inputs/dir-with-filtering2.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/Inputs/dir-with-filtering2.cpp?rev=314310&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-cov/Inputs/dir-with-filtering2.cpp (added)
+++ llvm/trunk/test/tools/llvm-cov/Inputs/dir-with-filtering2.cpp Wed Sep 27 08:37:40 2017
@@ -0,0 +1,8 @@
+int f2() {
+  return 2;
+}
+
+int f3() {
+  return 3;
+}
+

Added: llvm/trunk/test/tools/llvm-cov/dir-with-filtering.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/dir-with-filtering.test?rev=314310&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-cov/dir-with-filtering.test (added)
+++ llvm/trunk/test/tools/llvm-cov/dir-with-filtering.test Wed Sep 27 08:37:40 2017
@@ -0,0 +1,69 @@
+RUN: llvm-profdata merge %S/Inputs/dir-with-filtering.proftext -o %t.profdata
+
+// Test TEXT both files
+
+RUN: llvm-cov show %S/Inputs/dir-with-filtering.covmapping -o %t.text -instr-profile %t.profdata -path-equivalence=/tmp,%S/Inputs -name=main -name=f2
+
+RUN: FileCheck -input-file=%t.text/index.txt %s -check-prefix=TEXT-INDEX
+TEXT-INDEX: dir-with-filtering1.cpp 1 0 100.00% 1 0 100.00% 4 0 100.00%
+TEXT-INDEX: dir-with-filtering2.cpp 1 1 0.00% 1 1 0.00% 3 3 0.00%
+
+RUN: FileCheck -input-file=%t.text/coverage/tmp/dir-with-filtering1.cpp.txt %s -check-prefix=TEXT-FILE1
+TEXT-FILE1: Coverage Report
+TEXT-FILE1-NOT: _Z2f1v:
+TEXT-FILE1: main:
+TEXT-FILE1-NEXT: {{.*}}int main()
+TEXT-FILE1-NOT: _Z2f1v:
+
+RUN: FileCheck -input-file=%t.text/coverage/tmp/dir-with-filtering2.cpp.txt %s -check-prefix=TEXT-FILE2
+TEXT-FILE2: Coverage Report
+TEXT-FILE2-NOT: _Z2f3v:
+TEXT-FILE2: _Z2f2v:
+TEXT-FILE2-NEXT: {{.*}}int f2()
+TEXT-FILE2-NOT: _Z2f3v:
+
+// Test TEXT one file
+
+RUN: llvm-cov show %S/Inputs/dir-with-filtering.covmapping -o %t.text_one_file -instr-profile %t.profdata -path-equivalence=/tmp,%S/Inputs -name=main -name=f2 %S/Inputs/dir-with-filtering1.cpp
+
+RUN: FileCheck -input-file=%t.text_one_file/index.txt %s -check-prefix=TEXT-INDEX-ONE-FILE
+TEXT-INDEX-ONE-FILE: dir-with-filtering1.cpp 1 0 100.00% 1 0 100.00% 4 0 100.00%
+TEXT-INDEX-ONE-FILE-NOT: dir-with-filtering2.cpp
+
+RUN: FileCheck -input-file=%t.text_one_file/coverage/tmp/dir-with-filtering1.cpp.txt %s -check-prefix=TEXT-FILE1
+
+// Test HTML both files
+
+RUN: llvm-profdata merge %S/Inputs/dir-with-filtering.proftext -o %t.profdata
+RUN: llvm-cov show %S/Inputs/dir-with-filtering.covmapping -format html -o %t.html -instr-profile %t.profdata -path-equivalence=/tmp,%S/Inputs -name=main -name=f2
+
+RUN: FileCheck -input-file=%t.html/index.html %s -check-prefix=HTML-INDEX
+HTML-INDEX: <h2>Coverage Report</h2>
+HTML-INDEX: dir-with-filtering1.cpp{{.*}}100.00% (1/1){{.*}}100.00% (4/4){{.*}}100.00% (1/1)
+HTML-INDEX: dir-with-filtering2.cpp{{.*}}0.00% (0/1){{.*}}0.00% (0/3){{.*}}0.00% (0/1)
+
+RUN: FileCheck -input-file=%t.html/coverage/tmp/dir-with-filtering1.cpp.html %s -check-prefix=HTML-FILE1
+HTML-FILE1-NOT: <pre>f1</pre>
+HTML-FILE1: <pre>main</pre>
+HTML-FILE1-NOT: <pre>f1</pre>
+HTML-FILE1: int main()
+HTML-FILE1-NOT: <pre>f1</pre>
+
+RUN: FileCheck -input-file=%t.html/coverage/tmp/dir-with-filtering2.cpp.html %s -check-prefix=HTML-FILE2
+HTML-FILE2-NOT: <pre>f3</pre>
+HTML-FILE2: <pre>_Z2f2v</pre>
+HTML-FILE2-NOT: <pre>f3</pre>
+HTML-FILE2: int f2()
+HTML-FILE2-NOT: <pre>f3</pre>
+
+// Test HTML one file
+
+RUN: llvm-profdata merge %S/Inputs/dir-with-filtering.proftext -o %t.profdata
+RUN: llvm-cov show %S/Inputs/dir-with-filtering.covmapping -format html -o %t.html_one_file -instr-profile %t.profdata -path-equivalence=/tmp,%S/Inputs -name=main -name=f2 %S/Inputs/dir-with-filtering1.cpp
+
+RUN: FileCheck -input-file=%t.html_one_file/index.html %s -check-prefix=HTML-INDEX-ONE-FILE
+HTML-INDEX-ONE-FILE: <h2>Coverage Report</h2>
+HTML-INDEX-ONE-FILE: dir-with-filtering1.cpp{{.*}}100.00% (1/1){{.*}}100.00% (4/4){{.*}}100.00% (1/1)
+HTML-INDEX-ONE-FILE-NOT: dir-with-filtering2.cpp
+
+RUN: FileCheck -input-file=%t.html_one_file/coverage/tmp/dir-with-filtering1.cpp.html %s -check-prefix=HTML-FILE1

Modified: llvm/trunk/test/tools/llvm-cov/showLineExecutionCounts.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/showLineExecutionCounts.cpp?rev=314310&r1=314309&r2=314310&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-cov/showLineExecutionCounts.cpp (original)
+++ llvm/trunk/test/tools/llvm-cov/showLineExecutionCounts.cpp Wed Sep 27 08:37:40 2017
@@ -31,9 +31,9 @@ int main() {
 
 // Test -output-dir.
 // RUN: llvm-cov show %S/Inputs/lineExecutionCounts.covmapping -o %t.dir -instr-profile %t.profdata -path-equivalence=/tmp,%S %s
-// RUN: llvm-cov show %S/Inputs/lineExecutionCounts.covmapping -output-dir %t.dir -instr-profile %t.profdata -path-equivalence=/tmp,%S -name=main %s
+// RUN: llvm-cov show %S/Inputs/lineExecutionCounts.covmapping -output-dir %t.filtered.dir -instr-profile %t.profdata -path-equivalence=/tmp,%S -name=main %s
 // RUN: FileCheck -check-prefixes=TEXT,WHOLE-FILE -input-file %t.dir/coverage/tmp/showLineExecutionCounts.cpp.txt %s
-// RUN: FileCheck -check-prefixes=TEXT,FILTER -input-file %t.dir/functions.txt %s
+// RUN: FileCheck -check-prefixes=TEXT,FILTER -input-file %t.filtered.dir/coverage/tmp/showLineExecutionCounts.cpp.txt %s
 //
 // RUN: llvm-cov export %S/Inputs/lineExecutionCounts.covmapping -instr-profile %t.profdata -name=main 2>/dev/null > %t.export.json
 // RUN: FileCheck -input-file %t.export.json %S/Inputs/lineExecutionCounts.json
@@ -41,9 +41,9 @@ int main() {
 //
 // 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.dir -instr-profile %t.profdata -path-equivalence=/tmp,%S -name=main %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.dir/functions.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

Modified: llvm/trunk/test/tools/llvm-cov/showTemplateInstantiations.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/showTemplateInstantiations.cpp?rev=314310&r1=314309&r2=314310&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-cov/showTemplateInstantiations.cpp (original)
+++ llvm/trunk/test/tools/llvm-cov/showTemplateInstantiations.cpp Wed Sep 27 08:37:40 2017
@@ -41,9 +41,9 @@ int main() {         // ALL:         [[@
 
 // Test html output.
 // RUN: llvm-cov show %S/Inputs/templateInstantiations.covmapping -instr-profile %S/Inputs/templateInstantiations.profdata -path-equivalence=/tmp,%S %s -format html -o %t.html.dir
-// RUN: llvm-cov show %S/Inputs/templateInstantiations.covmapping -instr-profile %S/Inputs/templateInstantiations.profdata -path-equivalence=/tmp,%S -name=_Z4funcIbEiT_ %s -format html -o %t.html.dir
+// RUN: llvm-cov show %S/Inputs/templateInstantiations.covmapping -instr-profile %S/Inputs/templateInstantiations.profdata -path-equivalence=/tmp,%S -name=_Z4funcIbEiT_ %s -format html -o %t.html.filtered.dir
 // RUN: FileCheck -check-prefixes=HTML-SHARED,HTML-ALL -input-file=%t.html.dir/coverage/tmp/showTemplateInstantiations.cpp.html %s
-// RUN: FileCheck -check-prefixes=HTML-SHARED,HTML-FILTER -input-file=%t.html.dir/functions.html %s
+// RUN: FileCheck -check-prefixes=HTML-SHARED,HTML-FILTER -input-file=%t.html.filtered.dir/coverage/tmp/showTemplateInstantiations.cpp.html %s
 
 // HTML-ALL: <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

Modified: llvm/trunk/test/tools/llvm-cov/style.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/style.test?rev=314310&r1=314309&r2=314310&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-cov/style.test (original)
+++ llvm/trunk/test/tools/llvm-cov/style.test Wed Sep 27 08:37:40 2017
@@ -1,14 +1,17 @@
 RUN: llvm-cov show %S/Inputs/templateInstantiations.covmapping -instr-profile %S/Inputs/templateInstantiations.profdata -path-equivalence=/tmp,%S %S/showTemplateInstantiations.cpp -format html -o %t.dir
 
-RUN: llvm-cov show %S/Inputs/templateInstantiations.covmapping -instr-profile %S/Inputs/templateInstantiations.profdata -path-equivalence=/tmp,%S -name=_Z4funcIbEiT_ %S/showTemplateInstantiations.cpp -format html -o %t.dir
+RUN: llvm-cov show %S/Inputs/templateInstantiations.covmapping -instr-profile %S/Inputs/templateInstantiations.profdata -path-equivalence=/tmp,%S -name=_Z4funcIbEiT_ %S/showTemplateInstantiations.cpp -format html -o %t.filtered.dir
 
 RUN: llvm-cov show %S/Inputs/templateInstantiations.covmapping -instr-profile %S/Inputs/templateInstantiations.profdata -path-equivalence=/tmp,%S %S/showTemplateInstantiations.cpp -format html | FileCheck %s -check-prefix=NODIR
 
 RUN: FileCheck %s -input-file=%t.dir/style.css -check-prefix=STYLE
-RUN: FileCheck %s -input-file=%t.dir/functions.html -check-prefix=TOPLEVEL
 RUN: FileCheck %s -input-file=%t.dir/index.html -check-prefix=TOPLEVEL
 RUN: FileCheck %s -input-file=%t.dir/coverage/tmp/showTemplateInstantiations.cpp.html -check-prefix=FILEVIEW
 
+RUN: FileCheck %s -input-file=%t.filtered.dir/style.css -check-prefix=STYLE
+RUN: FileCheck %s -input-file=%t.filtered.dir/index.html -check-prefix=TOPLEVEL
+RUN: FileCheck %s -input-file=%t.filtered.dir/coverage/tmp/showTemplateInstantiations.cpp.html -check-prefix=FILEVIEW
+
 STYLE-DAG: .red
 STYLE-DAG: .cyan
 STYLE-DAG: .source-name-title

Modified: llvm/trunk/tools/llvm-cov/CodeCoverage.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/CodeCoverage.cpp?rev=314310&r1=314309&r2=314310&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/CodeCoverage.cpp (original)
+++ llvm/trunk/tools/llvm-cov/CodeCoverage.cpp Wed Sep 27 08:37:40 2017
@@ -35,7 +35,9 @@
 #include "llvm/Support/Threading.h"
 #include "llvm/Support/ThreadPool.h"
 #include "llvm/Support/ToolOutputFile.h"
+
 #include <functional>
+#include <map>
 #include <system_error>
 
 using namespace llvm;
@@ -526,7 +528,8 @@ void CodeCoverageTool::writeSourceFileVi
   auto OS = std::move(OSOrErr.get());
 
   View->print(*OS.get(), /*Wholefile=*/true,
-              /*ShowSourceName=*/ShowFilenames);
+              /*ShowSourceName=*/ShowFilenames,
+              /*ShowTitle=*/ViewOpts.hasOutputDirectory());
   Printer->closeViewFile(std::move(OS));
 }
 
@@ -845,29 +848,54 @@ int CodeCoverageTool::show(int argc, con
 
   auto Printer = CoveragePrinter::create(ViewOpts);
 
-  if (!Filters.empty()) {
-    auto OSOrErr = Printer->createViewFile("functions", /*InToplevel=*/true);
-    if (Error E = OSOrErr.takeError()) {
-      error("Could not create view file!", toString(std::move(E)));
+  if (SourceFiles.empty())
+    // Get the source files from the function coverage mapping.
+    for (StringRef Filename : Coverage->getUniqueSourceFiles())
+      SourceFiles.push_back(Filename);
+
+  // Create an index out of the source files.
+  if (ViewOpts.hasOutputDirectory()) {
+    if (Error E = Printer->createIndexFile(SourceFiles, *Coverage, Filters)) {
+      error("Could not create index file!", toString(std::move(E)));
       return 1;
     }
-    auto OS = std::move(OSOrErr.get());
+  }
 
-    // Show functions.
-    for (const auto &Function : Coverage->getCoveredFunctions()) {
-      if (!Filters.matches(*Coverage.get(), Function))
-        continue;
-
-      auto mainView = createFunctionView(Function, *Coverage);
-      if (!mainView) {
-        warning("Could not read coverage for '" + Function.Name + "'.");
-        continue;
+  if (!Filters.empty()) {
+    // Build the map of filenames to functions.
+    std::map<llvm::StringRef, std::vector<const FunctionRecord *>>
+        FilenameFunctionMap;
+    for (const auto &SourceFile : SourceFiles)
+      for (const auto &Function : Coverage->getCoveredFunctions(SourceFile))
+        if (Filters.matches(*Coverage.get(), Function))
+          FilenameFunctionMap[SourceFile].push_back(&Function);
+
+    // Only print filter matching functions for each file.
+    for (const auto &FileFunc : FilenameFunctionMap) {
+      const StringRef &File = FileFunc.first;
+      const auto &Functions = FileFunc.second;
+
+      auto OSOrErr = Printer->createViewFile(File, /*InToplevel=*/false);
+      if (Error E = OSOrErr.takeError()) {
+        error("Could not create view file!", toString(std::move(E)));
+        return 1;
       }
+      auto OS = std::move(OSOrErr.get());
 
-      mainView->print(*OS.get(), /*WholeFile=*/false, /*ShowSourceName=*/true);
-    }
+      bool ShowTitle = true;
+      for (const auto *Function : Functions) {
+        auto FunctionView = createFunctionView(*Function, *Coverage);
+        if (!FunctionView) {
+          warning("Could not read coverage for '" + Function->Name + "'.");
+          continue;
+        }
+        FunctionView->print(*OS.get(), /*WholeFile=*/false,
+                            /*ShowSourceName=*/true, ShowTitle);
+        ShowTitle = false;
+      }
 
-    Printer->closeViewFile(std::move(OS));
+      Printer->closeViewFile(std::move(OS));
+    }
     return 0;
   }
 
@@ -876,19 +904,6 @@ int CodeCoverageTool::show(int argc, con
       (SourceFiles.size() != 1) || ViewOpts.hasOutputDirectory() ||
       (ViewOpts.Format == CoverageViewOptions::OutputFormat::HTML);
 
-  if (SourceFiles.empty())
-    // Get the source files from the function coverage mapping.
-    for (StringRef Filename : Coverage->getUniqueSourceFiles())
-      SourceFiles.push_back(Filename);
-
-  // Create an index out of the source files.
-  if (ViewOpts.hasOutputDirectory()) {
-    if (Error E = Printer->createIndexFile(SourceFiles, *Coverage)) {
-      error("Could not create index file!", toString(std::move(E)));
-      return 1;
-    }
-  }
-
   // If NumThreads is not specified, auto-detect a good default.
   if (NumThreads == 0)
     NumThreads =

Modified: llvm/trunk/tools/llvm-cov/CoverageReport.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/CoverageReport.cpp?rev=314310&r1=314309&r2=314310&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/CoverageReport.cpp (original)
+++ llvm/trunk/tools/llvm-cov/CoverageReport.cpp Wed Sep 27 08:37:40 2017
@@ -322,7 +322,8 @@ void CoverageReport::renderFunctionRepor
 
 std::vector<FileCoverageSummary> CoverageReport::prepareFileReports(
     const coverage::CoverageMapping &Coverage, FileCoverageSummary &Totals,
-    ArrayRef<std::string> Files, const CoverageViewOptions &Options) {
+    ArrayRef<std::string> Files, const CoverageViewOptions &Options,
+    const CoverageFilter &Filters) {
   std::vector<FileCoverageSummary> FileReports;
   unsigned LCP = getRedundantPrefixLen(Files);
 
@@ -332,11 +333,15 @@ std::vector<FileCoverageSummary> Coverag
     for (const auto &Group : Coverage.getInstantiationGroups(Filename)) {
       std::vector<FunctionCoverageSummary> InstantiationSummaries;
       for (const coverage::FunctionRecord *F : Group.getInstantiations()) {
+        if (!Filters.matches(Coverage, *F))
+          continue;
         auto InstantiationSummary = FunctionCoverageSummary::get(Coverage, *F);
         Summary.addInstantiation(InstantiationSummary);
         Totals.addInstantiation(InstantiationSummary);
         InstantiationSummaries.push_back(InstantiationSummary);
       }
+      if (InstantiationSummaries.empty())
+        continue;
 
       auto GroupSummary =
           FunctionCoverageSummary::get(Group, InstantiationSummaries);
@@ -359,13 +364,15 @@ void CoverageReport::renderFileReports(r
   std::vector<std::string> UniqueSourceFiles;
   for (StringRef SF : Coverage.getUniqueSourceFiles())
     UniqueSourceFiles.emplace_back(SF.str());
-  renderFileReports(OS, UniqueSourceFiles);
+  renderFileReports(OS, UniqueSourceFiles, CoverageFiltersMatchAll());
 }
 
 void CoverageReport::renderFileReports(raw_ostream &OS,
-                                       ArrayRef<std::string> Files) const {
+                                       ArrayRef<std::string> Files,
+                                       const CoverageFilter &Filters) const {
   FileCoverageSummary Totals("TOTAL");
-  auto FileReports = prepareFileReports(Coverage, Totals, Files, Options);
+  auto FileReports =
+      prepareFileReports(Coverage, Totals, Files, Options, Filters);
 
   std::vector<StringRef> Filenames;
   for (const FileCoverageSummary &FCS : FileReports)

Modified: llvm/trunk/tools/llvm-cov/CoverageReport.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/CoverageReport.h?rev=314310&r1=314309&r2=314310&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/CoverageReport.h (original)
+++ llvm/trunk/tools/llvm-cov/CoverageReport.h Wed Sep 27 08:37:40 2017
@@ -14,6 +14,7 @@
 #ifndef LLVM_COV_COVERAGEREPORT_H
 #define LLVM_COV_COVERAGEREPORT_H
 
+#include "CoverageFilters.h"
 #include "CoverageSummaryInfo.h"
 #include "CoverageViewOptions.h"
 
@@ -40,13 +41,16 @@ public:
   static std::vector<FileCoverageSummary>
   prepareFileReports(const coverage::CoverageMapping &Coverage,
                      FileCoverageSummary &Totals, ArrayRef<std::string> Files,
-                     const CoverageViewOptions &Options);
+                     const CoverageViewOptions &Options,
+                     const CoverageFilter &Filters = CoverageFiltersMatchAll());
 
   /// Render file reports for every unique file in the coverage mapping.
   void renderFileReports(raw_ostream &OS) const;
 
-  /// Render file reports for the files specified in \p Files.
-  void renderFileReports(raw_ostream &OS, ArrayRef<std::string> Files) const;
+  /// Render file reports for the files specified in \p Files and the functions
+  /// in \p Filters.
+  void renderFileReports(raw_ostream &OS, ArrayRef<std::string> Files,
+                         const CoverageFilter &Filters) const;
 };
 
 } // end namespace llvm

Modified: llvm/trunk/tools/llvm-cov/SourceCoverageView.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/SourceCoverageView.cpp?rev=314310&r1=314309&r2=314310&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/SourceCoverageView.cpp (original)
+++ llvm/trunk/tools/llvm-cov/SourceCoverageView.cpp Wed Sep 27 08:37:40 2017
@@ -164,8 +164,9 @@ void SourceCoverageView::addInstantiatio
 }
 
 void SourceCoverageView::print(raw_ostream &OS, bool WholeFile,
-                               bool ShowSourceName, unsigned ViewDepth) {
-  if (WholeFile && getOptions().hasOutputDirectory())
+                               bool ShowSourceName, bool ShowTitle,
+                               unsigned ViewDepth) {
+  if (ShowTitle)
     renderTitle(OS, "Coverage Report");
 
   renderViewHeader(OS);

Modified: llvm/trunk/tools/llvm-cov/SourceCoverageView.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/SourceCoverageView.h?rev=314310&r1=314309&r2=314310&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/SourceCoverageView.h (original)
+++ llvm/trunk/tools/llvm-cov/SourceCoverageView.h Wed Sep 27 08:37:40 2017
@@ -22,6 +22,7 @@
 
 namespace llvm {
 
+class CoverageFilter;
 class SourceCoverageView;
 
 /// \brief A view that represents a macro or include expansion.
@@ -111,7 +112,8 @@ public:
 
   /// \brief Create an index which lists reports for the given source files.
   virtual Error createIndexFile(ArrayRef<std::string> SourceFiles,
-                                const coverage::CoverageMapping &Coverage) = 0;
+                                const coverage::CoverageMapping &Coverage,
+                                const CoverageFilter &Filters) = 0;
 
   /// @}
 };
@@ -258,7 +260,7 @@ public:
   /// \brief Print the code coverage information for a specific portion of a
   /// source file to the output stream.
   void print(raw_ostream &OS, bool WholeFile, bool ShowSourceName,
-             unsigned ViewDepth = 0);
+             bool ShowTitle, unsigned ViewDepth = 0);
 };
 
 } // namespace llvm

Modified: llvm/trunk/tools/llvm-cov/SourceCoverageViewHTML.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/SourceCoverageViewHTML.cpp?rev=314310&r1=314309&r2=314310&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/SourceCoverageViewHTML.cpp (original)
+++ llvm/trunk/tools/llvm-cov/SourceCoverageViewHTML.cpp Wed Sep 27 08:37:40 2017
@@ -366,7 +366,7 @@ void CoveragePrinterHTML::emitFileSummar
 
 Error CoveragePrinterHTML::createIndexFile(
     ArrayRef<std::string> SourceFiles,
-    const coverage::CoverageMapping &Coverage) {
+    const coverage::CoverageMapping &Coverage, const CoverageFilter &Filters) {
   // Emit the default stylesheet.
   auto CSSOrErr = createOutputStream("style", "css", /*InToplevel=*/true);
   if (Error E = CSSOrErr.takeError())
@@ -404,8 +404,8 @@ Error CoveragePrinterHTML::createIndexFi
   OSRef << BeginCenteredDiv << BeginTable;
   emitColumnLabelsForIndex(OSRef, Opts);
   FileCoverageSummary Totals("TOTALS");
-  auto FileReports =
-      CoverageReport::prepareFileReports(Coverage, Totals, SourceFiles, Opts);
+  auto FileReports = CoverageReport::prepareFileReports(
+      Coverage, Totals, SourceFiles, Opts, Filters);
   bool EmptyFiles = false;
   for (unsigned I = 0, E = FileReports.size(); I < E; ++I) {
     if (FileReports[I].FunctionCoverage.getNumFunctions())
@@ -620,7 +620,7 @@ void SourceCoverageViewHTML::renderExpan
                                                  unsigned ViewDepth) {
   OS << BeginExpansionDiv;
   ESV.View->print(OS, /*WholeFile=*/false, /*ShowSourceName=*/false,
-                  ViewDepth + 1);
+                  /*ShowTitle=*/false, ViewDepth + 1);
   OS << EndExpansionDiv;
 }
 
@@ -636,7 +636,7 @@ void SourceCoverageViewHTML::renderInsta
        << EndSourceNameDiv;
   else
     ISV.View->print(OS, /*WholeFile=*/false, /*ShowSourceName=*/true,
-                    ViewDepth);
+                    /*ShowTitle=*/false, ViewDepth);
   OS << EndExpansionDiv;
 }
 

Modified: llvm/trunk/tools/llvm-cov/SourceCoverageViewHTML.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/SourceCoverageViewHTML.h?rev=314310&r1=314309&r2=314310&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/SourceCoverageViewHTML.h (original)
+++ llvm/trunk/tools/llvm-cov/SourceCoverageViewHTML.h Wed Sep 27 08:37:40 2017
@@ -29,7 +29,8 @@ public:
   void closeViewFile(OwnedStream OS) override;
 
   Error createIndexFile(ArrayRef<std::string> SourceFiles,
-                        const coverage::CoverageMapping &Coverage) override;
+                        const coverage::CoverageMapping &Coverage,
+                        const CoverageFilter &Filters) override;
 
   CoveragePrinterHTML(const CoverageViewOptions &Opts)
       : CoveragePrinter(Opts) {}

Modified: llvm/trunk/tools/llvm-cov/SourceCoverageViewText.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/SourceCoverageViewText.cpp?rev=314310&r1=314309&r2=314310&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/SourceCoverageViewText.cpp (original)
+++ llvm/trunk/tools/llvm-cov/SourceCoverageViewText.cpp Wed Sep 27 08:37:40 2017
@@ -30,7 +30,7 @@ void CoveragePrinterText::closeViewFile(
 
 Error CoveragePrinterText::createIndexFile(
     ArrayRef<std::string> SourceFiles,
-    const coverage::CoverageMapping &Coverage) {
+    const coverage::CoverageMapping &Coverage, const CoverageFilter &Filters) {
   auto OSOrErr = createOutputStream("index", "txt", /*InToplevel=*/true);
   if (Error E = OSOrErr.takeError())
     return E;
@@ -38,7 +38,7 @@ Error CoveragePrinterText::createIndexFi
   raw_ostream &OSRef = *OS.get();
 
   CoverageReport Report(Opts, Coverage);
-  Report.renderFileReports(OSRef, SourceFiles);
+  Report.renderFileReports(OSRef, SourceFiles, Filters);
 
   Opts.colored_ostream(OSRef, raw_ostream::CYAN) << "\n"
                                                  << Opts.getLLVMVersionString();
@@ -210,7 +210,7 @@ void SourceCoverageViewText::renderExpan
     errs() << "Expansion at line " << ESV.getLine() << ", " << ESV.getStartCol()
            << " -> " << ESV.getEndCol() << '\n';
   ESV.View->print(OS, /*WholeFile=*/false, /*ShowSourceName=*/false,
-                  ViewDepth + 1);
+                  /*ShowTitle=*/false, ViewDepth + 1);
 }
 
 void SourceCoverageViewText::renderInstantiationView(raw_ostream &OS,
@@ -223,7 +223,7 @@ void SourceCoverageViewText::renderInsta
         << "Unexecuted instantiation: " << ISV.FunctionName << "\n";
   else
     ISV.View->print(OS, /*WholeFile=*/false, /*ShowSourceName=*/true,
-                    ViewDepth);
+                    /*ShowTitle=*/false, ViewDepth);
 }
 
 void SourceCoverageViewText::renderTitle(raw_ostream &OS, StringRef Title) {

Modified: llvm/trunk/tools/llvm-cov/SourceCoverageViewText.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/SourceCoverageViewText.h?rev=314310&r1=314309&r2=314310&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/SourceCoverageViewText.h (original)
+++ llvm/trunk/tools/llvm-cov/SourceCoverageViewText.h Wed Sep 27 08:37:40 2017
@@ -27,7 +27,8 @@ public:
   void closeViewFile(OwnedStream OS) override;
 
   Error createIndexFile(ArrayRef<std::string> SourceFiles,
-                        const coverage::CoverageMapping &Coverage) override;
+                        const coverage::CoverageMapping &Coverage,
+                        const CoverageFilter &Filters) override;
 
   CoveragePrinterText(const CoverageViewOptions &Opts)
       : CoveragePrinter(Opts) {}




More information about the llvm-commits mailing list