blob: 0036032ab399816d32346ba4727820f1b400cedf [file] [log] [blame]
Alex Lorenze82d89c2014-08-22 22:56:03 +00001//===- CoverageSummaryInfo.h - Coverage summary for function/file ---------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// These structures are used to represent code coverage metrics
11// for functions/files.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_COV_COVERAGESUMMARYINFO_H
16#define LLVM_COV_COVERAGESUMMARYINFO_H
17
Justin Bogner15562d02014-09-12 06:52:44 +000018#include "llvm/ProfileData/CoverageMapping.h"
Alex Lorenze82d89c2014-08-22 22:56:03 +000019#include "llvm/Support/raw_ostream.h"
20
21namespace llvm {
22
23/// \brief Provides information about region coverage for a function/file.
24struct RegionCoverageInfo {
25 /// \brief The number of regions that were executed at least once.
26 size_t Covered;
27
28 /// \brief The number of regions that weren't executed.
29 size_t NotCovered;
30
31 /// \brief The total number of regions in a function/file.
32 size_t NumRegions;
33
34 RegionCoverageInfo(size_t Covered, size_t NumRegions)
35 : Covered(Covered), NotCovered(NumRegions - Covered),
36 NumRegions(NumRegions) {}
37
38 bool isFullyCovered() const { return Covered == NumRegions; }
39
40 double getPercentCovered() const {
41 return double(Covered) / double(NumRegions) * 100.0;
42 }
43};
44
45/// \brief Provides information about line coverage for a function/file.
46struct LineCoverageInfo {
47 /// \brief The number of lines that were executed at least once.
48 size_t Covered;
49
50 /// \brief The number of lines that weren't executed.
51 size_t NotCovered;
52
53 /// \brief The number of lines that aren't code.
54 size_t NonCodeLines;
55
56 /// \brief The total number of lines in a function/file.
57 size_t NumLines;
58
59 LineCoverageInfo(size_t Covered, size_t NumNonCodeLines, size_t NumLines)
60 : Covered(Covered), NotCovered(NumLines - NumNonCodeLines - Covered),
61 NonCodeLines(NumNonCodeLines), NumLines(NumLines) {}
62
63 bool isFullyCovered() const { return Covered == (NumLines - NonCodeLines); }
64
65 double getPercentCovered() const {
66 return double(Covered) / double(NumLines - NonCodeLines) * 100.0;
67 }
68};
69
70/// \brief Provides information about function coverage for a file.
71struct FunctionCoverageInfo {
Alex Lorenzcb1702d2014-09-30 12:45:13 +000072 /// \brief The number of functions that were executed.
73 size_t Executed;
Alex Lorenze82d89c2014-08-22 22:56:03 +000074
75 /// \brief The total number of functions in this file.
76 size_t NumFunctions;
77
Alex Lorenzcb1702d2014-09-30 12:45:13 +000078 FunctionCoverageInfo(size_t Executed, size_t NumFunctions)
79 : Executed(Executed), NumFunctions(NumFunctions) {}
Alex Lorenze82d89c2014-08-22 22:56:03 +000080
Alex Lorenzcb1702d2014-09-30 12:45:13 +000081 bool isFullyCovered() const { return Executed == NumFunctions; }
Alex Lorenze82d89c2014-08-22 22:56:03 +000082
83 double getPercentCovered() const {
Alex Lorenzcb1702d2014-09-30 12:45:13 +000084 return double(Executed) / double(NumFunctions) * 100.0;
Alex Lorenze82d89c2014-08-22 22:56:03 +000085 }
86};
87
88/// \brief A summary of function's code coverage.
89struct FunctionCoverageSummary {
90 StringRef Name;
Alex Lorenzcb1702d2014-09-30 12:45:13 +000091 uint64_t ExecutionCount;
Alex Lorenze82d89c2014-08-22 22:56:03 +000092 RegionCoverageInfo RegionCoverage;
93 LineCoverageInfo LineCoverage;
94
Alex Lorenzcb1702d2014-09-30 12:45:13 +000095 FunctionCoverageSummary(StringRef Name, uint64_t ExecutionCount,
Alex Lorenze82d89c2014-08-22 22:56:03 +000096 const RegionCoverageInfo &RegionCoverage,
97 const LineCoverageInfo &LineCoverage)
Alex Lorenzcb1702d2014-09-30 12:45:13 +000098 : Name(Name), ExecutionCount(ExecutionCount),
99 RegionCoverage(RegionCoverage), LineCoverage(LineCoverage) {
Alex Lorenze82d89c2014-08-22 22:56:03 +0000100 }
101
102 /// \brief Compute the code coverage summary for the given function coverage
103 /// mapping record.
Justin Bogner15562d02014-09-12 06:52:44 +0000104 static FunctionCoverageSummary
Justin Bogner953e2402014-09-20 15:31:56 +0000105 get(const coverage::FunctionRecord &Function);
Alex Lorenze82d89c2014-08-22 22:56:03 +0000106};
107
108/// \brief A summary of file's code coverage.
109struct FileCoverageSummary {
110 StringRef Name;
111 RegionCoverageInfo RegionCoverage;
112 LineCoverageInfo LineCoverage;
113 FunctionCoverageInfo FunctionCoverage;
114 /// \brief The summary of every function
115 /// in this file.
116 ArrayRef<FunctionCoverageSummary> FunctionSummaries;
117
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) {}
125
126 /// \brief Compute the code coverage summary for a file.
127 static FileCoverageSummary
128 get(StringRef Name, ArrayRef<FunctionCoverageSummary> FunctionSummaries);
129};
130
131} // namespace llvm
132
133#endif // LLVM_COV_COVERAGESUMMARYINFO_H