2014-08-23 06:56:03 +08:00
|
|
|
//===- CoverageReport.cpp - Code coverage report -------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This class implements rendering of a code coverage report.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "CoverageReport.h"
|
|
|
|
#include "RenderingSupport.h"
|
2016-09-19 08:38:23 +08:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2014-08-23 06:56:03 +08:00
|
|
|
#include "llvm/Support/FileSystem.h"
|
2015-01-14 19:23:27 +08:00
|
|
|
#include "llvm/Support/Format.h"
|
2016-09-10 01:37:11 +08:00
|
|
|
#include "llvm/Support/Path.h"
|
2016-09-07 06:45:57 +08:00
|
|
|
#include <numeric>
|
2014-08-23 06:56:03 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
2016-09-07 06:45:57 +08:00
|
|
|
|
2014-08-23 06:56:03 +08:00
|
|
|
namespace {
|
2016-09-07 06:45:57 +08:00
|
|
|
|
2014-08-23 06:56:03 +08:00
|
|
|
/// \brief Helper struct which prints trimmed and aligned columns.
|
|
|
|
struct Column {
|
2016-09-07 06:45:57 +08:00
|
|
|
enum TrimKind { NoTrim, WidthTrim, RightTrim };
|
2014-08-23 06:56:03 +08:00
|
|
|
|
|
|
|
enum AlignmentKind { LeftAlignment, RightAlignment };
|
|
|
|
|
|
|
|
StringRef Str;
|
|
|
|
unsigned Width;
|
|
|
|
TrimKind Trim;
|
|
|
|
AlignmentKind Alignment;
|
|
|
|
|
|
|
|
Column(StringRef Str, unsigned Width)
|
2015-09-15 07:26:36 +08:00
|
|
|
: Str(Str), Width(Width), Trim(WidthTrim), Alignment(LeftAlignment) {}
|
2014-08-23 06:56:03 +08:00
|
|
|
|
|
|
|
Column &set(TrimKind Value) {
|
|
|
|
Trim = Value;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
Column &set(AlignmentKind Value) {
|
|
|
|
Alignment = Value;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-09-07 06:45:57 +08:00
|
|
|
void render(raw_ostream &OS) const {
|
|
|
|
if (Str.size() <= Width) {
|
|
|
|
if (Alignment == RightAlignment) {
|
|
|
|
OS.indent(Width - Str.size());
|
|
|
|
OS << Str;
|
|
|
|
return;
|
|
|
|
}
|
2014-08-23 06:56:03 +08:00
|
|
|
OS << Str;
|
2016-09-07 06:45:57 +08:00
|
|
|
OS.indent(Width - Str.size());
|
2014-08-23 06:56:03 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-07 06:45:57 +08:00
|
|
|
switch (Trim) {
|
|
|
|
case NoTrim:
|
|
|
|
OS << Str;
|
|
|
|
break;
|
|
|
|
case WidthTrim:
|
|
|
|
OS << Str.substr(0, Width);
|
|
|
|
break;
|
|
|
|
case RightTrim:
|
|
|
|
OS << Str.substr(0, Width - 3) << "...";
|
|
|
|
break;
|
|
|
|
}
|
2014-08-23 06:56:03 +08:00
|
|
|
}
|
2016-09-07 06:45:57 +08:00
|
|
|
};
|
2014-08-23 06:56:03 +08:00
|
|
|
|
2016-09-07 06:45:57 +08:00
|
|
|
raw_ostream &operator<<(raw_ostream &OS, const Column &Value) {
|
|
|
|
Value.render(OS);
|
|
|
|
return OS;
|
2014-08-23 06:56:03 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 06:45:57 +08:00
|
|
|
Column column(StringRef Str, unsigned Width) { return Column(Str, Width); }
|
|
|
|
|
2014-08-23 06:56:03 +08:00
|
|
|
template <typename T>
|
2016-09-07 06:45:57 +08:00
|
|
|
Column column(StringRef Str, unsigned Width, const T &Value) {
|
2014-08-23 06:56:03 +08:00
|
|
|
return Column(Str, Width).set(Value);
|
|
|
|
}
|
|
|
|
|
2016-07-22 20:46:13 +08:00
|
|
|
// Specify the default column widths.
|
2016-09-19 08:38:23 +08:00
|
|
|
size_t FileReportColumns[] = {25, 12, 18, 10, 12, 18, 10,
|
|
|
|
16, 16, 10, 12, 18, 10};
|
2016-09-07 06:45:57 +08:00
|
|
|
size_t FunctionReportColumns[] = {25, 10, 8, 8, 10, 8, 8};
|
2014-08-23 06:56:03 +08:00
|
|
|
|
2016-09-07 06:45:57 +08:00
|
|
|
/// \brief Adjust column widths to fit long file paths and function names.
|
2016-09-19 08:38:16 +08:00
|
|
|
void adjustColumnWidths(ArrayRef<StringRef> Files,
|
|
|
|
ArrayRef<StringRef> Functions) {
|
|
|
|
for (StringRef Filename : Files)
|
2015-10-22 00:03:32 +08:00
|
|
|
FileReportColumns[0] = std::max(FileReportColumns[0], Filename.size());
|
2016-09-19 08:38:16 +08:00
|
|
|
for (StringRef Funcname : Functions)
|
|
|
|
FunctionReportColumns[0] =
|
|
|
|
std::max(FunctionReportColumns[0], Funcname.size());
|
2015-10-22 00:03:32 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 06:45:57 +08:00
|
|
|
/// \brief Prints a horizontal divider long enough to cover the given column
|
|
|
|
/// widths.
|
|
|
|
void renderDivider(ArrayRef<size_t> ColumnWidths, raw_ostream &OS) {
|
|
|
|
size_t Length = std::accumulate(ColumnWidths.begin(), ColumnWidths.end(), 0);
|
|
|
|
for (size_t I = 0; I < Length; ++I)
|
2014-08-23 06:56:03 +08:00
|
|
|
OS << '-';
|
|
|
|
}
|
|
|
|
|
2016-09-07 06:46:00 +08:00
|
|
|
/// \brief Return the color which correponds to the coverage percentage of a
|
|
|
|
/// certain metric.
|
2014-08-23 06:56:03 +08:00
|
|
|
template <typename T>
|
2016-09-07 06:45:57 +08:00
|
|
|
raw_ostream::Colors determineCoveragePercentageColor(const T &Info) {
|
2014-08-23 06:56:03 +08:00
|
|
|
if (Info.isFullyCovered())
|
|
|
|
return raw_ostream::GREEN;
|
|
|
|
return Info.getPercentCovered() >= 80.0 ? raw_ostream::YELLOW
|
|
|
|
: raw_ostream::RED;
|
|
|
|
}
|
|
|
|
|
2017-02-24 06:20:32 +08:00
|
|
|
/// \brief Get the number of redundant path components in each path in \p Paths.
|
|
|
|
unsigned getNumRedundantPathComponents(ArrayRef<std::string> Paths) {
|
|
|
|
// To start, set the number of redundant path components to the maximum
|
|
|
|
// possible value.
|
|
|
|
SmallVector<StringRef, 8> FirstPathComponents{sys::path::begin(Paths[0]),
|
|
|
|
sys::path::end(Paths[0])};
|
|
|
|
unsigned NumRedundant = FirstPathComponents.size();
|
|
|
|
|
|
|
|
for (unsigned I = 1, E = Paths.size(); NumRedundant > 0 && I < E; ++I) {
|
|
|
|
StringRef Path = Paths[I];
|
|
|
|
for (const auto &Component :
|
|
|
|
enumerate(make_range(sys::path::begin(Path), sys::path::end(Path)))) {
|
|
|
|
// Do not increase the number of redundant components: that would remove
|
|
|
|
// useful parts of already-visited paths.
|
2017-03-14 00:32:08 +08:00
|
|
|
if (Component.index() >= NumRedundant)
|
2016-09-27 01:57:13 +08:00
|
|
|
break;
|
2017-02-24 06:20:32 +08:00
|
|
|
|
|
|
|
// Lower the number of redundant components when there's a mismatch
|
|
|
|
// between the first path, and the path under consideration.
|
2017-03-14 00:32:08 +08:00
|
|
|
if (FirstPathComponents[Component.index()] != Component.value()) {
|
|
|
|
NumRedundant = Component.index();
|
2017-02-24 06:20:32 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NumRedundant;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Determine the length of the longest redundant prefix of the paths in
|
|
|
|
/// \p Paths.
|
|
|
|
unsigned getRedundantPrefixLen(ArrayRef<std::string> Paths) {
|
|
|
|
// If there's at most one path, no path components are redundant.
|
|
|
|
if (Paths.size() <= 1)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
unsigned PrefixLen = 0;
|
|
|
|
unsigned NumRedundant = getNumRedundantPathComponents(Paths);
|
|
|
|
auto Component = sys::path::begin(Paths[0]);
|
|
|
|
for (unsigned I = 0; I < NumRedundant; ++I) {
|
|
|
|
auto LastComponent = Component;
|
|
|
|
++Component;
|
|
|
|
PrefixLen += Component - LastComponent;
|
2016-09-08 08:56:43 +08:00
|
|
|
}
|
2017-02-24 06:20:32 +08:00
|
|
|
return PrefixLen;
|
2016-09-08 08:56:43 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 06:45:57 +08:00
|
|
|
} // end anonymous namespace
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2016-09-09 09:32:49 +08:00
|
|
|
void CoverageReport::render(const FileCoverageSummary &File,
|
|
|
|
raw_ostream &OS) const {
|
2016-09-07 06:46:00 +08:00
|
|
|
auto FileCoverageColor =
|
|
|
|
determineCoveragePercentageColor(File.RegionCoverage);
|
|
|
|
auto FuncCoverageColor =
|
|
|
|
determineCoveragePercentageColor(File.FunctionCoverage);
|
2016-09-19 08:38:23 +08:00
|
|
|
auto InstantiationCoverageColor =
|
|
|
|
determineCoveragePercentageColor(File.InstantiationCoverage);
|
2016-09-07 06:46:00 +08:00
|
|
|
auto LineCoverageColor = determineCoveragePercentageColor(File.LineCoverage);
|
2016-09-10 01:37:11 +08:00
|
|
|
SmallString<256> FileName = File.Name;
|
|
|
|
sys::path::remove_dots(FileName, /*remove_dot_dots=*/true);
|
|
|
|
sys::path::native(FileName);
|
2017-09-12 06:56:20 +08:00
|
|
|
OS << column(FileName, FileReportColumns[0], Column::NoTrim);
|
|
|
|
|
|
|
|
if (Options.ShowRegionSummary) {
|
|
|
|
OS << format("%*u", FileReportColumns[1],
|
2017-09-16 07:00:01 +08:00
|
|
|
(unsigned)File.RegionCoverage.getNumRegions());
|
|
|
|
Options.colored_ostream(OS, FileCoverageColor)
|
|
|
|
<< format("%*u", FileReportColumns[2],
|
|
|
|
(unsigned)(File.RegionCoverage.getNumRegions() -
|
|
|
|
File.RegionCoverage.getCovered()));
|
|
|
|
if (File.RegionCoverage.getNumRegions())
|
2017-09-12 06:56:20 +08:00
|
|
|
Options.colored_ostream(OS, FileCoverageColor)
|
|
|
|
<< format("%*.2f", FileReportColumns[3] - 1,
|
|
|
|
File.RegionCoverage.getPercentCovered())
|
|
|
|
<< '%';
|
|
|
|
else
|
|
|
|
OS << column("-", FileReportColumns[3], Column::RightAlignment);
|
|
|
|
}
|
|
|
|
|
2014-10-01 08:29:26 +08:00
|
|
|
OS << format("%*u", FileReportColumns[4],
|
2017-09-16 07:00:01 +08:00
|
|
|
(unsigned)File.FunctionCoverage.getNumFunctions());
|
2016-07-22 20:46:13 +08:00
|
|
|
OS << format("%*u", FileReportColumns[5],
|
2017-09-16 07:00:01 +08:00
|
|
|
(unsigned)(File.FunctionCoverage.getNumFunctions() -
|
|
|
|
File.FunctionCoverage.getExecuted()));
|
|
|
|
if (File.FunctionCoverage.getNumFunctions())
|
2016-11-21 22:00:04 +08:00
|
|
|
Options.colored_ostream(OS, FuncCoverageColor)
|
|
|
|
<< format("%*.2f", FileReportColumns[6] - 1,
|
|
|
|
File.FunctionCoverage.getPercentCovered())
|
|
|
|
<< '%';
|
|
|
|
else
|
|
|
|
OS << column("-", FileReportColumns[6], Column::RightAlignment);
|
2017-09-12 06:56:20 +08:00
|
|
|
|
|
|
|
if (Options.ShowInstantiationSummary) {
|
|
|
|
OS << format("%*u", FileReportColumns[7],
|
2017-09-16 07:00:01 +08:00
|
|
|
(unsigned)File.InstantiationCoverage.getNumFunctions());
|
2017-09-12 06:56:20 +08:00
|
|
|
OS << format("%*u", FileReportColumns[8],
|
2017-09-16 07:00:01 +08:00
|
|
|
(unsigned)(File.InstantiationCoverage.getNumFunctions() -
|
|
|
|
File.InstantiationCoverage.getExecuted()));
|
|
|
|
if (File.InstantiationCoverage.getNumFunctions())
|
2017-09-12 06:56:20 +08:00
|
|
|
Options.colored_ostream(OS, InstantiationCoverageColor)
|
|
|
|
<< format("%*.2f", FileReportColumns[9] - 1,
|
|
|
|
File.InstantiationCoverage.getPercentCovered())
|
|
|
|
<< '%';
|
|
|
|
else
|
|
|
|
OS << column("-", FileReportColumns[9], Column::RightAlignment);
|
|
|
|
}
|
|
|
|
|
2016-09-19 08:38:23 +08:00
|
|
|
OS << format("%*u", FileReportColumns[10],
|
2017-09-16 07:00:01 +08:00
|
|
|
(unsigned)File.LineCoverage.getNumLines());
|
2016-09-07 06:46:00 +08:00
|
|
|
Options.colored_ostream(OS, LineCoverageColor) << format(
|
2017-09-16 07:00:01 +08:00
|
|
|
"%*u", FileReportColumns[11], (unsigned)(File.LineCoverage.getNumLines() -
|
|
|
|
File.LineCoverage.getCovered()));
|
|
|
|
if (File.LineCoverage.getNumLines())
|
2016-11-21 22:00:04 +08:00
|
|
|
Options.colored_ostream(OS, LineCoverageColor)
|
|
|
|
<< format("%*.2f", FileReportColumns[12] - 1,
|
|
|
|
File.LineCoverage.getPercentCovered())
|
|
|
|
<< '%';
|
|
|
|
else
|
|
|
|
OS << column("-", FileReportColumns[12], Column::RightAlignment);
|
2014-08-23 06:56:03 +08:00
|
|
|
OS << "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
void CoverageReport::render(const FunctionCoverageSummary &Function,
|
2017-02-06 04:11:03 +08:00
|
|
|
const DemangleCache &DC,
|
2016-09-09 09:32:49 +08:00
|
|
|
raw_ostream &OS) const {
|
2016-09-07 06:46:00 +08:00
|
|
|
auto FuncCoverageColor =
|
|
|
|
determineCoveragePercentageColor(Function.RegionCoverage);
|
|
|
|
auto LineCoverageColor =
|
|
|
|
determineCoveragePercentageColor(Function.LineCoverage);
|
2017-02-06 04:11:03 +08:00
|
|
|
OS << column(DC.demangle(Function.Name), FunctionReportColumns[0],
|
|
|
|
Column::RightTrim)
|
2014-10-01 08:29:26 +08:00
|
|
|
<< format("%*u", FunctionReportColumns[1],
|
2017-09-16 07:00:01 +08:00
|
|
|
(unsigned)Function.RegionCoverage.getNumRegions());
|
2016-09-07 06:46:00 +08:00
|
|
|
Options.colored_ostream(OS, FuncCoverageColor)
|
2014-10-01 08:29:26 +08:00
|
|
|
<< format("%*u", FunctionReportColumns[2],
|
2017-09-16 07:00:01 +08:00
|
|
|
(unsigned)(Function.RegionCoverage.getNumRegions() -
|
|
|
|
Function.RegionCoverage.getCovered()));
|
2014-08-23 06:56:03 +08:00
|
|
|
Options.colored_ostream(
|
|
|
|
OS, determineCoveragePercentageColor(Function.RegionCoverage))
|
|
|
|
<< format("%*.2f", FunctionReportColumns[3] - 1,
|
2016-09-07 06:46:00 +08:00
|
|
|
Function.RegionCoverage.getPercentCovered())
|
|
|
|
<< '%';
|
2014-10-01 08:29:26 +08:00
|
|
|
OS << format("%*u", FunctionReportColumns[4],
|
2017-09-16 07:00:01 +08:00
|
|
|
(unsigned)Function.LineCoverage.getNumLines());
|
2016-09-07 06:46:00 +08:00
|
|
|
Options.colored_ostream(OS, LineCoverageColor)
|
2014-10-01 08:29:26 +08:00
|
|
|
<< format("%*u", FunctionReportColumns[5],
|
2017-09-16 07:00:01 +08:00
|
|
|
(unsigned)(Function.LineCoverage.getNumLines() -
|
|
|
|
Function.LineCoverage.getCovered()));
|
2014-08-23 06:56:03 +08:00
|
|
|
Options.colored_ostream(
|
|
|
|
OS, determineCoveragePercentageColor(Function.LineCoverage))
|
|
|
|
<< format("%*.2f", FunctionReportColumns[6] - 1,
|
2016-09-07 06:46:00 +08:00
|
|
|
Function.LineCoverage.getPercentCovered())
|
|
|
|
<< '%';
|
2014-08-23 06:56:03 +08:00
|
|
|
OS << "\n";
|
|
|
|
}
|
|
|
|
|
2016-09-24 02:57:32 +08:00
|
|
|
void CoverageReport::renderFunctionReports(ArrayRef<std::string> Files,
|
2017-02-06 04:11:03 +08:00
|
|
|
const DemangleCache &DC,
|
2015-02-14 10:05:05 +08:00
|
|
|
raw_ostream &OS) {
|
2014-08-23 06:56:03 +08:00
|
|
|
bool isFirst = true;
|
2015-02-14 10:05:05 +08:00
|
|
|
for (StringRef Filename : Files) {
|
2016-09-19 08:38:16 +08:00
|
|
|
auto Functions = Coverage.getCoveredFunctions(Filename);
|
|
|
|
|
2014-08-23 06:56:03 +08:00
|
|
|
if (isFirst)
|
|
|
|
isFirst = false;
|
|
|
|
else
|
|
|
|
OS << "\n";
|
2016-09-19 08:38:16 +08:00
|
|
|
|
|
|
|
std::vector<StringRef> Funcnames;
|
|
|
|
for (const auto &F : Functions)
|
2017-02-06 04:11:03 +08:00
|
|
|
Funcnames.emplace_back(DC.demangle(F.Name));
|
2016-09-19 08:38:16 +08:00
|
|
|
adjustColumnWidths({}, Funcnames);
|
|
|
|
|
2015-02-14 10:01:24 +08:00
|
|
|
OS << "File '" << Filename << "':\n";
|
2014-08-23 06:56:03 +08:00
|
|
|
OS << column("Name", FunctionReportColumns[0])
|
|
|
|
<< column("Regions", FunctionReportColumns[1], Column::RightAlignment)
|
|
|
|
<< column("Miss", FunctionReportColumns[2], Column::RightAlignment)
|
|
|
|
<< column("Cover", FunctionReportColumns[3], Column::RightAlignment)
|
|
|
|
<< column("Lines", FunctionReportColumns[4], Column::RightAlignment)
|
|
|
|
<< column("Miss", FunctionReportColumns[5], Column::RightAlignment)
|
|
|
|
<< column("Cover", FunctionReportColumns[6], Column::RightAlignment);
|
|
|
|
OS << "\n";
|
|
|
|
renderDivider(FunctionReportColumns, OS);
|
|
|
|
OS << "\n";
|
2015-02-14 10:01:24 +08:00
|
|
|
FunctionCoverageSummary Totals("TOTAL");
|
2016-09-19 08:38:16 +08:00
|
|
|
for (const auto &F : Functions) {
|
2017-09-19 10:00:12 +08:00
|
|
|
auto Function = FunctionCoverageSummary::get(Coverage, F);
|
2015-02-14 10:01:24 +08:00
|
|
|
++Totals.ExecutionCount;
|
|
|
|
Totals.RegionCoverage += Function.RegionCoverage;
|
|
|
|
Totals.LineCoverage += Function.LineCoverage;
|
2017-02-06 04:11:03 +08:00
|
|
|
render(Function, DC, OS);
|
2015-02-14 10:01:24 +08:00
|
|
|
}
|
|
|
|
if (Totals.ExecutionCount) {
|
|
|
|
renderDivider(FunctionReportColumns, OS);
|
|
|
|
OS << "\n";
|
2017-02-06 04:11:03 +08:00
|
|
|
render(Totals, DC, OS);
|
2015-02-14 10:01:24 +08:00
|
|
|
}
|
2014-08-23 06:56:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-09 02:44:49 +08:00
|
|
|
std::vector<FileCoverageSummary> CoverageReport::prepareFileReports(
|
|
|
|
const coverage::CoverageMapping &Coverage, FileCoverageSummary &Totals,
|
2017-09-28 18:07:30 +08:00
|
|
|
ArrayRef<std::string> Files, const CoverageViewOptions &Options,
|
|
|
|
const CoverageFilter &Filters) {
|
2016-09-09 09:32:49 +08:00
|
|
|
std::vector<FileCoverageSummary> FileReports;
|
2017-02-24 06:20:32 +08:00
|
|
|
unsigned LCP = getRedundantPrefixLen(Files);
|
2016-09-09 09:32:49 +08:00
|
|
|
|
|
|
|
for (StringRef Filename : Files) {
|
|
|
|
FileCoverageSummary Summary(Filename.drop_front(LCP));
|
2016-09-19 08:38:23 +08:00
|
|
|
|
2017-08-03 07:35:25 +08:00
|
|
|
for (const auto &Group : Coverage.getInstantiationGroups(Filename)) {
|
|
|
|
std::vector<FunctionCoverageSummary> InstantiationSummaries;
|
|
|
|
for (const coverage::FunctionRecord *F : Group.getInstantiations()) {
|
2017-09-28 18:07:30 +08:00
|
|
|
if (!Filters.matches(Coverage, *F))
|
|
|
|
continue;
|
2017-09-19 10:00:12 +08:00
|
|
|
auto InstantiationSummary = FunctionCoverageSummary::get(Coverage, *F);
|
2017-08-03 07:35:25 +08:00
|
|
|
Summary.addInstantiation(InstantiationSummary);
|
|
|
|
Totals.addInstantiation(InstantiationSummary);
|
|
|
|
InstantiationSummaries.push_back(InstantiationSummary);
|
|
|
|
}
|
2017-09-28 18:07:30 +08:00
|
|
|
if (InstantiationSummaries.empty())
|
|
|
|
continue;
|
2016-09-19 08:38:23 +08:00
|
|
|
|
2017-08-03 07:35:25 +08:00
|
|
|
auto GroupSummary =
|
|
|
|
FunctionCoverageSummary::get(Group, InstantiationSummaries);
|
2017-09-09 02:44:49 +08:00
|
|
|
|
|
|
|
if (Options.Debug)
|
|
|
|
outs() << "InstantiationGroup: " << GroupSummary.Name << " with "
|
|
|
|
<< "size = " << Group.size() << "\n";
|
|
|
|
|
2017-08-03 07:35:25 +08:00
|
|
|
Summary.addFunction(GroupSummary);
|
|
|
|
Totals.addFunction(GroupSummary);
|
2016-09-19 08:38:23 +08:00
|
|
|
}
|
|
|
|
|
2016-09-09 09:32:49 +08:00
|
|
|
FileReports.push_back(Summary);
|
|
|
|
}
|
|
|
|
|
|
|
|
return FileReports;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CoverageReport::renderFileReports(raw_ostream &OS) const {
|
2016-09-24 02:57:32 +08:00
|
|
|
std::vector<std::string> UniqueSourceFiles;
|
|
|
|
for (StringRef SF : Coverage.getUniqueSourceFiles())
|
|
|
|
UniqueSourceFiles.emplace_back(SF.str());
|
2017-10-13 22:44:51 +08:00
|
|
|
renderFileReports(OS, UniqueSourceFiles);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CoverageReport::renderFileReports(
|
|
|
|
raw_ostream &OS, ArrayRef<std::string> Files) const {
|
|
|
|
renderFileReports(OS, Files, CoverageFiltersMatchAll());
|
2016-09-09 09:32:49 +08:00
|
|
|
}
|
|
|
|
|
2017-10-03 19:05:28 +08:00
|
|
|
void CoverageReport::renderFileReports(
|
|
|
|
raw_ostream &OS, ArrayRef<std::string> Files,
|
|
|
|
const CoverageFiltersMatchAll &Filters) const {
|
2016-09-19 08:38:16 +08:00
|
|
|
FileCoverageSummary Totals("TOTAL");
|
2017-09-28 18:07:30 +08:00
|
|
|
auto FileReports =
|
|
|
|
prepareFileReports(Coverage, Totals, Files, Options, Filters);
|
2016-09-19 08:38:16 +08:00
|
|
|
|
|
|
|
std::vector<StringRef> Filenames;
|
|
|
|
for (const FileCoverageSummary &FCS : FileReports)
|
|
|
|
Filenames.emplace_back(FCS.Name);
|
|
|
|
adjustColumnWidths(Filenames, {});
|
|
|
|
|
2017-09-12 06:56:20 +08:00
|
|
|
OS << column("Filename", FileReportColumns[0]);
|
|
|
|
if (Options.ShowRegionSummary)
|
|
|
|
OS << column("Regions", FileReportColumns[1], Column::RightAlignment)
|
|
|
|
<< column("Missed Regions", FileReportColumns[2], Column::RightAlignment)
|
|
|
|
<< column("Cover", FileReportColumns[3], Column::RightAlignment);
|
|
|
|
OS << column("Functions", FileReportColumns[4], Column::RightAlignment)
|
2016-09-07 06:46:00 +08:00
|
|
|
<< column("Missed Functions", FileReportColumns[5], Column::RightAlignment)
|
2017-09-12 06:56:20 +08:00
|
|
|
<< column("Executed", FileReportColumns[6], Column::RightAlignment);
|
|
|
|
if (Options.ShowInstantiationSummary)
|
|
|
|
OS << column("Instantiations", FileReportColumns[7], Column::RightAlignment)
|
|
|
|
<< column("Missed Insts.", FileReportColumns[8], Column::RightAlignment)
|
|
|
|
<< column("Executed", FileReportColumns[9], Column::RightAlignment);
|
|
|
|
OS << column("Lines", FileReportColumns[10], Column::RightAlignment)
|
2016-09-19 08:38:23 +08:00
|
|
|
<< column("Missed Lines", FileReportColumns[11], Column::RightAlignment)
|
|
|
|
<< column("Cover", FileReportColumns[12], Column::RightAlignment) << "\n";
|
2014-08-23 06:56:03 +08:00
|
|
|
renderDivider(FileReportColumns, OS);
|
|
|
|
OS << "\n";
|
2015-09-15 07:26:36 +08:00
|
|
|
|
2017-08-10 04:43:31 +08:00
|
|
|
bool EmptyFiles = false;
|
|
|
|
for (const FileCoverageSummary &FCS : FileReports) {
|
2017-09-16 07:00:01 +08:00
|
|
|
if (FCS.FunctionCoverage.getNumFunctions())
|
2017-08-10 04:43:31 +08:00
|
|
|
render(FCS, OS);
|
|
|
|
else
|
|
|
|
EmptyFiles = true;
|
|
|
|
}
|
|
|
|
|
2017-10-03 19:05:28 +08:00
|
|
|
if (EmptyFiles && Filters.empty()) {
|
2017-08-10 04:43:31 +08:00
|
|
|
OS << "\n"
|
|
|
|
<< "Files which contain no functions:\n";
|
|
|
|
|
|
|
|
for (const FileCoverageSummary &FCS : FileReports)
|
2017-09-16 07:00:01 +08:00
|
|
|
if (!FCS.FunctionCoverage.getNumFunctions())
|
2017-08-10 04:43:31 +08:00
|
|
|
render(FCS, OS);
|
|
|
|
}
|
2016-09-09 09:32:49 +08:00
|
|
|
|
2014-08-23 06:56:03 +08:00
|
|
|
renderDivider(FileReportColumns, OS);
|
|
|
|
OS << "\n";
|
2015-02-14 10:01:24 +08:00
|
|
|
render(Totals, OS);
|
2014-08-23 06:56:03 +08:00
|
|
|
}
|
2016-09-07 06:45:57 +08:00
|
|
|
|
|
|
|
} // end namespace llvm
|