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(size_t Covered, size_t NumRegions)
35 : Covered(Covered), NotCovered(NumRegions - Covered),
36 NumRegions(NumRegions) {}
38 bool isFullyCovered() const { return Covered == NumRegions; }
40 double getPercentCovered() const {
41 return double(Covered) / double(NumRegions) * 100.0;
45 /// \brief Provides information about line coverage for a function/file.
46 struct LineCoverageInfo {
47 /// \brief The number of lines that were executed at least once.
50 /// \brief The number of lines that weren't executed.
53 /// \brief The number of lines that aren't code.
56 /// \brief The total number of lines in a function/file.
59 LineCoverageInfo(size_t Covered, size_t NumNonCodeLines, size_t NumLines)
60 : Covered(Covered), NotCovered(NumLines - NumNonCodeLines - Covered),
61 NonCodeLines(NumNonCodeLines), NumLines(NumLines) {}
63 bool isFullyCovered() const { return Covered == (NumLines - NonCodeLines); }
65 double getPercentCovered() const {
66 return double(Covered) / double(NumLines - NonCodeLines) * 100.0;
70 /// \brief Provides information about function coverage for a file.
71 struct FunctionCoverageInfo {
72 /// \brief The number of functions that were executed.
75 /// \brief The total number of functions in this file.
78 FunctionCoverageInfo(size_t Executed, size_t NumFunctions)
79 : Executed(Executed), NumFunctions(NumFunctions) {}
81 bool isFullyCovered() const { return Executed == NumFunctions; }
83 double getPercentCovered() const {
84 return double(Executed) / double(NumFunctions) * 100.0;
88 /// \brief A summary of function's code coverage.
89 struct FunctionCoverageSummary {
91 uint64_t ExecutionCount;
92 RegionCoverageInfo RegionCoverage;
93 LineCoverageInfo LineCoverage;
95 FunctionCoverageSummary(StringRef Name, uint64_t ExecutionCount,
96 const RegionCoverageInfo &RegionCoverage,
97 const LineCoverageInfo &LineCoverage)
98 : Name(Name), ExecutionCount(ExecutionCount),
99 RegionCoverage(RegionCoverage), LineCoverage(LineCoverage) {
102 /// \brief Compute the code coverage summary for the given function coverage
104 static FunctionCoverageSummary
105 get(const coverage::FunctionRecord &Function);
108 /// \brief A summary of file's code coverage.
109 struct FileCoverageSummary {
111 RegionCoverageInfo RegionCoverage;
112 LineCoverageInfo LineCoverage;
113 FunctionCoverageInfo FunctionCoverage;
114 /// \brief The summary of every function
116 ArrayRef<FunctionCoverageSummary> FunctionSummaries;
118 FileCoverageSummary(StringRef Name, const RegionCoverageInfo &RegionCoverage,
119 const LineCoverageInfo &LineCoverage,
120 const FunctionCoverageInfo &FunctionCoverage,
121 ArrayRef<FunctionCoverageSummary> FunctionSummaries)
122 : Name(Name), RegionCoverage(RegionCoverage), LineCoverage(LineCoverage),
123 FunctionCoverage(FunctionCoverage),
124 FunctionSummaries(FunctionSummaries) {}
126 /// \brief Compute the code coverage summary for a file.
127 static FileCoverageSummary
128 get(StringRef Name, ArrayRef<FunctionCoverageSummary> FunctionSummaries);
133 #endif // LLVM_COV_COVERAGESUMMARYINFO_H