1 //===- CoverageSummaryInfo.h - Coverage summary for function/file ---------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // These structures are used to represent code coverage metrics
11 // for functions/files.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_COV_COVERAGESUMMARYINFO_H
16 #define LLVM_COV_COVERAGESUMMARYINFO_H
18 #include "llvm/ProfileData/Coverage/CoverageMapping.h"
19 #include "llvm/Support/raw_ostream.h"
23 /// \brief Provides information about region coverage for a function/file.
24 struct RegionCoverageInfo {
25 /// \brief The number of regions that were executed at least once.
28 /// \brief The number of regions that weren't executed.
31 /// \brief The total number of regions in a function/file.
34 RegionCoverageInfo() : Covered(0), NotCovered(0), NumRegions(0) {}
36 RegionCoverageInfo(size_t Covered, size_t NumRegions)
37 : Covered(Covered), NotCovered(NumRegions - Covered),
38 NumRegions(NumRegions) {}
40 RegionCoverageInfo &operator+=(const RegionCoverageInfo &RHS) {
41 Covered += RHS.Covered;
42 NotCovered += RHS.NotCovered;
43 NumRegions += RHS.NumRegions;
47 bool isFullyCovered() const { return Covered == NumRegions; }
49 double getPercentCovered() const {
52 return double(Covered) / double(NumRegions) * 100.0;
56 /// \brief Provides information about line coverage for a function/file.
57 struct LineCoverageInfo {
58 /// \brief The number of lines that were executed at least once.
61 /// \brief The number of lines that weren't executed.
64 /// \brief The number of lines that aren't code.
67 /// \brief The total number of lines in a function/file.
71 : Covered(0), NotCovered(0), NonCodeLines(0), NumLines(0) {}
73 LineCoverageInfo(size_t Covered, size_t NumNonCodeLines, size_t NumLines)
74 : Covered(Covered), NotCovered(NumLines - NumNonCodeLines - Covered),
75 NonCodeLines(NumNonCodeLines), NumLines(NumLines) {}
77 LineCoverageInfo &operator+=(const LineCoverageInfo &RHS) {
78 Covered += RHS.Covered;
79 NotCovered += RHS.NotCovered;
80 NonCodeLines += RHS.NonCodeLines;
81 NumLines += RHS.NumLines;
85 bool isFullyCovered() const { return Covered == (NumLines - NonCodeLines); }
87 double getPercentCovered() const {
88 if (NumLines - NonCodeLines == 0)
90 return double(Covered) / double(NumLines - NonCodeLines) * 100.0;
94 /// \brief Provides information about function coverage for a file.
95 struct FunctionCoverageInfo {
96 /// \brief The number of functions that were executed.
99 /// \brief The total number of functions in this file.
102 FunctionCoverageInfo() : Executed(0), NumFunctions(0) {}
104 FunctionCoverageInfo(size_t Executed, size_t NumFunctions)
105 : Executed(Executed), NumFunctions(NumFunctions) {}
107 void addFunction(bool Covered) {
113 bool isFullyCovered() const { return Executed == NumFunctions; }
115 double getPercentCovered() const {
116 if (NumFunctions == 0)
118 return double(Executed) / double(NumFunctions) * 100.0;
122 /// \brief A summary of function's code coverage.
123 struct FunctionCoverageSummary {
125 uint64_t ExecutionCount;
126 RegionCoverageInfo RegionCoverage;
127 LineCoverageInfo LineCoverage;
129 FunctionCoverageSummary(StringRef Name) : Name(Name), ExecutionCount(0) {}
131 FunctionCoverageSummary(StringRef Name, uint64_t ExecutionCount,
132 const RegionCoverageInfo &RegionCoverage,
133 const LineCoverageInfo &LineCoverage)
134 : Name(Name), ExecutionCount(ExecutionCount),
135 RegionCoverage(RegionCoverage), LineCoverage(LineCoverage) {
138 /// \brief Compute the code coverage summary for the given function coverage
140 static FunctionCoverageSummary
141 get(const coverage::FunctionRecord &Function);
144 /// \brief A summary of file's code coverage.
145 struct FileCoverageSummary {
147 RegionCoverageInfo RegionCoverage;
148 LineCoverageInfo LineCoverage;
149 FunctionCoverageInfo FunctionCoverage;
151 FileCoverageSummary(StringRef Name) : Name(Name) {}
153 void addFunction(const FunctionCoverageSummary &Function) {
154 RegionCoverage += Function.RegionCoverage;
155 LineCoverage += Function.LineCoverage;
156 FunctionCoverage.addFunction(/*Covered=*/Function.ExecutionCount > 0);
162 #endif // LLVM_COV_COVERAGESUMMARYINFO_H