2014-08-23 00:56:03 +02:00
|
|
|
//===- CodeCoverage.cpp - Coverage tool based on profiling instrumentation-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// The 'CodeCoverageTool' class implements a command line tool to analyze and
|
|
|
|
// report coverage information using the profiling instrumentation and code
|
|
|
|
// coverage mapping.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "CoverageFilters.h"
|
|
|
|
#include "CoverageReport.h"
|
2015-01-14 12:23:27 +01:00
|
|
|
#include "CoverageViewOptions.h"
|
2016-04-29 20:53:05 +02:00
|
|
|
#include "RenderingSupport.h"
|
2015-01-14 12:23:27 +01:00
|
|
|
#include "SourceCoverageView.h"
|
2014-08-23 00:56:03 +02:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
2015-01-14 12:23:27 +01:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2015-03-11 03:30:51 +01:00
|
|
|
#include "llvm/ADT/Triple.h"
|
2016-04-29 20:53:05 +02:00
|
|
|
#include "llvm/ProfileData/Coverage/CoverageMapping.h"
|
2015-01-14 12:23:27 +01:00
|
|
|
#include "llvm/ProfileData/InstrProfReader.h"
|
2014-08-23 00:56:03 +02:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
|
|
|
#include "llvm/Support/FileSystem.h"
|
|
|
|
#include "llvm/Support/Format.h"
|
2016-07-16 00:44:57 +02:00
|
|
|
#include "llvm/Support/MemoryBuffer.h"
|
2014-08-23 00:56:03 +02:00
|
|
|
#include "llvm/Support/Path.h"
|
2015-03-19 01:02:23 +01:00
|
|
|
#include "llvm/Support/Process.h"
|
2016-07-16 00:44:57 +02:00
|
|
|
#include "llvm/Support/Program.h"
|
2016-07-13 23:38:36 +02:00
|
|
|
#include "llvm/Support/ThreadPool.h"
|
2016-07-16 00:44:57 +02:00
|
|
|
#include "llvm/Support/ToolOutputFile.h"
|
2014-08-23 00:56:03 +02:00
|
|
|
#include <functional>
|
2014-09-09 07:32:18 +02:00
|
|
|
#include <system_error>
|
2014-08-23 00:56:03 +02:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace coverage;
|
|
|
|
|
2016-07-27 00:50:58 +02:00
|
|
|
void exportCoverageDataToJson(StringRef ObjectFilename,
|
|
|
|
const coverage::CoverageMapping &CoverageMapping,
|
|
|
|
raw_ostream &OS);
|
|
|
|
|
2014-08-23 00:56:03 +02:00
|
|
|
namespace {
|
|
|
|
/// \brief The implementation of the coverage tool.
|
|
|
|
class CodeCoverageTool {
|
|
|
|
public:
|
|
|
|
enum Command {
|
|
|
|
/// \brief The show command.
|
|
|
|
Show,
|
|
|
|
/// \brief The report command.
|
2016-07-27 00:50:58 +02:00
|
|
|
Report,
|
|
|
|
/// \brief The export command.
|
|
|
|
Export
|
2014-08-23 00:56:03 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/// \brief Print the error message to the error output stream.
|
|
|
|
void error(const Twine &Message, StringRef Whence = "");
|
|
|
|
|
2016-07-18 19:53:12 +02:00
|
|
|
/// \brief Print the warning message to the error output stream.
|
|
|
|
void warning(const Twine &Message, StringRef Whence = "");
|
2016-07-13 23:38:36 +02:00
|
|
|
|
2016-07-18 20:02:54 +02:00
|
|
|
/// \brief Copy \p Path into the list of input source files.
|
2016-06-28 18:12:18 +02:00
|
|
|
void addCollectedPath(const std::string &Path);
|
|
|
|
|
2014-08-23 00:56:03 +02:00
|
|
|
/// \brief Return a memory buffer for the given source file.
|
|
|
|
ErrorOr<const MemoryBuffer &> getSourceFile(StringRef SourceFile);
|
|
|
|
|
2014-09-20 17:31:56 +02:00
|
|
|
/// \brief Create source views for the expansions of the view.
|
|
|
|
void attachExpansionSubViews(SourceCoverageView &View,
|
|
|
|
ArrayRef<ExpansionRecord> Expansions,
|
2016-07-15 03:19:33 +02:00
|
|
|
const CoverageMapping &Coverage);
|
2014-08-23 00:56:03 +02:00
|
|
|
|
2014-09-20 17:31:56 +02:00
|
|
|
/// \brief Create the source view of a particular function.
|
2014-09-19 21:07:17 +02:00
|
|
|
std::unique_ptr<SourceCoverageView>
|
2016-07-15 03:19:33 +02:00
|
|
|
createFunctionView(const FunctionRecord &Function,
|
|
|
|
const CoverageMapping &Coverage);
|
2014-08-23 00:56:03 +02:00
|
|
|
|
|
|
|
/// \brief Create the main source view of a particular source file.
|
2014-09-19 21:07:17 +02:00
|
|
|
std::unique_ptr<SourceCoverageView>
|
2016-07-15 03:19:33 +02:00
|
|
|
createSourceFileView(StringRef SourceFile, const CoverageMapping &Coverage);
|
2014-08-23 00:56:03 +02:00
|
|
|
|
2016-07-15 03:19:33 +02:00
|
|
|
/// \brief Load the coverage mapping data. Return nullptr if an error occured.
|
2014-09-20 17:31:56 +02:00
|
|
|
std::unique_ptr<CoverageMapping> load();
|
2014-08-23 00:56:03 +02:00
|
|
|
|
2016-07-16 00:44:57 +02:00
|
|
|
/// \brief If a demangler is available, demangle all symbol names.
|
|
|
|
void demangleSymbols(const CoverageMapping &Coverage);
|
|
|
|
|
|
|
|
/// \brief Demangle \p Sym if possible. Otherwise, just return \p Sym.
|
|
|
|
StringRef getSymbolForHumans(StringRef Sym) const;
|
|
|
|
|
2014-08-23 00:56:03 +02:00
|
|
|
int run(Command Cmd, int argc, const char **argv);
|
|
|
|
|
2016-06-08 21:09:22 +02:00
|
|
|
typedef llvm::function_ref<int(int, const char **)> CommandLineParserType;
|
2014-08-23 00:56:03 +02:00
|
|
|
|
|
|
|
int show(int argc, const char **argv,
|
|
|
|
CommandLineParserType commandLineParser);
|
|
|
|
|
|
|
|
int report(int argc, const char **argv,
|
|
|
|
CommandLineParserType commandLineParser);
|
|
|
|
|
2016-07-27 00:50:58 +02:00
|
|
|
int export_(int argc, const char **argv,
|
|
|
|
CommandLineParserType commandLineParser);
|
|
|
|
|
2014-10-30 21:51:24 +01:00
|
|
|
std::string ObjectFilename;
|
2014-08-23 00:56:03 +02:00
|
|
|
CoverageViewOptions ViewOpts;
|
2014-09-20 17:31:56 +02:00
|
|
|
std::string PGOFilename;
|
2014-08-23 00:56:03 +02:00
|
|
|
CoverageFiltersMatchAll Filters;
|
2016-06-28 18:12:18 +02:00
|
|
|
std::vector<StringRef> SourceFiles;
|
2014-08-23 00:56:03 +02:00
|
|
|
bool CompareFilenamesOnly;
|
2014-09-19 10:13:12 +02:00
|
|
|
StringMap<std::string> RemappedFilenames;
|
2015-06-22 23:33:24 +02:00
|
|
|
std::string CoverageArch;
|
2016-06-28 18:12:18 +02:00
|
|
|
|
|
|
|
private:
|
2016-07-16 00:44:57 +02:00
|
|
|
/// A cache for demangled symbol names.
|
|
|
|
StringMap<std::string> DemangledNames;
|
|
|
|
|
2016-07-16 00:44:54 +02:00
|
|
|
/// File paths (absolute, or otherwise) to input source files.
|
2016-06-28 18:12:18 +02:00
|
|
|
std::vector<std::string> CollectedPaths;
|
2016-07-13 23:38:36 +02:00
|
|
|
|
2016-07-16 00:44:54 +02:00
|
|
|
/// Errors and warnings which have not been printed.
|
2016-07-18 19:53:12 +02:00
|
|
|
std::mutex ErrsLock;
|
2016-07-13 23:38:36 +02:00
|
|
|
|
2016-07-16 00:44:54 +02:00
|
|
|
/// A container for input source file buffers.
|
2016-07-13 23:38:36 +02:00
|
|
|
std::mutex LoadedSourceFilesLock;
|
|
|
|
std::vector<std::pair<std::string, std::unique_ptr<MemoryBuffer>>>
|
|
|
|
LoadedSourceFiles;
|
2014-08-23 00:56:03 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-07-13 23:38:36 +02:00
|
|
|
static std::string getErrorString(const Twine &Message, StringRef Whence,
|
|
|
|
bool Warning) {
|
|
|
|
std::string Str = (Warning ? "warning" : "error");
|
|
|
|
Str += ": ";
|
2014-08-23 00:56:03 +02:00
|
|
|
if (!Whence.empty())
|
2016-07-15 03:53:39 +02:00
|
|
|
Str += Whence.str() + ": ";
|
2016-07-13 23:38:36 +02:00
|
|
|
Str += Message.str() + "\n";
|
|
|
|
return Str;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CodeCoverageTool::error(const Twine &Message, StringRef Whence) {
|
2016-07-18 19:53:12 +02:00
|
|
|
std::unique_lock<std::mutex> Guard{ErrsLock};
|
|
|
|
ViewOpts.colored_ostream(errs(), raw_ostream::RED)
|
|
|
|
<< getErrorString(Message, Whence, false);
|
2016-07-13 23:38:36 +02:00
|
|
|
}
|
|
|
|
|
2016-07-18 19:53:12 +02:00
|
|
|
void CodeCoverageTool::warning(const Twine &Message, StringRef Whence) {
|
|
|
|
std::unique_lock<std::mutex> Guard{ErrsLock};
|
|
|
|
ViewOpts.colored_ostream(errs(), raw_ostream::RED)
|
|
|
|
<< getErrorString(Message, Whence, true);
|
2014-08-23 00:56:03 +02:00
|
|
|
}
|
|
|
|
|
2016-06-28 18:12:18 +02:00
|
|
|
void CodeCoverageTool::addCollectedPath(const std::string &Path) {
|
|
|
|
CollectedPaths.push_back(Path);
|
|
|
|
SourceFiles.emplace_back(CollectedPaths.back());
|
|
|
|
}
|
|
|
|
|
2014-08-23 00:56:03 +02:00
|
|
|
ErrorOr<const MemoryBuffer &>
|
|
|
|
CodeCoverageTool::getSourceFile(StringRef SourceFile) {
|
2014-09-19 10:13:12 +02:00
|
|
|
// If we've remapped filenames, look up the real location for this file.
|
2016-07-15 03:19:36 +02:00
|
|
|
std::unique_lock<std::mutex> Guard{LoadedSourceFilesLock};
|
2014-09-19 10:13:12 +02:00
|
|
|
if (!RemappedFilenames.empty()) {
|
|
|
|
auto Loc = RemappedFilenames.find(SourceFile);
|
|
|
|
if (Loc != RemappedFilenames.end())
|
|
|
|
SourceFile = Loc->second;
|
2014-08-23 00:56:03 +02:00
|
|
|
}
|
2014-09-19 10:13:12 +02:00
|
|
|
for (const auto &Files : LoadedSourceFiles)
|
|
|
|
if (sys::fs::equivalent(SourceFile, Files.first))
|
|
|
|
return *Files.second;
|
2014-08-23 00:56:03 +02:00
|
|
|
auto Buffer = MemoryBuffer::getFile(SourceFile);
|
|
|
|
if (auto EC = Buffer.getError()) {
|
2016-07-18 19:53:12 +02:00
|
|
|
error(EC.message(), SourceFile);
|
2014-08-23 00:56:03 +02:00
|
|
|
return EC;
|
|
|
|
}
|
2015-05-29 21:43:39 +02:00
|
|
|
LoadedSourceFiles.emplace_back(SourceFile, std::move(Buffer.get()));
|
2014-08-23 00:56:03 +02:00
|
|
|
return *LoadedSourceFiles.back().second;
|
|
|
|
}
|
|
|
|
|
2016-07-15 03:19:33 +02:00
|
|
|
void CodeCoverageTool::attachExpansionSubViews(
|
|
|
|
SourceCoverageView &View, ArrayRef<ExpansionRecord> Expansions,
|
|
|
|
const CoverageMapping &Coverage) {
|
2014-08-23 00:56:03 +02:00
|
|
|
if (!ViewOpts.ShowExpandedRegions)
|
|
|
|
return;
|
2014-09-20 17:31:56 +02:00
|
|
|
for (const auto &Expansion : Expansions) {
|
|
|
|
auto ExpansionCoverage = Coverage.getCoverageForExpansion(Expansion);
|
|
|
|
if (ExpansionCoverage.empty())
|
2014-08-23 00:56:03 +02:00
|
|
|
continue;
|
2014-09-20 17:31:56 +02:00
|
|
|
auto SourceBuffer = getSourceFile(ExpansionCoverage.getFilename());
|
|
|
|
if (!SourceBuffer)
|
2014-08-23 00:56:03 +02:00
|
|
|
continue;
|
2014-09-20 17:31:56 +02:00
|
|
|
|
|
|
|
auto SubViewExpansions = ExpansionCoverage.getExpansions();
|
2016-06-25 04:58:30 +02:00
|
|
|
auto SubView =
|
|
|
|
SourceCoverageView::create(Expansion.Function.Name, SourceBuffer.get(),
|
|
|
|
ViewOpts, std::move(ExpansionCoverage));
|
2014-09-20 17:31:56 +02:00
|
|
|
attachExpansionSubViews(*SubView, SubViewExpansions, Coverage);
|
|
|
|
View.addExpansion(Expansion.Region, std::move(SubView));
|
2014-08-23 00:56:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-19 21:07:17 +02:00
|
|
|
std::unique_ptr<SourceCoverageView>
|
2014-09-20 17:31:56 +02:00
|
|
|
CodeCoverageTool::createFunctionView(const FunctionRecord &Function,
|
2016-07-15 03:19:33 +02:00
|
|
|
const CoverageMapping &Coverage) {
|
2014-09-20 17:31:56 +02:00
|
|
|
auto FunctionCoverage = Coverage.getCoverageForFunction(Function);
|
|
|
|
if (FunctionCoverage.empty())
|
2014-09-19 21:07:17 +02:00
|
|
|
return nullptr;
|
2014-09-20 17:31:56 +02:00
|
|
|
auto SourceBuffer = getSourceFile(FunctionCoverage.getFilename());
|
2014-09-19 21:07:17 +02:00
|
|
|
if (!SourceBuffer)
|
|
|
|
return nullptr;
|
2014-08-23 00:56:03 +02:00
|
|
|
|
2014-09-20 17:31:56 +02:00
|
|
|
auto Expansions = FunctionCoverage.getExpansions();
|
2016-09-08 02:56:48 +02:00
|
|
|
auto View = SourceCoverageView::create(getSymbolForHumans(Function.Name),
|
|
|
|
SourceBuffer.get(), ViewOpts,
|
|
|
|
std::move(FunctionCoverage));
|
2014-09-20 17:31:56 +02:00
|
|
|
attachExpansionSubViews(*View, Expansions, Coverage);
|
|
|
|
|
|
|
|
return View;
|
|
|
|
}
|
2014-08-23 00:56:03 +02:00
|
|
|
|
2014-09-20 17:31:56 +02:00
|
|
|
std::unique_ptr<SourceCoverageView>
|
|
|
|
CodeCoverageTool::createSourceFileView(StringRef SourceFile,
|
2016-07-15 03:19:33 +02:00
|
|
|
const CoverageMapping &Coverage) {
|
2014-09-19 21:07:17 +02:00
|
|
|
auto SourceBuffer = getSourceFile(SourceFile);
|
|
|
|
if (!SourceBuffer)
|
|
|
|
return nullptr;
|
2014-09-20 17:31:56 +02:00
|
|
|
auto FileCoverage = Coverage.getCoverageForFile(SourceFile);
|
|
|
|
if (FileCoverage.empty())
|
2014-09-19 21:07:17 +02:00
|
|
|
return nullptr;
|
2014-09-20 17:31:56 +02:00
|
|
|
|
|
|
|
auto Expansions = FileCoverage.getExpansions();
|
2016-06-25 04:58:30 +02:00
|
|
|
auto View = SourceCoverageView::create(SourceFile, SourceBuffer.get(),
|
|
|
|
ViewOpts, std::move(FileCoverage));
|
2014-09-20 17:31:56 +02:00
|
|
|
attachExpansionSubViews(*View, Expansions, Coverage);
|
|
|
|
|
2016-07-15 03:19:33 +02:00
|
|
|
for (const auto *Function : Coverage.getInstantiations(SourceFile)) {
|
2016-09-15 08:44:51 +02:00
|
|
|
std::unique_ptr<SourceCoverageView> SubView{nullptr};
|
|
|
|
|
2016-09-20 23:27:48 +02:00
|
|
|
StringRef Funcname = getSymbolForHumans(Function->Name);
|
|
|
|
|
2016-09-15 08:44:51 +02:00
|
|
|
if (Function->ExecutionCount > 0) {
|
|
|
|
auto SubViewCoverage = Coverage.getCoverageForFunction(*Function);
|
|
|
|
auto SubViewExpansions = SubViewCoverage.getExpansions();
|
|
|
|
SubView = SourceCoverageView::create(
|
2016-09-20 23:27:48 +02:00
|
|
|
Funcname, SourceBuffer.get(), ViewOpts, std::move(SubViewCoverage));
|
2016-09-15 08:44:51 +02:00
|
|
|
attachExpansionSubViews(*SubView, SubViewExpansions, Coverage);
|
2014-08-23 00:56:03 +02:00
|
|
|
}
|
2016-09-15 08:44:51 +02:00
|
|
|
|
|
|
|
unsigned FileID = Function->CountedRegions.front().FileID;
|
|
|
|
unsigned Line = 0;
|
|
|
|
for (const auto &CR : Function->CountedRegions)
|
|
|
|
if (CR.FileID == FileID)
|
|
|
|
Line = std::max(CR.LineEnd, Line);
|
2016-09-20 23:27:48 +02:00
|
|
|
View->addInstantiation(Funcname, Line, std::move(SubView));
|
2014-08-23 00:56:03 +02:00
|
|
|
}
|
2014-09-19 21:07:17 +02:00
|
|
|
return View;
|
2014-08-23 00:56:03 +02:00
|
|
|
}
|
|
|
|
|
2015-05-04 06:09:38 +02:00
|
|
|
static bool modifiedTimeGT(StringRef LHS, StringRef RHS) {
|
|
|
|
sys::fs::file_status Status;
|
|
|
|
if (sys::fs::status(LHS, Status))
|
|
|
|
return false;
|
|
|
|
auto LHSTime = Status.getLastModificationTime();
|
|
|
|
if (sys::fs::status(RHS, Status))
|
|
|
|
return false;
|
|
|
|
auto RHSTime = Status.getLastModificationTime();
|
|
|
|
return LHSTime > RHSTime;
|
|
|
|
}
|
|
|
|
|
2014-09-20 17:31:56 +02:00
|
|
|
std::unique_ptr<CoverageMapping> CodeCoverageTool::load() {
|
2015-05-04 06:09:38 +02:00
|
|
|
if (modifiedTimeGT(ObjectFilename, PGOFilename))
|
2016-07-18 19:53:12 +02:00
|
|
|
warning("profile data may be out of date - object is newer",
|
|
|
|
ObjectFilename);
|
|
|
|
auto CoverageOrErr =
|
|
|
|
CoverageMapping::load(ObjectFilename, PGOFilename, CoverageArch);
|
2016-05-19 05:54:45 +02:00
|
|
|
if (Error E = CoverageOrErr.takeError()) {
|
2016-07-18 19:53:12 +02:00
|
|
|
error("Failed to load coverage: " + toString(std::move(E)), ObjectFilename);
|
2014-09-20 17:31:56 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
auto Coverage = std::move(CoverageOrErr.get());
|
|
|
|
unsigned Mismatched = Coverage->getMismatchedCount();
|
2016-07-18 19:53:12 +02:00
|
|
|
if (Mismatched)
|
|
|
|
warning(utostr(Mismatched) + " functions have mismatched data");
|
2014-09-19 10:13:12 +02:00
|
|
|
|
|
|
|
if (CompareFilenamesOnly) {
|
2014-09-20 17:31:56 +02:00
|
|
|
auto CoveredFiles = Coverage.get()->getUniqueSourceFiles();
|
2014-09-19 10:13:12 +02:00
|
|
|
for (auto &SF : SourceFiles) {
|
|
|
|
StringRef SFBase = sys::path::filename(SF);
|
|
|
|
for (const auto &CF : CoveredFiles)
|
|
|
|
if (SFBase == sys::path::filename(CF)) {
|
|
|
|
RemappedFilenames[CF] = SF;
|
|
|
|
SF = CF;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-16 00:44:57 +02:00
|
|
|
demangleSymbols(*Coverage);
|
|
|
|
|
2014-09-20 17:31:56 +02:00
|
|
|
return Coverage;
|
2014-08-23 00:56:03 +02:00
|
|
|
}
|
|
|
|
|
2016-07-16 00:44:57 +02:00
|
|
|
void CodeCoverageTool::demangleSymbols(const CoverageMapping &Coverage) {
|
|
|
|
if (!ViewOpts.hasDemangler())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Pass function names to the demangler in a temporary file.
|
|
|
|
int InputFD;
|
|
|
|
SmallString<256> InputPath;
|
|
|
|
std::error_code EC =
|
|
|
|
sys::fs::createTemporaryFile("demangle-in", "list", InputFD, InputPath);
|
|
|
|
if (EC) {
|
|
|
|
error(InputPath, EC.message());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
tool_output_file InputTOF{InputPath, InputFD};
|
|
|
|
|
|
|
|
unsigned NumSymbols = 0;
|
|
|
|
for (const auto &Function : Coverage.getCoveredFunctions()) {
|
|
|
|
InputTOF.os() << Function.Name << '\n';
|
|
|
|
++NumSymbols;
|
|
|
|
}
|
2016-07-16 01:08:22 +02:00
|
|
|
InputTOF.os().close();
|
2016-07-16 00:44:57 +02:00
|
|
|
|
|
|
|
// Use another temporary file to store the demangler's output.
|
|
|
|
int OutputFD;
|
|
|
|
SmallString<256> OutputPath;
|
|
|
|
EC = sys::fs::createTemporaryFile("demangle-out", "list", OutputFD,
|
|
|
|
OutputPath);
|
|
|
|
if (EC) {
|
|
|
|
error(OutputPath, EC.message());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
tool_output_file OutputTOF{OutputPath, OutputFD};
|
2016-07-16 01:08:22 +02:00
|
|
|
OutputTOF.os().close();
|
2016-07-16 00:44:57 +02:00
|
|
|
|
|
|
|
// Invoke the demangler.
|
|
|
|
std::vector<const char *> ArgsV;
|
|
|
|
for (const std::string &Arg : ViewOpts.DemanglerOpts)
|
|
|
|
ArgsV.push_back(Arg.c_str());
|
|
|
|
ArgsV.push_back(nullptr);
|
2016-07-16 01:15:35 +02:00
|
|
|
StringRef InputPathRef = InputPath.str();
|
|
|
|
StringRef OutputPathRef = OutputPath.str();
|
|
|
|
StringRef StderrRef;
|
2016-07-16 00:44:57 +02:00
|
|
|
const StringRef *Redirects[] = {&InputPathRef, &OutputPathRef, &StderrRef};
|
|
|
|
std::string ErrMsg;
|
|
|
|
int RC = sys::ExecuteAndWait(ViewOpts.DemanglerOpts[0], ArgsV.data(),
|
|
|
|
/*env=*/nullptr, Redirects, /*secondsToWait=*/0,
|
|
|
|
/*memoryLimit=*/0, &ErrMsg);
|
|
|
|
if (RC) {
|
|
|
|
error(ErrMsg, ViewOpts.DemanglerOpts[0]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse the demangler's output.
|
|
|
|
auto BufOrError = MemoryBuffer::getFile(OutputPath);
|
|
|
|
if (!BufOrError) {
|
|
|
|
error(OutputPath, BufOrError.getError().message());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<MemoryBuffer> DemanglerBuf = std::move(*BufOrError);
|
|
|
|
|
|
|
|
SmallVector<StringRef, 8> Symbols;
|
|
|
|
StringRef DemanglerData = DemanglerBuf->getBuffer();
|
|
|
|
DemanglerData.split(Symbols, '\n', /*MaxSplit=*/NumSymbols,
|
|
|
|
/*KeepEmpty=*/false);
|
|
|
|
if (Symbols.size() != NumSymbols) {
|
|
|
|
error("Demangler did not provide expected number of symbols");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cache the demangled names.
|
|
|
|
unsigned I = 0;
|
|
|
|
for (const auto &Function : Coverage.getCoveredFunctions())
|
|
|
|
DemangledNames[Function.Name] = Symbols[I++];
|
|
|
|
}
|
|
|
|
|
|
|
|
StringRef CodeCoverageTool::getSymbolForHumans(StringRef Sym) const {
|
|
|
|
const auto DemangledName = DemangledNames.find(Sym);
|
|
|
|
if (DemangledName == DemangledNames.end())
|
|
|
|
return Sym;
|
|
|
|
return DemangledName->getValue();
|
|
|
|
}
|
|
|
|
|
2014-08-23 00:56:03 +02:00
|
|
|
int CodeCoverageTool::run(Command Cmd, int argc, const char **argv) {
|
2014-10-30 21:51:24 +01:00
|
|
|
cl::opt<std::string, true> ObjectFilename(
|
|
|
|
cl::Positional, cl::Required, cl::location(this->ObjectFilename),
|
|
|
|
cl::desc("Covered executable or object file."));
|
|
|
|
|
2014-08-23 00:56:03 +02:00
|
|
|
cl::list<std::string> InputSourceFiles(
|
|
|
|
cl::Positional, cl::desc("<Source files>"), cl::ZeroOrMore);
|
|
|
|
|
2014-09-20 17:31:56 +02:00
|
|
|
cl::opt<std::string, true> PGOFilename(
|
|
|
|
"instr-profile", cl::Required, cl::location(this->PGOFilename),
|
2014-08-23 00:56:03 +02:00
|
|
|
cl::desc(
|
|
|
|
"File with the profile data obtained after an instrumented run"));
|
|
|
|
|
2015-03-11 03:30:51 +01:00
|
|
|
cl::opt<std::string> Arch(
|
|
|
|
"arch", cl::desc("architecture of the coverage mapping binary"));
|
|
|
|
|
2014-08-23 00:56:03 +02:00
|
|
|
cl::opt<bool> DebugDump("dump", cl::Optional,
|
|
|
|
cl::desc("Show internal debug dump"));
|
|
|
|
|
2016-06-29 02:38:21 +02:00
|
|
|
cl::opt<CoverageViewOptions::OutputFormat> Format(
|
|
|
|
"format", cl::desc("Output format for line-based coverage reports"),
|
|
|
|
cl::values(clEnumValN(CoverageViewOptions::OutputFormat::Text, "text",
|
|
|
|
"Text output"),
|
2016-07-06 23:44:05 +02:00
|
|
|
clEnumValN(CoverageViewOptions::OutputFormat::HTML, "html",
|
|
|
|
"HTML output"),
|
2016-06-29 02:38:21 +02:00
|
|
|
clEnumValEnd),
|
|
|
|
cl::init(CoverageViewOptions::OutputFormat::Text));
|
|
|
|
|
2014-08-23 00:56:03 +02:00
|
|
|
cl::opt<bool> FilenameEquivalence(
|
|
|
|
"filename-equivalence", cl::Optional,
|
2014-09-19 10:13:12 +02:00
|
|
|
cl::desc("Treat source files as equivalent to paths in the coverage data "
|
|
|
|
"when the file names match, even if the full paths do not"));
|
2014-08-23 00:56:03 +02:00
|
|
|
|
|
|
|
cl::OptionCategory FilteringCategory("Function filtering options");
|
|
|
|
|
|
|
|
cl::list<std::string> NameFilters(
|
|
|
|
"name", cl::Optional,
|
|
|
|
cl::desc("Show code coverage only for functions with the given name"),
|
|
|
|
cl::ZeroOrMore, cl::cat(FilteringCategory));
|
|
|
|
|
|
|
|
cl::list<std::string> NameRegexFilters(
|
|
|
|
"name-regex", cl::Optional,
|
|
|
|
cl::desc("Show code coverage only for functions that match the given "
|
|
|
|
"regular expression"),
|
|
|
|
cl::ZeroOrMore, cl::cat(FilteringCategory));
|
|
|
|
|
|
|
|
cl::opt<double> RegionCoverageLtFilter(
|
|
|
|
"region-coverage-lt", cl::Optional,
|
|
|
|
cl::desc("Show code coverage only for functions with region coverage "
|
|
|
|
"less than the given threshold"),
|
|
|
|
cl::cat(FilteringCategory));
|
|
|
|
|
|
|
|
cl::opt<double> RegionCoverageGtFilter(
|
|
|
|
"region-coverage-gt", cl::Optional,
|
|
|
|
cl::desc("Show code coverage only for functions with region coverage "
|
|
|
|
"greater than the given threshold"),
|
|
|
|
cl::cat(FilteringCategory));
|
|
|
|
|
|
|
|
cl::opt<double> LineCoverageLtFilter(
|
|
|
|
"line-coverage-lt", cl::Optional,
|
|
|
|
cl::desc("Show code coverage only for functions with line coverage less "
|
|
|
|
"than the given threshold"),
|
|
|
|
cl::cat(FilteringCategory));
|
|
|
|
|
|
|
|
cl::opt<double> LineCoverageGtFilter(
|
|
|
|
"line-coverage-gt", cl::Optional,
|
|
|
|
cl::desc("Show code coverage only for functions with line coverage "
|
|
|
|
"greater than the given threshold"),
|
|
|
|
cl::cat(FilteringCategory));
|
|
|
|
|
2015-03-19 05:45:16 +01:00
|
|
|
cl::opt<cl::boolOrDefault> UseColor(
|
|
|
|
"use-color", cl::desc("Emit colored output (default=autodetect)"),
|
|
|
|
cl::init(cl::BOU_UNSET));
|
2015-03-19 01:02:23 +01:00
|
|
|
|
2016-07-16 00:44:57 +02:00
|
|
|
cl::list<std::string> DemanglerOpts(
|
|
|
|
"Xdemangler", cl::desc("<demangler-path>|<demangler-option>"));
|
|
|
|
|
2014-08-23 00:56:03 +02:00
|
|
|
auto commandLineParser = [&, this](int argc, const char **argv) -> int {
|
|
|
|
cl::ParseCommandLineOptions(argc, argv, "LLVM code coverage tool\n");
|
|
|
|
ViewOpts.Debug = DebugDump;
|
|
|
|
CompareFilenamesOnly = FilenameEquivalence;
|
|
|
|
|
2016-06-29 02:38:21 +02:00
|
|
|
ViewOpts.Format = Format;
|
2016-08-24 16:27:23 +02:00
|
|
|
SmallString<128> ObjectFilePath(this->ObjectFilename);
|
|
|
|
if (std::error_code EC = sys::fs::make_absolute(ObjectFilePath)) {
|
|
|
|
error(EC.message(), this->ObjectFilename);
|
|
|
|
return 1;
|
|
|
|
}
|
2016-08-30 09:01:37 +02:00
|
|
|
sys::path::native(ObjectFilePath);
|
2016-08-24 16:27:23 +02:00
|
|
|
ViewOpts.ObjectFilename = ObjectFilePath.c_str();
|
2016-06-29 02:38:21 +02:00
|
|
|
switch (ViewOpts.Format) {
|
|
|
|
case CoverageViewOptions::OutputFormat::Text:
|
|
|
|
ViewOpts.Colors = UseColor == cl::BOU_UNSET
|
|
|
|
? sys::Process::StandardOutHasColors()
|
|
|
|
: UseColor == cl::BOU_TRUE;
|
|
|
|
break;
|
2016-07-06 23:44:05 +02:00
|
|
|
case CoverageViewOptions::OutputFormat::HTML:
|
|
|
|
if (UseColor == cl::BOU_FALSE)
|
|
|
|
error("Color output cannot be disabled when generating html.");
|
|
|
|
ViewOpts.Colors = true;
|
|
|
|
break;
|
2016-06-29 02:38:21 +02:00
|
|
|
}
|
2015-03-19 01:02:23 +01:00
|
|
|
|
2016-07-16 00:44:57 +02:00
|
|
|
// If a demangler is supplied, check if it exists and register it.
|
|
|
|
if (DemanglerOpts.size()) {
|
|
|
|
auto DemanglerPathOrErr = sys::findProgramByName(DemanglerOpts[0]);
|
|
|
|
if (!DemanglerPathOrErr) {
|
|
|
|
error("Could not find the demangler!",
|
|
|
|
DemanglerPathOrErr.getError().message());
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
DemanglerOpts[0] = *DemanglerPathOrErr;
|
|
|
|
ViewOpts.DemanglerOpts.swap(DemanglerOpts);
|
|
|
|
}
|
|
|
|
|
2014-08-23 00:56:03 +02:00
|
|
|
// Create the function filters
|
|
|
|
if (!NameFilters.empty() || !NameRegexFilters.empty()) {
|
|
|
|
auto NameFilterer = new CoverageFilters;
|
|
|
|
for (const auto &Name : NameFilters)
|
|
|
|
NameFilterer->push_back(llvm::make_unique<NameCoverageFilter>(Name));
|
|
|
|
for (const auto &Regex : NameRegexFilters)
|
|
|
|
NameFilterer->push_back(
|
|
|
|
llvm::make_unique<NameRegexCoverageFilter>(Regex));
|
|
|
|
Filters.push_back(std::unique_ptr<CoverageFilter>(NameFilterer));
|
|
|
|
}
|
|
|
|
if (RegionCoverageLtFilter.getNumOccurrences() ||
|
|
|
|
RegionCoverageGtFilter.getNumOccurrences() ||
|
|
|
|
LineCoverageLtFilter.getNumOccurrences() ||
|
|
|
|
LineCoverageGtFilter.getNumOccurrences()) {
|
|
|
|
auto StatFilterer = new CoverageFilters;
|
|
|
|
if (RegionCoverageLtFilter.getNumOccurrences())
|
|
|
|
StatFilterer->push_back(llvm::make_unique<RegionCoverageFilter>(
|
|
|
|
RegionCoverageFilter::LessThan, RegionCoverageLtFilter));
|
|
|
|
if (RegionCoverageGtFilter.getNumOccurrences())
|
|
|
|
StatFilterer->push_back(llvm::make_unique<RegionCoverageFilter>(
|
|
|
|
RegionCoverageFilter::GreaterThan, RegionCoverageGtFilter));
|
|
|
|
if (LineCoverageLtFilter.getNumOccurrences())
|
|
|
|
StatFilterer->push_back(llvm::make_unique<LineCoverageFilter>(
|
|
|
|
LineCoverageFilter::LessThan, LineCoverageLtFilter));
|
|
|
|
if (LineCoverageGtFilter.getNumOccurrences())
|
|
|
|
StatFilterer->push_back(llvm::make_unique<LineCoverageFilter>(
|
|
|
|
RegionCoverageFilter::GreaterThan, LineCoverageGtFilter));
|
|
|
|
Filters.push_back(std::unique_ptr<CoverageFilter>(StatFilterer));
|
|
|
|
}
|
|
|
|
|
2015-06-22 23:33:24 +02:00
|
|
|
if (!Arch.empty() &&
|
|
|
|
Triple(Arch).getArch() == llvm::Triple::ArchType::UnknownArch) {
|
2016-07-18 19:53:12 +02:00
|
|
|
error("Unknown architecture: " + Arch);
|
2015-06-22 23:33:24 +02:00
|
|
|
return 1;
|
2015-03-11 03:30:51 +01:00
|
|
|
}
|
2015-06-22 23:33:24 +02:00
|
|
|
CoverageArch = Arch;
|
2015-03-11 03:30:51 +01:00
|
|
|
|
2014-09-19 10:13:12 +02:00
|
|
|
for (const auto &File : InputSourceFiles) {
|
|
|
|
SmallString<128> Path(File);
|
2016-07-18 19:53:12 +02:00
|
|
|
if (!CompareFilenamesOnly) {
|
2015-02-14 03:05:05 +01:00
|
|
|
if (std::error_code EC = sys::fs::make_absolute(Path)) {
|
2016-07-18 19:53:12 +02:00
|
|
|
error(EC.message(), File);
|
2015-02-14 03:05:05 +01:00
|
|
|
return 1;
|
|
|
|
}
|
2016-07-18 19:53:12 +02:00
|
|
|
}
|
2016-06-28 18:12:18 +02:00
|
|
|
addCollectedPath(Path.str());
|
2014-09-19 10:13:12 +02:00
|
|
|
}
|
2014-08-23 00:56:03 +02:00
|
|
|
return 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
switch (Cmd) {
|
|
|
|
case Show:
|
|
|
|
return show(argc, argv, commandLineParser);
|
|
|
|
case Report:
|
|
|
|
return report(argc, argv, commandLineParser);
|
2016-07-27 00:50:58 +02:00
|
|
|
case Export:
|
|
|
|
return export_(argc, argv, commandLineParser);
|
2014-08-23 00:56:03 +02:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CodeCoverageTool::show(int argc, const char **argv,
|
|
|
|
CommandLineParserType commandLineParser) {
|
|
|
|
|
|
|
|
cl::OptionCategory ViewCategory("Viewing options");
|
|
|
|
|
|
|
|
cl::opt<bool> ShowLineExecutionCounts(
|
|
|
|
"show-line-counts", cl::Optional,
|
|
|
|
cl::desc("Show the execution counts for each line"), cl::init(true),
|
|
|
|
cl::cat(ViewCategory));
|
|
|
|
|
|
|
|
cl::opt<bool> ShowRegions(
|
|
|
|
"show-regions", cl::Optional,
|
|
|
|
cl::desc("Show the execution counts for each region"),
|
|
|
|
cl::cat(ViewCategory));
|
|
|
|
|
|
|
|
cl::opt<bool> ShowBestLineRegionsCounts(
|
|
|
|
"show-line-counts-or-regions", cl::Optional,
|
|
|
|
cl::desc("Show the execution counts for each line, or the execution "
|
|
|
|
"counts for each region on lines that have multiple regions"),
|
|
|
|
cl::cat(ViewCategory));
|
|
|
|
|
|
|
|
cl::opt<bool> ShowExpansions("show-expansions", cl::Optional,
|
|
|
|
cl::desc("Show expanded source regions"),
|
|
|
|
cl::cat(ViewCategory));
|
|
|
|
|
|
|
|
cl::opt<bool> ShowInstantiations("show-instantiations", cl::Optional,
|
|
|
|
cl::desc("Show function instantiations"),
|
|
|
|
cl::cat(ViewCategory));
|
|
|
|
|
2016-06-28 04:09:39 +02:00
|
|
|
cl::opt<std::string> ShowOutputDirectory(
|
|
|
|
"output-dir", cl::init(""),
|
|
|
|
cl::desc("Directory in which coverage information is written out"));
|
|
|
|
cl::alias ShowOutputDirectoryA("o", cl::desc("Alias for --output-dir"),
|
|
|
|
cl::aliasopt(ShowOutputDirectory));
|
|
|
|
|
2016-08-04 12:39:43 +02:00
|
|
|
cl::opt<uint32_t> TabSize(
|
2016-08-04 20:00:42 +02:00
|
|
|
"tab-size", cl::init(2),
|
|
|
|
cl::desc(
|
|
|
|
"Set tab expansion size for html coverage reports (default = 2)"));
|
2016-08-04 12:39:43 +02:00
|
|
|
|
2016-08-24 16:27:23 +02:00
|
|
|
cl::opt<std::string> ProjectTitle(
|
|
|
|
"project-title", cl::Optional,
|
|
|
|
cl::desc("Set project title for the coverage report"));
|
|
|
|
|
2014-08-23 00:56:03 +02:00
|
|
|
auto Err = commandLineParser(argc, argv);
|
|
|
|
if (Err)
|
|
|
|
return Err;
|
|
|
|
|
|
|
|
ViewOpts.ShowLineNumbers = true;
|
|
|
|
ViewOpts.ShowLineStats = ShowLineExecutionCounts.getNumOccurrences() != 0 ||
|
|
|
|
!ShowRegions || ShowBestLineRegionsCounts;
|
|
|
|
ViewOpts.ShowRegionMarkers = ShowRegions || ShowBestLineRegionsCounts;
|
|
|
|
ViewOpts.ShowLineStatsOrRegionMarkers = ShowBestLineRegionsCounts;
|
|
|
|
ViewOpts.ShowExpandedRegions = ShowExpansions;
|
|
|
|
ViewOpts.ShowFunctionInstantiations = ShowInstantiations;
|
2016-06-28 04:09:39 +02:00
|
|
|
ViewOpts.ShowOutputDirectory = ShowOutputDirectory;
|
2016-08-04 12:39:43 +02:00
|
|
|
ViewOpts.TabSize = TabSize;
|
2016-08-24 16:27:23 +02:00
|
|
|
ViewOpts.ProjectTitle = ProjectTitle;
|
2016-06-28 04:09:39 +02:00
|
|
|
|
2016-06-28 18:12:20 +02:00
|
|
|
if (ViewOpts.hasOutputDirectory()) {
|
2016-06-28 04:09:39 +02:00
|
|
|
if (auto E = sys::fs::create_directories(ViewOpts.ShowOutputDirectory)) {
|
|
|
|
error("Could not create output directory!", E.message());
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2014-08-23 00:56:03 +02:00
|
|
|
|
2016-08-24 16:27:23 +02:00
|
|
|
sys::fs::file_status Status;
|
|
|
|
if (sys::fs::status(PGOFilename, Status)) {
|
|
|
|
error("profdata file error: can not get the file status. \n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto ModifiedTime = Status.getLastModificationTime();
|
|
|
|
std::string ModifiedTimeStr = ModifiedTime.str();
|
|
|
|
size_t found = ModifiedTimeStr.rfind(":");
|
|
|
|
ViewOpts.CreatedTimeStr = (found != std::string::npos)
|
|
|
|
? "Created: " + ModifiedTimeStr.substr(0, found)
|
|
|
|
: "Created: " + ModifiedTimeStr;
|
|
|
|
|
2014-09-20 17:31:56 +02:00
|
|
|
auto Coverage = load();
|
|
|
|
if (!Coverage)
|
2014-08-23 00:56:03 +02:00
|
|
|
return 1;
|
|
|
|
|
2016-06-28 18:12:24 +02:00
|
|
|
auto Printer = CoveragePrinter::create(ViewOpts);
|
|
|
|
|
2014-08-23 00:56:03 +02:00
|
|
|
if (!Filters.empty()) {
|
2016-06-29 02:38:21 +02:00
|
|
|
auto OSOrErr = Printer->createViewFile("functions", /*InToplevel=*/true);
|
|
|
|
if (Error E = OSOrErr.takeError()) {
|
2016-07-15 03:53:39 +02:00
|
|
|
error("Could not create view file!", toString(std::move(E)));
|
2016-06-29 02:38:21 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
auto OS = std::move(OSOrErr.get());
|
|
|
|
|
|
|
|
// Show functions.
|
2014-09-20 17:31:56 +02:00
|
|
|
for (const auto &Function : Coverage->getCoveredFunctions()) {
|
|
|
|
if (!Filters.matches(Function))
|
2014-08-23 00:56:03 +02:00
|
|
|
continue;
|
2014-09-20 17:31:56 +02:00
|
|
|
|
|
|
|
auto mainView = createFunctionView(Function, *Coverage);
|
2014-09-19 21:07:17 +02:00
|
|
|
if (!mainView) {
|
2016-07-18 19:53:12 +02:00
|
|
|
warning("Could not read coverage for '" + Function.Name + "'.");
|
2014-09-19 21:07:17 +02:00
|
|
|
continue;
|
|
|
|
}
|
2016-06-28 04:09:39 +02:00
|
|
|
|
|
|
|
mainView->print(*OS.get(), /*WholeFile=*/false, /*ShowSourceName=*/true);
|
2014-08-23 00:56:03 +02:00
|
|
|
}
|
2016-06-29 02:38:21 +02:00
|
|
|
|
|
|
|
Printer->closeViewFile(std::move(OS));
|
2014-08-23 00:56:03 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Show files
|
2016-08-24 16:27:23 +02:00
|
|
|
bool ShowFilenames =
|
2016-09-06 23:41:38 +02:00
|
|
|
(SourceFiles.size() != 1) || ViewOpts.hasOutputDirectory() ||
|
2016-08-24 16:27:23 +02:00
|
|
|
(ViewOpts.Format == CoverageViewOptions::OutputFormat::HTML);
|
2014-08-23 00:56:03 +02:00
|
|
|
|
2014-09-19 10:13:12 +02:00
|
|
|
if (SourceFiles.empty())
|
2016-06-28 18:12:20 +02:00
|
|
|
// Get the source files from the function coverage mapping.
|
2014-09-20 17:31:56 +02:00
|
|
|
for (StringRef Filename : Coverage->getUniqueSourceFiles())
|
2014-08-23 00:56:03 +02:00
|
|
|
SourceFiles.push_back(Filename);
|
|
|
|
|
2016-06-28 18:12:24 +02:00
|
|
|
// Create an index out of the source files.
|
|
|
|
if (ViewOpts.hasOutputDirectory()) {
|
2016-09-09 03:32:55 +02:00
|
|
|
if (Error E = Printer->createIndexFile(SourceFiles, *Coverage)) {
|
2016-07-15 03:53:39 +02:00
|
|
|
error("Could not create index file!", toString(std::move(E)));
|
2016-06-28 18:12:24 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-13 23:38:36 +02:00
|
|
|
// In -output-dir mode, it's safe to use multiple threads to print files.
|
|
|
|
unsigned ThreadCount = 1;
|
|
|
|
if (ViewOpts.hasOutputDirectory())
|
|
|
|
ThreadCount = std::thread::hardware_concurrency();
|
|
|
|
ThreadPool Pool(ThreadCount);
|
|
|
|
|
2016-07-15 03:19:35 +02:00
|
|
|
for (StringRef SourceFile : SourceFiles) {
|
|
|
|
Pool.async([this, SourceFile, &Coverage, &Printer, ShowFilenames] {
|
2016-07-13 23:38:36 +02:00
|
|
|
auto View = createSourceFileView(SourceFile, *Coverage);
|
|
|
|
if (!View) {
|
2016-07-18 19:53:12 +02:00
|
|
|
warning("The file '" + SourceFile.str() + "' isn't covered.");
|
2016-07-13 23:38:36 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-08-23 00:56:03 +02:00
|
|
|
|
2016-07-13 23:38:36 +02:00
|
|
|
auto OSOrErr = Printer->createViewFile(SourceFile, /*InToplevel=*/false);
|
|
|
|
if (Error E = OSOrErr.takeError()) {
|
2016-07-18 19:53:12 +02:00
|
|
|
error("Could not create view file!", toString(std::move(E)));
|
2016-07-13 23:38:36 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto OS = std::move(OSOrErr.get());
|
|
|
|
|
|
|
|
View->print(*OS.get(), /*Wholefile=*/true,
|
|
|
|
/*ShowSourceName=*/ShowFilenames);
|
|
|
|
Printer->closeViewFile(std::move(OS));
|
|
|
|
});
|
2014-08-23 00:56:03 +02:00
|
|
|
}
|
|
|
|
|
2016-07-13 23:38:36 +02:00
|
|
|
Pool.wait();
|
|
|
|
|
2014-08-23 00:56:03 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CodeCoverageTool::report(int argc, const char **argv,
|
|
|
|
CommandLineParserType commandLineParser) {
|
|
|
|
auto Err = commandLineParser(argc, argv);
|
|
|
|
if (Err)
|
|
|
|
return Err;
|
|
|
|
|
2016-07-06 23:44:05 +02:00
|
|
|
if (ViewOpts.Format == CoverageViewOptions::OutputFormat::HTML)
|
|
|
|
error("HTML output for summary reports is not yet supported.");
|
|
|
|
|
2014-09-20 17:31:56 +02:00
|
|
|
auto Coverage = load();
|
|
|
|
if (!Coverage)
|
2014-08-23 00:56:03 +02:00
|
|
|
return 1;
|
|
|
|
|
2016-09-07 00:45:57 +02:00
|
|
|
CoverageReport Report(ViewOpts, *Coverage.get());
|
2015-02-14 03:05:05 +01:00
|
|
|
if (SourceFiles.empty())
|
2014-08-23 00:56:03 +02:00
|
|
|
Report.renderFileReports(llvm::outs());
|
2015-02-14 03:05:05 +01:00
|
|
|
else
|
|
|
|
Report.renderFunctionReports(SourceFiles, llvm::outs());
|
2014-08-23 00:56:03 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-07-27 00:50:58 +02:00
|
|
|
int CodeCoverageTool::export_(int argc, const char **argv,
|
|
|
|
CommandLineParserType commandLineParser) {
|
|
|
|
|
|
|
|
auto Err = commandLineParser(argc, argv);
|
|
|
|
if (Err)
|
|
|
|
return Err;
|
|
|
|
|
|
|
|
auto Coverage = load();
|
|
|
|
if (!Coverage) {
|
|
|
|
error("Could not load coverage information");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
exportCoverageDataToJson(ObjectFilename, *Coverage.get(), outs());
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-30 21:57:49 +01:00
|
|
|
int showMain(int argc, const char *argv[]) {
|
2014-08-23 00:56:03 +02:00
|
|
|
CodeCoverageTool Tool;
|
|
|
|
return Tool.run(CodeCoverageTool::Show, argc, argv);
|
|
|
|
}
|
|
|
|
|
2014-10-30 21:57:49 +01:00
|
|
|
int reportMain(int argc, const char *argv[]) {
|
2014-08-23 00:56:03 +02:00
|
|
|
CodeCoverageTool Tool;
|
|
|
|
return Tool.run(CodeCoverageTool::Report, argc, argv);
|
|
|
|
}
|
2016-07-27 00:50:58 +02:00
|
|
|
|
|
|
|
int exportMain(int argc, const char *argv[]) {
|
|
|
|
CodeCoverageTool Tool;
|
|
|
|
return Tool.run(CodeCoverageTool::Export, argc, argv);
|
|
|
|
}
|