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/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 {
50 return double(Covered) / double(NumRegions) * 100.0;
54 /// \brief Provides information about line coverage for a function/file.
55 struct LineCoverageInfo {
56 /// \brief The number of lines that were executed at least once.
59 /// \brief The number of lines that weren't executed.
62 /// \brief The number of lines that aren't code.
65 /// \brief The total number of lines in a function/file.
69 : Covered(0), NotCovered(0), NonCodeLines(0), NumLines(0) {}
71 LineCoverageInfo(size_t Covered, size_t NumNonCodeLines, size_t NumLines)
72 : Covered(Covered), NotCovered(NumLines - NumNonCodeLines - Covered),
73 NonCodeLines(NumNonCodeLines), NumLines(NumLines) {}
75 LineCoverageInfo &operator+=(const LineCoverageInfo &RHS) {
76 Covered += RHS.Covered;
77 NotCovered += RHS.NotCovered;
78 NonCodeLines += RHS.NonCodeLines;
79 NumLines += RHS.NumLines;
83 bool isFullyCovered() const { return Covered == (NumLines - NonCodeLines); }
85 double getPercentCovered() const {
86 return double(Covered) / double(NumLines - NonCodeLines) * 100.0;
90 /// \brief Provides information about function coverage for a file.
91 struct FunctionCoverageInfo {
92 /// \brief The number of functions that were executed.
95 /// \brief The total number of functions in this file.
98 FunctionCoverageInfo() : Executed(0), NumFunctions(0) {}
100 FunctionCoverageInfo(size_t Executed, size_t NumFunctions)
101 : Executed(Executed), NumFunctions(NumFunctions) {}
103 void addFunction(bool Covered) {
109 bool isFullyCovered() const { return Executed == NumFunctions; }
111 double getPercentCovered() const {
112 return double(Executed) / double(NumFunctions) * 100.0;
116 /// \brief A summary of function's code coverage.
117 struct FunctionCoverageSummary {
119 uint64_t ExecutionCount;
120 RegionCoverageInfo RegionCoverage;
121 LineCoverageInfo LineCoverage;
123 FunctionCoverageSummary(StringRef Name) : Name(Name), ExecutionCount(0) {}
125 FunctionCoverageSummary(StringRef Name, uint64_t ExecutionCount,
126 const RegionCoverageInfo &RegionCoverage,
127 const LineCoverageInfo &LineCoverage)
128 : Name(Name), ExecutionCount(ExecutionCount),
129 RegionCoverage(RegionCoverage), LineCoverage(LineCoverage) {
132 /// \brief Compute the code coverage summary for the given function coverage
134 static FunctionCoverageSummary
135 get(const coverage::FunctionRecord &Function);
138 /// \brief A summary of file's code coverage.
139 struct FileCoverageSummary {
141 RegionCoverageInfo RegionCoverage;
142 LineCoverageInfo LineCoverage;
143 FunctionCoverageInfo FunctionCoverage;
145 FileCoverageSummary(StringRef Name) : Name(Name) {}
147 void addFunction(const FunctionCoverageSummary &Function) {
148 RegionCoverage += Function.RegionCoverage;
149 LineCoverage += Function.LineCoverage;
150 FunctionCoverage.addFunction(/*Covered=*/Function.ExecutionCount > 0);
156 #endif // LLVM_COV_COVERAGESUMMARYINFO_H