[llvm] r218672 - llvm-cov: Use the number of executed functions for the function coverage metric.
Alex Lorenz
arphaman at gmail.com
Tue Sep 30 05:45:14 PDT 2014
Author: arphaman
Date: Tue Sep 30 07:45:13 2014
New Revision: 218672
URL: http://llvm.org/viewvc/llvm-project?rev=218672&view=rev
Log:
llvm-cov: Use the number of executed functions for the function coverage metric.
This commit fixes llvm-cov's function coverage metric by using the number of executed functions instead of the number of fully covered functions.
Differential Revision: http://reviews.llvm.org/D5196
Added:
llvm/trunk/test/tools/llvm-cov/Inputs/report.covmapping (with props)
llvm/trunk/test/tools/llvm-cov/Inputs/report.profdata (with props)
llvm/trunk/test/tools/llvm-cov/report.cpp
Modified:
llvm/trunk/include/llvm/ProfileData/CoverageMapping.h
llvm/trunk/lib/ProfileData/CoverageMapping.cpp
llvm/trunk/tools/llvm-cov/CoverageReport.cpp
llvm/trunk/tools/llvm-cov/CoverageSummary.cpp
llvm/trunk/tools/llvm-cov/CoverageSummaryInfo.cpp
llvm/trunk/tools/llvm-cov/CoverageSummaryInfo.h
Modified: llvm/trunk/include/llvm/ProfileData/CoverageMapping.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ProfileData/CoverageMapping.h?rev=218672&r1=218671&r2=218672&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ProfileData/CoverageMapping.h (original)
+++ llvm/trunk/include/llvm/ProfileData/CoverageMapping.h Tue Sep 30 07:45:13 2014
@@ -228,9 +228,13 @@ struct FunctionRecord {
std::vector<std::string> Filenames;
/// \brief Regions in the function along with their counts.
std::vector<CountedRegion> CountedRegions;
+ /// \brief The number of times this function was executed.
+ uint64_t ExecutionCount;
- FunctionRecord(StringRef Name, ArrayRef<StringRef> Filenames)
- : Name(Name), Filenames(Filenames.begin(), Filenames.end()) {}
+ FunctionRecord(StringRef Name, ArrayRef<StringRef> Filenames,
+ uint64_t ExecutionCount)
+ : Name(Name), Filenames(Filenames.begin(), Filenames.end()),
+ ExecutionCount(ExecutionCount) {}
};
/// \brief Coverage information for a macro expansion or #included file.
Modified: llvm/trunk/lib/ProfileData/CoverageMapping.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/CoverageMapping.cpp?rev=218672&r1=218671&r2=218672&view=diff
==============================================================================
--- llvm/trunk/lib/ProfileData/CoverageMapping.cpp (original)
+++ llvm/trunk/lib/ProfileData/CoverageMapping.cpp Tue Sep 30 07:45:13 2014
@@ -167,7 +167,9 @@ CoverageMapping::load(ObjectFileCoverage
continue;
}
- FunctionRecord Function(Record.FunctionName, Record.Filenames);
+ assert(Counts.size() != 0 && "Function's counts are empty");
+ FunctionRecord Function(Record.FunctionName, Record.Filenames,
+ Counts.front());
CounterMappingContext Ctx(Record.Expressions, Counts);
for (const auto &Region : Record.MappingRegions) {
ErrorOr<int64_t> ExecutionCount = Ctx.evaluate(Region.Count);
Added: llvm/trunk/test/tools/llvm-cov/Inputs/report.covmapping
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/Inputs/report.covmapping?rev=218672&view=auto
==============================================================================
Binary file - no diff available.
Propchange: llvm/trunk/test/tools/llvm-cov/Inputs/report.covmapping
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: llvm/trunk/test/tools/llvm-cov/Inputs/report.profdata
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/Inputs/report.profdata?rev=218672&view=auto
==============================================================================
Binary file - no diff available.
Propchange: llvm/trunk/test/tools/llvm-cov/Inputs/report.profdata
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: llvm/trunk/test/tools/llvm-cov/report.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/report.cpp?rev=218672&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-cov/report.cpp (added)
+++ llvm/trunk/test/tools/llvm-cov/report.cpp Tue Sep 30 07:45:13 2014
@@ -0,0 +1,24 @@
+// RUN: llvm-cov report %S/Inputs/report.covmapping -instr-profile %S/Inputs/report.profdata -no-colors 2>&1 | FileCheck %s
+
+// CHECK: Filename Regions Miss Cover Functions Executed
+// CHECK: TOTAL 5 2 60.00% 4 75.00%
+
+void foo(bool cond) {
+ if (cond) {
+ }
+}
+
+void bar() {
+}
+
+void func() {
+}
+
+int main() {
+ foo(false);
+ bar();
+ return 0;
+}
+
+// llvm-cov doesn't work on big endian yet
+// XFAIL: powerpc64-, s390x, mips-, mips64-, sparc
Modified: llvm/trunk/tools/llvm-cov/CoverageReport.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/CoverageReport.cpp?rev=218672&r1=218671&r2=218672&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/CoverageReport.cpp (original)
+++ llvm/trunk/tools/llvm-cov/CoverageReport.cpp Tue Sep 30 07:45:13 2014
@@ -85,7 +85,7 @@ static Column column(StringRef Str, unsi
return Column(Str, Width).set(Value);
}
-static const unsigned FileReportColumns[] = {25, 10, 8, 8, 10, 8};
+static const unsigned FileReportColumns[] = {25, 10, 8, 8, 10, 10};
static const unsigned FunctionReportColumns[] = {25, 10, 8, 8, 10, 8, 8};
/// \brief Prints a horizontal divider which spans across the given columns.
@@ -178,8 +178,8 @@ void CoverageReport::renderFunctionRepor
render(Function, OS);
renderDivider(FunctionReportColumns, OS);
OS << "\n";
- render(FunctionCoverageSummary("TOTAL", File.RegionCoverage,
- File.LineCoverage),
+ render(FunctionCoverageSummary("TOTAL", /*ExecutionCount=*/0,
+ File.RegionCoverage, File.LineCoverage),
OS);
}
}
@@ -190,7 +190,8 @@ void CoverageReport::renderFileReports(r
<< column("Miss", FileReportColumns[2], Column::RightAlignment)
<< column("Cover", FileReportColumns[3], Column::RightAlignment)
<< column("Functions", FileReportColumns[4], Column::RightAlignment)
- << column("Cover", FileReportColumns[5], Column::RightAlignment) << "\n";
+ << column("Executed", FileReportColumns[5], Column::RightAlignment)
+ << "\n";
renderDivider(FileReportColumns, OS);
OS << "\n";
for (const auto &File : Summary.getFileSummaries())
Modified: llvm/trunk/tools/llvm-cov/CoverageSummary.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/CoverageSummary.cpp?rev=218672&r1=218671&r2=218672&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/CoverageSummary.cpp (original)
+++ llvm/trunk/tools/llvm-cov/CoverageSummary.cpp Tue Sep 30 07:45:13 2014
@@ -72,7 +72,7 @@ CoverageSummary::createSummaries(ArrayRe
FileCoverageSummary CoverageSummary::getCombinedFileSummaries() {
size_t NumRegions = 0, CoveredRegions = 0;
size_t NumLines = 0, NonCodeLines = 0, CoveredLines = 0;
- size_t NumFunctionsCovered = 0, NumFunctions = 0;
+ size_t NumFunctionsExecuted = 0, NumFunctions = 0;
for (const auto &File : FileSummaries) {
NumRegions += File.RegionCoverage.NumRegions;
CoveredRegions += File.RegionCoverage.Covered;
@@ -81,12 +81,12 @@ FileCoverageSummary CoverageSummary::get
NonCodeLines += File.LineCoverage.NonCodeLines;
CoveredLines += File.LineCoverage.Covered;
- NumFunctionsCovered += File.FunctionCoverage.FullyCovered;
+ NumFunctionsExecuted += File.FunctionCoverage.Executed;
NumFunctions += File.FunctionCoverage.NumFunctions;
}
return FileCoverageSummary(
"TOTAL", RegionCoverageInfo(CoveredRegions, NumRegions),
LineCoverageInfo(CoveredLines, NonCodeLines, NumLines),
- FunctionCoverageInfo(NumFunctionsCovered, NumFunctions),
+ FunctionCoverageInfo(NumFunctionsExecuted, NumFunctions),
None);
}
Modified: llvm/trunk/tools/llvm-cov/CoverageSummaryInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/CoverageSummaryInfo.cpp?rev=218672&r1=218671&r2=218672&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/CoverageSummaryInfo.cpp (original)
+++ llvm/trunk/tools/llvm-cov/CoverageSummaryInfo.cpp Tue Sep 30 07:45:13 2014
@@ -65,7 +65,8 @@ FunctionCoverageSummary::get(const cover
NumLines += LineCount;
}
return FunctionCoverageSummary(
- Function.Name, RegionCoverageInfo(CoveredRegions, NumCodeRegions),
+ Function.Name, Function.ExecutionCount,
+ RegionCoverageInfo(CoveredRegions, NumCodeRegions),
LineCoverageInfo(CoveredLines, 0, NumLines));
}
@@ -74,7 +75,7 @@ FileCoverageSummary::get(StringRef Name,
ArrayRef<FunctionCoverageSummary> FunctionSummaries) {
size_t NumRegions = 0, CoveredRegions = 0;
size_t NumLines = 0, NonCodeLines = 0, CoveredLines = 0;
- size_t NumFunctionsCovered = 0;
+ size_t NumFunctionsExecuted = 0;
for (const auto &Func : FunctionSummaries) {
CoveredRegions += Func.RegionCoverage.Covered;
NumRegions += Func.RegionCoverage.NumRegions;
@@ -83,13 +84,13 @@ FileCoverageSummary::get(StringRef Name,
NonCodeLines += Func.LineCoverage.NonCodeLines;
NumLines += Func.LineCoverage.NumLines;
- if (Func.RegionCoverage.isFullyCovered())
- ++NumFunctionsCovered;
+ if (Func.ExecutionCount != 0)
+ ++NumFunctionsExecuted;
}
return FileCoverageSummary(
Name, RegionCoverageInfo(CoveredRegions, NumRegions),
LineCoverageInfo(CoveredLines, NonCodeLines, NumLines),
- FunctionCoverageInfo(NumFunctionsCovered, FunctionSummaries.size()),
+ FunctionCoverageInfo(NumFunctionsExecuted, FunctionSummaries.size()),
FunctionSummaries);
}
Modified: llvm/trunk/tools/llvm-cov/CoverageSummaryInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/CoverageSummaryInfo.h?rev=218672&r1=218671&r2=218672&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/CoverageSummaryInfo.h (original)
+++ llvm/trunk/tools/llvm-cov/CoverageSummaryInfo.h Tue Sep 30 07:45:13 2014
@@ -69,33 +69,34 @@ struct LineCoverageInfo {
/// \brief Provides information about function coverage for a file.
struct FunctionCoverageInfo {
- /// \brief The number of functions that have full
- /// region coverage.
- size_t FullyCovered;
+ /// \brief The number of functions that were executed.
+ size_t Executed;
/// \brief The total number of functions in this file.
size_t NumFunctions;
- FunctionCoverageInfo(size_t FullyCovered, size_t NumFunctions)
- : FullyCovered(FullyCovered), NumFunctions(NumFunctions) {}
+ FunctionCoverageInfo(size_t Executed, size_t NumFunctions)
+ : Executed(Executed), NumFunctions(NumFunctions) {}
- bool isFullyCovered() const { return FullyCovered == NumFunctions; }
+ bool isFullyCovered() const { return Executed == NumFunctions; }
double getPercentCovered() const {
- return double(FullyCovered) / double(NumFunctions) * 100.0;
+ return double(Executed) / double(NumFunctions) * 100.0;
}
};
/// \brief A summary of function's code coverage.
struct FunctionCoverageSummary {
StringRef Name;
+ uint64_t ExecutionCount;
RegionCoverageInfo RegionCoverage;
LineCoverageInfo LineCoverage;
- FunctionCoverageSummary(StringRef Name,
+ FunctionCoverageSummary(StringRef Name, uint64_t ExecutionCount,
const RegionCoverageInfo &RegionCoverage,
const LineCoverageInfo &LineCoverage)
- : Name(Name), RegionCoverage(RegionCoverage), LineCoverage(LineCoverage) {
+ : Name(Name), ExecutionCount(ExecutionCount),
+ RegionCoverage(RegionCoverage), LineCoverage(LineCoverage) {
}
/// \brief Compute the code coverage summary for the given function coverage
More information about the llvm-commits
mailing list