mirror of
https://github.com/RPCS3/llvm.git
synced 2025-01-05 19:29:54 +00:00
[sancov] -print-coverage-stats option to print various coverage statistics.
Differential Revision: http://reviews.llvm.org/D18418 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@264222 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
d34f785662
commit
9647ee51e2
9
test/tools/sancov/stats.test
Normal file
9
test/tools/sancov/stats.test
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
REQUIRES: x86_64-linux
|
||||||
|
RUN: sancov -print-coverage-stats %p/Inputs/test-linux_x86_64 %p/Inputs/test-linux_x86_64.0.sancov | FileCheck %s
|
||||||
|
|
||||||
|
CHECK: all-points: 16
|
||||||
|
CHECK: cov-points: 7
|
||||||
|
CHECK: all-fns: 3
|
||||||
|
CHECK: cov-fns: 2
|
||||||
|
|
||||||
|
|
@ -63,7 +63,8 @@ enum ActionType {
|
|||||||
PrintCovPointsAction,
|
PrintCovPointsAction,
|
||||||
CoveredFunctionsAction,
|
CoveredFunctionsAction,
|
||||||
NotCoveredFunctionsAction,
|
NotCoveredFunctionsAction,
|
||||||
HtmlReportAction
|
HtmlReportAction,
|
||||||
|
StatsAction
|
||||||
};
|
};
|
||||||
|
|
||||||
cl::opt<ActionType> Action(
|
cl::opt<ActionType> Action(
|
||||||
@ -77,6 +78,8 @@ cl::opt<ActionType> Action(
|
|||||||
"Print all not covered funcions."),
|
"Print all not covered funcions."),
|
||||||
clEnumValN(HtmlReportAction, "html-report",
|
clEnumValN(HtmlReportAction, "html-report",
|
||||||
"Print HTML coverage report."),
|
"Print HTML coverage report."),
|
||||||
|
clEnumValN(StatsAction, "print-coverage-stats",
|
||||||
|
"Print coverage statistics."),
|
||||||
clEnumValEnd));
|
clEnumValEnd));
|
||||||
|
|
||||||
static cl::list<std::string>
|
static cl::list<std::string>
|
||||||
@ -516,6 +519,23 @@ static ErrorOr<bool> isCoverageFile(std::string FileName) {
|
|||||||
return Header->Magic == BinCoverageMagic;
|
return Header->Magic == BinCoverageMagic;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct CoverageStats {
|
||||||
|
CoverageStats() : AllPoints(0), CovPoints(0), AllFns(0), CovFns(0) {}
|
||||||
|
|
||||||
|
size_t AllPoints;
|
||||||
|
size_t CovPoints;
|
||||||
|
size_t AllFns;
|
||||||
|
size_t CovFns;
|
||||||
|
};
|
||||||
|
|
||||||
|
static raw_ostream &operator<<(raw_ostream &OS, const CoverageStats &Stats) {
|
||||||
|
OS << "all-points: " << Stats.AllPoints << "\n";
|
||||||
|
OS << "cov-points: " << Stats.CovPoints << "\n";
|
||||||
|
OS << "all-fns: " << Stats.AllFns << "\n";
|
||||||
|
OS << "cov-fns: " << Stats.CovFns << "\n";
|
||||||
|
return OS;
|
||||||
|
}
|
||||||
|
|
||||||
class CoverageData {
|
class CoverageData {
|
||||||
public:
|
public:
|
||||||
// Read single file coverage data.
|
// Read single file coverage data.
|
||||||
@ -615,9 +635,8 @@ public:
|
|||||||
MIXED = 3
|
MIXED = 3
|
||||||
};
|
};
|
||||||
|
|
||||||
SourceCoverageData(std::string ObjectFile, const std::set<uint64_t> &Addrs) {
|
SourceCoverageData(std::string ObjectFile, const std::set<uint64_t> &Addrs)
|
||||||
std::set<uint64_t> AllCovPoints = getCoveragePoints(ObjectFile);
|
: AllCovPoints(getCoveragePoints(ObjectFile)) {
|
||||||
|
|
||||||
if (!std::includes(AllCovPoints.begin(), AllCovPoints.end(), Addrs.begin(),
|
if (!std::includes(AllCovPoints.begin(), AllCovPoints.end(), Addrs.begin(),
|
||||||
Addrs.end())) {
|
Addrs.end())) {
|
||||||
Fail("Coverage points in binary and .sancov file do not match.");
|
Fail("Coverage points in binary and .sancov file do not match.");
|
||||||
@ -776,7 +795,15 @@ public:
|
|||||||
return Files;
|
return Files;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void collectStats(CoverageStats *Stats) const {
|
||||||
|
Stats->AllPoints += AllCovPoints.size();
|
||||||
|
Stats->AllFns += computeAllFunctions().size();
|
||||||
|
Stats->CovFns += computeCoveredFunctions().size();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
const std::set<uint64_t> AllCovPoints;
|
||||||
|
|
||||||
std::vector<AddrInfo> AllAddrInfo;
|
std::vector<AddrInfo> AllAddrInfo;
|
||||||
std::vector<AddrInfo> CovAddrInfo;
|
std::vector<AddrInfo> CovAddrInfo;
|
||||||
};
|
};
|
||||||
@ -954,6 +981,13 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void collectStats(CoverageStats *Stats) const {
|
||||||
|
Stats->CovPoints += Addrs->size();
|
||||||
|
|
||||||
|
SourceCoverageData SCovData(ObjectFile, *Addrs);
|
||||||
|
SCovData.collectStats(Stats);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CoverageDataWithObjectFile(std::string ObjectFile,
|
CoverageDataWithObjectFile(std::string ObjectFile,
|
||||||
std::unique_ptr<CoverageData> Coverage)
|
std::unique_ptr<CoverageData> Coverage)
|
||||||
@ -1048,6 +1082,14 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void printStats(raw_ostream &OS) const {
|
||||||
|
CoverageStats Stats;
|
||||||
|
for (const auto &Cov : Coverage) {
|
||||||
|
Cov->collectStats(&Stats);
|
||||||
|
}
|
||||||
|
OS << Stats;
|
||||||
|
}
|
||||||
|
|
||||||
void printReport(raw_ostream &OS) const {
|
void printReport(raw_ostream &OS) const {
|
||||||
auto Title =
|
auto Title =
|
||||||
(llvm::sys::path::filename(MainObjFile) + " Coverage Report").str();
|
(llvm::sys::path::filename(MainObjFile) + " Coverage Report").str();
|
||||||
@ -1172,6 +1214,10 @@ int main(int argc, char **argv) {
|
|||||||
CovDataSet.get()->printReport(outs());
|
CovDataSet.get()->printReport(outs());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
case StatsAction: {
|
||||||
|
CovDataSet.get()->printStats(outs());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
case PrintAction:
|
case PrintAction:
|
||||||
case PrintCovPointsAction:
|
case PrintCovPointsAction:
|
||||||
llvm_unreachable("unsupported action");
|
llvm_unreachable("unsupported action");
|
||||||
|
Loading…
Reference in New Issue
Block a user