2014-08-23 06:56:03 +08:00
|
|
|
//===- CoverageSummaryInfo.h - Coverage summary for function/file ---------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// These structures are used to represent code coverage metrics
|
|
|
|
// for functions/files.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_COV_COVERAGESUMMARYINFO_H
|
|
|
|
#define LLVM_COV_COVERAGESUMMARYINFO_H
|
|
|
|
|
2016-04-30 02:53:05 +08:00
|
|
|
#include "llvm/ProfileData/Coverage/CoverageMapping.h"
|
2014-08-23 06:56:03 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2018-05-01 23:54:18 +08:00
|
|
|
/// Provides information about region coverage for a function/file.
|
2017-09-16 07:00:01 +08:00
|
|
|
class RegionCoverageInfo {
|
2018-05-01 23:54:18 +08:00
|
|
|
/// The number of regions that were executed at least once.
|
2014-08-23 06:56:03 +08:00
|
|
|
size_t Covered;
|
|
|
|
|
2018-05-01 23:54:18 +08:00
|
|
|
/// The total number of regions in a function/file.
|
2014-08-23 06:56:03 +08:00
|
|
|
size_t NumRegions;
|
|
|
|
|
2017-09-16 07:00:01 +08:00
|
|
|
public:
|
2017-09-16 07:00:00 +08:00
|
|
|
RegionCoverageInfo() : Covered(0), NumRegions(0) {}
|
2015-02-14 10:01:24 +08:00
|
|
|
|
2014-08-23 06:56:03 +08:00
|
|
|
RegionCoverageInfo(size_t Covered, size_t NumRegions)
|
2017-09-16 07:00:02 +08:00
|
|
|
: Covered(Covered), NumRegions(NumRegions) {
|
|
|
|
assert(Covered <= NumRegions && "Covered regions over-counted");
|
|
|
|
}
|
2014-08-23 06:56:03 +08:00
|
|
|
|
2015-02-14 10:01:24 +08:00
|
|
|
RegionCoverageInfo &operator+=(const RegionCoverageInfo &RHS) {
|
|
|
|
Covered += RHS.Covered;
|
|
|
|
NumRegions += RHS.NumRegions;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2017-09-16 07:00:01 +08:00
|
|
|
void merge(const RegionCoverageInfo &RHS) {
|
|
|
|
Covered = std::max(Covered, RHS.Covered);
|
2017-09-16 07:00:02 +08:00
|
|
|
NumRegions = std::max(NumRegions, RHS.NumRegions);
|
2017-09-16 07:00:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t getCovered() const { return Covered; }
|
|
|
|
|
|
|
|
size_t getNumRegions() const { return NumRegions; }
|
|
|
|
|
2014-08-23 06:56:03 +08:00
|
|
|
bool isFullyCovered() const { return Covered == NumRegions; }
|
|
|
|
|
|
|
|
double getPercentCovered() const {
|
2017-09-16 07:00:02 +08:00
|
|
|
assert(Covered <= NumRegions && "Covered regions over-counted");
|
2016-04-29 09:31:49 +08:00
|
|
|
if (NumRegions == 0)
|
|
|
|
return 0.0;
|
2014-08-23 06:56:03 +08:00
|
|
|
return double(Covered) / double(NumRegions) * 100.0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-05-01 23:54:18 +08:00
|
|
|
/// Provides information about line coverage for a function/file.
|
2017-09-16 07:00:01 +08:00
|
|
|
class LineCoverageInfo {
|
2018-05-01 23:54:18 +08:00
|
|
|
/// The number of lines that were executed at least once.
|
2014-08-23 06:56:03 +08:00
|
|
|
size_t Covered;
|
|
|
|
|
2018-05-01 23:54:18 +08:00
|
|
|
/// The total number of lines in a function/file.
|
2014-08-23 06:56:03 +08:00
|
|
|
size_t NumLines;
|
|
|
|
|
2017-09-16 07:00:01 +08:00
|
|
|
public:
|
2017-09-16 07:00:00 +08:00
|
|
|
LineCoverageInfo() : Covered(0), NumLines(0) {}
|
2015-02-14 10:01:24 +08:00
|
|
|
|
2016-09-19 09:46:01 +08:00
|
|
|
LineCoverageInfo(size_t Covered, size_t NumLines)
|
2017-09-16 07:00:02 +08:00
|
|
|
: Covered(Covered), NumLines(NumLines) {
|
|
|
|
assert(Covered <= NumLines && "Covered lines over-counted");
|
|
|
|
}
|
2014-08-23 06:56:03 +08:00
|
|
|
|
2015-02-14 10:01:24 +08:00
|
|
|
LineCoverageInfo &operator+=(const LineCoverageInfo &RHS) {
|
|
|
|
Covered += RHS.Covered;
|
|
|
|
NumLines += RHS.NumLines;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2017-09-16 07:00:01 +08:00
|
|
|
void merge(const LineCoverageInfo &RHS) {
|
|
|
|
Covered = std::max(Covered, RHS.Covered);
|
2017-09-16 07:00:02 +08:00
|
|
|
NumLines = std::max(NumLines, RHS.NumLines);
|
2017-09-16 07:00:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t getCovered() const { return Covered; }
|
|
|
|
|
|
|
|
size_t getNumLines() const { return NumLines; }
|
|
|
|
|
2016-09-19 09:46:01 +08:00
|
|
|
bool isFullyCovered() const { return Covered == NumLines; }
|
2014-08-23 06:56:03 +08:00
|
|
|
|
|
|
|
double getPercentCovered() const {
|
2017-09-16 07:00:02 +08:00
|
|
|
assert(Covered <= NumLines && "Covered lines over-counted");
|
2016-09-19 09:46:01 +08:00
|
|
|
if (NumLines == 0)
|
2016-04-29 09:31:49 +08:00
|
|
|
return 0.0;
|
2016-09-19 09:46:01 +08:00
|
|
|
return double(Covered) / double(NumLines) * 100.0;
|
2014-08-23 06:56:03 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-05-01 23:54:18 +08:00
|
|
|
/// Provides information about function coverage for a file.
|
2017-09-16 07:00:01 +08:00
|
|
|
class FunctionCoverageInfo {
|
2018-05-01 23:54:18 +08:00
|
|
|
/// The number of functions that were executed.
|
2014-09-30 20:45:13 +08:00
|
|
|
size_t Executed;
|
2014-08-23 06:56:03 +08:00
|
|
|
|
2018-05-01 23:54:18 +08:00
|
|
|
/// The total number of functions in this file.
|
2014-08-23 06:56:03 +08:00
|
|
|
size_t NumFunctions;
|
|
|
|
|
2017-09-16 07:00:01 +08:00
|
|
|
public:
|
2015-02-14 10:01:24 +08:00
|
|
|
FunctionCoverageInfo() : Executed(0), NumFunctions(0) {}
|
|
|
|
|
2014-09-30 20:45:13 +08:00
|
|
|
FunctionCoverageInfo(size_t Executed, size_t NumFunctions)
|
|
|
|
: Executed(Executed), NumFunctions(NumFunctions) {}
|
2014-08-23 06:56:03 +08:00
|
|
|
|
2018-01-06 00:15:07 +08:00
|
|
|
FunctionCoverageInfo &operator+=(const FunctionCoverageInfo &RHS) {
|
|
|
|
Executed += RHS.Executed;
|
|
|
|
NumFunctions += RHS.NumFunctions;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-02-14 10:01:24 +08:00
|
|
|
void addFunction(bool Covered) {
|
|
|
|
if (Covered)
|
|
|
|
++Executed;
|
|
|
|
++NumFunctions;
|
|
|
|
}
|
|
|
|
|
2017-09-16 07:00:01 +08:00
|
|
|
size_t getExecuted() const { return Executed; }
|
|
|
|
|
|
|
|
size_t getNumFunctions() const { return NumFunctions; }
|
|
|
|
|
2014-09-30 20:45:13 +08:00
|
|
|
bool isFullyCovered() const { return Executed == NumFunctions; }
|
2014-08-23 06:56:03 +08:00
|
|
|
|
|
|
|
double getPercentCovered() const {
|
2017-09-16 07:00:02 +08:00
|
|
|
assert(Executed <= NumFunctions && "Covered functions over-counted");
|
2016-04-29 09:31:49 +08:00
|
|
|
if (NumFunctions == 0)
|
|
|
|
return 0.0;
|
2014-09-30 20:45:13 +08:00
|
|
|
return double(Executed) / double(NumFunctions) * 100.0;
|
2014-08-23 06:56:03 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-05-01 23:54:18 +08:00
|
|
|
/// A summary of function's code coverage.
|
2014-08-23 06:56:03 +08:00
|
|
|
struct FunctionCoverageSummary {
|
2017-08-03 07:35:25 +08:00
|
|
|
std::string Name;
|
2014-09-30 20:45:13 +08:00
|
|
|
uint64_t ExecutionCount;
|
2014-08-23 06:56:03 +08:00
|
|
|
RegionCoverageInfo RegionCoverage;
|
|
|
|
LineCoverageInfo LineCoverage;
|
|
|
|
|
2017-09-09 02:44:49 +08:00
|
|
|
FunctionCoverageSummary(const std::string &Name)
|
2017-09-16 07:00:02 +08:00
|
|
|
: Name(Name), ExecutionCount(0), RegionCoverage(), LineCoverage() {}
|
2015-02-14 10:01:24 +08:00
|
|
|
|
2017-09-09 02:44:49 +08:00
|
|
|
FunctionCoverageSummary(const std::string &Name, uint64_t ExecutionCount,
|
2014-08-23 06:56:03 +08:00
|
|
|
const RegionCoverageInfo &RegionCoverage,
|
|
|
|
const LineCoverageInfo &LineCoverage)
|
2014-09-30 20:45:13 +08:00
|
|
|
: Name(Name), ExecutionCount(ExecutionCount),
|
2017-09-09 02:44:49 +08:00
|
|
|
RegionCoverage(RegionCoverage), LineCoverage(LineCoverage) {}
|
2014-08-23 06:56:03 +08:00
|
|
|
|
2018-05-01 23:54:18 +08:00
|
|
|
/// Compute the code coverage summary for the given function coverage
|
2014-08-23 06:56:03 +08:00
|
|
|
/// mapping record.
|
2017-09-19 10:00:12 +08:00
|
|
|
static FunctionCoverageSummary get(const coverage::CoverageMapping &CM,
|
|
|
|
const coverage::FunctionRecord &Function);
|
2016-09-19 08:38:23 +08:00
|
|
|
|
2017-08-03 07:35:25 +08:00
|
|
|
/// Compute the code coverage summary for an instantiation group \p Group,
|
|
|
|
/// given a list of summaries for each instantiation in \p Summaries.
|
|
|
|
static FunctionCoverageSummary
|
|
|
|
get(const coverage::InstantiationGroup &Group,
|
|
|
|
ArrayRef<FunctionCoverageSummary> Summaries);
|
2014-08-23 06:56:03 +08:00
|
|
|
};
|
|
|
|
|
2018-05-01 23:54:18 +08:00
|
|
|
/// A summary of file's code coverage.
|
2014-08-23 06:56:03 +08:00
|
|
|
struct FileCoverageSummary {
|
|
|
|
StringRef Name;
|
|
|
|
RegionCoverageInfo RegionCoverage;
|
|
|
|
LineCoverageInfo LineCoverage;
|
|
|
|
FunctionCoverageInfo FunctionCoverage;
|
2016-09-19 08:38:23 +08:00
|
|
|
FunctionCoverageInfo InstantiationCoverage;
|
2015-02-14 10:01:24 +08:00
|
|
|
|
2017-09-16 07:00:02 +08:00
|
|
|
FileCoverageSummary(StringRef Name)
|
|
|
|
: Name(Name), RegionCoverage(), LineCoverage(), FunctionCoverage(),
|
|
|
|
InstantiationCoverage() {}
|
2015-02-14 10:01:24 +08:00
|
|
|
|
2018-01-06 00:15:07 +08:00
|
|
|
FileCoverageSummary &operator+=(const FileCoverageSummary &RHS) {
|
|
|
|
RegionCoverage += RHS.RegionCoverage;
|
|
|
|
LineCoverage += RHS.LineCoverage;
|
|
|
|
FunctionCoverage += RHS.FunctionCoverage;
|
|
|
|
InstantiationCoverage += RHS.InstantiationCoverage;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-02-14 10:01:24 +08:00
|
|
|
void addFunction(const FunctionCoverageSummary &Function) {
|
|
|
|
RegionCoverage += Function.RegionCoverage;
|
|
|
|
LineCoverage += Function.LineCoverage;
|
|
|
|
FunctionCoverage.addFunction(/*Covered=*/Function.ExecutionCount > 0);
|
|
|
|
}
|
2016-09-19 08:38:23 +08:00
|
|
|
|
|
|
|
void addInstantiation(const FunctionCoverageSummary &Function) {
|
|
|
|
InstantiationCoverage.addFunction(/*Covered=*/Function.ExecutionCount > 0);
|
|
|
|
}
|
2014-08-23 06:56:03 +08:00
|
|
|
};
|
|
|
|
|
2018-05-01 23:54:18 +08:00
|
|
|
/// A cache for demangled symbols.
|
2017-02-06 04:10:58 +08:00
|
|
|
struct DemangleCache {
|
|
|
|
StringMap<std::string> DemangledNames;
|
|
|
|
|
2018-05-01 23:54:18 +08:00
|
|
|
/// Demangle \p Sym if possible. Otherwise, just return \p Sym.
|
2017-02-06 04:10:58 +08:00
|
|
|
StringRef demangle(StringRef Sym) const {
|
|
|
|
const auto DemangledName = DemangledNames.find(Sym);
|
|
|
|
if (DemangledName == DemangledNames.end())
|
|
|
|
return Sym;
|
|
|
|
return DemangledName->getValue();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-08-23 06:56:03 +08:00
|
|
|
} // namespace llvm
|
|
|
|
|
|
|
|
#endif // LLVM_COV_COVERAGESUMMARYINFO_H
|