diff options
author | Sean Eveson <eveson.sean@gmail.com> | 2017-09-28 10:07:30 +0000 |
---|---|---|
committer | Sean Eveson <eveson.sean@gmail.com> | 2017-09-28 10:07:30 +0000 |
commit | fa8ef35e786b59d2916a7358c30c1489a7d79b19 (patch) | |
tree | 36c1109197a1708c03e6e76b48428228c468e223 /llvm/tools | |
parent | 89d2be0702e1e57bfe514b050bdbd743c3e8731f (diff) | |
download | llvm-fa8ef35e786b59d2916a7358c30c1489a7d79b19.zip llvm-fa8ef35e786b59d2916a7358c30c1489a7d79b19.tar.gz llvm-fa8ef35e786b59d2916a7358c30c1489a7d79b19.tar.bz2 |
[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
llvm-svn: 314396
Diffstat (limited to 'llvm/tools')
-rw-r--r-- | llvm/tools/llvm-cov/CodeCoverage.cpp | 77 | ||||
-rw-r--r-- | llvm/tools/llvm-cov/CoverageReport.cpp | 15 | ||||
-rw-r--r-- | llvm/tools/llvm-cov/CoverageReport.h | 10 | ||||
-rw-r--r-- | llvm/tools/llvm-cov/SourceCoverageView.cpp | 5 | ||||
-rw-r--r-- | llvm/tools/llvm-cov/SourceCoverageView.h | 6 | ||||
-rw-r--r-- | llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp | 10 | ||||
-rw-r--r-- | llvm/tools/llvm-cov/SourceCoverageViewHTML.h | 3 | ||||
-rw-r--r-- | llvm/tools/llvm-cov/SourceCoverageViewText.cpp | 8 | ||||
-rw-r--r-- | llvm/tools/llvm-cov/SourceCoverageViewText.h | 3 |
9 files changed, 84 insertions, 53 deletions
diff --git a/llvm/tools/llvm-cov/CodeCoverage.cpp b/llvm/tools/llvm-cov/CodeCoverage.cpp index 1ea54a8..1b9f232 100644 --- a/llvm/tools/llvm-cov/CodeCoverage.cpp +++ b/llvm/tools/llvm-cov/CodeCoverage.cpp @@ -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::writeSourceFileView(StringRef SourceFile, 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, const char **argv, 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) { + 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()); + + 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; } - mainView->print(*OS.get(), /*WholeFile=*/false, /*ShowSourceName=*/true); + Printer->closeViewFile(std::move(OS)); } - - Printer->closeViewFile(std::move(OS)); return 0; } @@ -876,19 +904,6 @@ int CodeCoverageTool::show(int argc, const char **argv, (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 = diff --git a/llvm/tools/llvm-cov/CoverageReport.cpp b/llvm/tools/llvm-cov/CoverageReport.cpp index 4c02bbc..5c8ffe1 100644 --- a/llvm/tools/llvm-cov/CoverageReport.cpp +++ b/llvm/tools/llvm-cov/CoverageReport.cpp @@ -322,7 +322,8 @@ void CoverageReport::renderFunctionReports(ArrayRef<std::string> Files, 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> CoverageReport::prepareFileReports( 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(raw_ostream &OS) const { 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) diff --git a/llvm/tools/llvm-cov/CoverageReport.h b/llvm/tools/llvm-cov/CoverageReport.h index 242dc7f..d78f2e4 100644 --- a/llvm/tools/llvm-cov/CoverageReport.h +++ b/llvm/tools/llvm-cov/CoverageReport.h @@ -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 diff --git a/llvm/tools/llvm-cov/SourceCoverageView.cpp b/llvm/tools/llvm-cov/SourceCoverageView.cpp index dc00b80..f944dc6 100644 --- a/llvm/tools/llvm-cov/SourceCoverageView.cpp +++ b/llvm/tools/llvm-cov/SourceCoverageView.cpp @@ -164,8 +164,9 @@ void SourceCoverageView::addInstantiation( } 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); diff --git a/llvm/tools/llvm-cov/SourceCoverageView.h b/llvm/tools/llvm-cov/SourceCoverageView.h index 72d6866..7c7e878 100644 --- a/llvm/tools/llvm-cov/SourceCoverageView.h +++ b/llvm/tools/llvm-cov/SourceCoverageView.h @@ -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 diff --git a/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp b/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp index 300a016..a031f18 100644 --- a/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp +++ b/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp @@ -366,7 +366,7 @@ void CoveragePrinterHTML::emitFileSummary(raw_ostream &OS, StringRef SF, 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::createIndexFile( 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::renderExpansionView(raw_ostream &OS, 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::renderInstantiationView(raw_ostream &OS, << EndSourceNameDiv; else ISV.View->print(OS, /*WholeFile=*/false, /*ShowSourceName=*/true, - ViewDepth); + /*ShowTitle=*/false, ViewDepth); OS << EndExpansionDiv; } diff --git a/llvm/tools/llvm-cov/SourceCoverageViewHTML.h b/llvm/tools/llvm-cov/SourceCoverageViewHTML.h index 8cb7356..e11111a 100644 --- a/llvm/tools/llvm-cov/SourceCoverageViewHTML.h +++ b/llvm/tools/llvm-cov/SourceCoverageViewHTML.h @@ -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) {} diff --git a/llvm/tools/llvm-cov/SourceCoverageViewText.cpp b/llvm/tools/llvm-cov/SourceCoverageViewText.cpp index a78c057..b2902df1 100644 --- a/llvm/tools/llvm-cov/SourceCoverageViewText.cpp +++ b/llvm/tools/llvm-cov/SourceCoverageViewText.cpp @@ -30,7 +30,7 @@ void CoveragePrinterText::closeViewFile(OwnedStream OS) { 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::createIndexFile( 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::renderExpansionView(raw_ostream &OS, 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::renderInstantiationView(raw_ostream &OS, << "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) { diff --git a/llvm/tools/llvm-cov/SourceCoverageViewText.h b/llvm/tools/llvm-cov/SourceCoverageViewText.h index c3f20de..3a04070 100644 --- a/llvm/tools/llvm-cov/SourceCoverageViewText.h +++ b/llvm/tools/llvm-cov/SourceCoverageViewText.h @@ -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) {} |