Coverage Report

Created: 2017-09-21 03:39

/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/tools/llvm-cov/CoverageSummaryInfo.h
Line
Count
Source (jump to first uncovered line)
1
//===- 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
18
#include "llvm/ProfileData/Coverage/CoverageMapping.h"
19
#include "llvm/Support/raw_ostream.h"
20
21
namespace llvm {
22
23
/// \brief Provides information about region coverage for a function/file.
24
class RegionCoverageInfo {
25
  /// \brief The number of regions that were executed at least once.
26
  size_t Covered;
27
28
  /// \brief The total number of regions in a function/file.
29
  size_t NumRegions;
30
31
public:
32
153
  RegionCoverageInfo() : Covered(0), NumRegions(0) {}
33
34
  RegionCoverageInfo(size_t Covered, size_t NumRegions)
35
88
      : Covered(Covered), NumRegions(NumRegions) {
36
88
    assert(Covered <= NumRegions && "Covered regions over-counted");
37
88
  }
38
39
145
  RegionCoverageInfo &operator+=(const RegionCoverageInfo &RHS) {
40
145
    Covered += RHS.Covered;
41
145
    NumRegions += RHS.NumRegions;
42
145
    return *this;
43
145
  }
44
45
10
  void merge(const RegionCoverageInfo &RHS) {
46
10
    Covered = std::max(Covered, RHS.Covered);
47
10
    NumRegions = std::max(NumRegions, RHS.NumRegions);
48
10
  }
49
50
112
  size_t getCovered() const { return Covered; }
51
52
226
  size_t getNumRegions() const { return NumRegions; }
53
54
78
  bool isFullyCovered() const { return Covered == NumRegions; }
55
56
139
  double getPercentCovered() const {
57
139
    assert(Covered <= NumRegions && "Covered regions over-counted");
58
139
    if (NumRegions == 0)
59
0
      return 0.0;
60
139
    return double(Covered) / double(NumRegions) * 100.0;
61
139
  }
62
};
63
64
/// \brief Provides information about line coverage for a function/file.
65
class LineCoverageInfo {
66
  /// \brief The number of lines that were executed at least once.
67
  size_t Covered;
68
69
  /// \brief The total number of lines in a function/file.
70
  size_t NumLines;
71
72
public:
73
153
  LineCoverageInfo() : Covered(0), NumLines(0) {}
74
75
  LineCoverageInfo(size_t Covered, size_t NumLines)
76
88
      : Covered(Covered), NumLines(NumLines) {
77
88
    assert(Covered <= NumLines && "Covered lines over-counted");
78
88
  }
79
80
145
  LineCoverageInfo &operator+=(const LineCoverageInfo &RHS) {
81
145
    Covered += RHS.Covered;
82
145
    NumLines += RHS.NumLines;
83
145
    return *this;
84
145
  }
85
86
10
  void merge(const LineCoverageInfo &RHS) {
87
10
    Covered = std::max(Covered, RHS.Covered);
88
10
    NumLines = std::max(NumLines, RHS.NumLines);
89
10
  }
90
91
96
  size_t getCovered() const { return Covered; }
92
93
210
  size_t getNumLines() const { return NumLines; }
94
95
78
  bool isFullyCovered() const { return Covered == NumLines; }
96
97
137
  double getPercentCovered() const {
98
137
    assert(Covered <= NumLines && "Covered lines over-counted");
99
137
    if (NumLines == 0)
100
0
      return 0.0;
101
137
    return double(Covered) / double(NumLines) * 100.0;
102
137
  }
103
};
104
105
/// \brief Provides information about function coverage for a file.
106
class FunctionCoverageInfo {
107
  /// \brief The number of functions that were executed.
108
  size_t Executed;
109
110
  /// \brief The total number of functions in this file.
111
  size_t NumFunctions;
112
113
public:
114
166
  FunctionCoverageInfo() : Executed(0), NumFunctions(0) {}
115
116
  FunctionCoverageInfo(size_t Executed, size_t NumFunctions)
117
0
      : Executed(Executed), NumFunctions(NumFunctions) {}
118
119
288
  void addFunction(bool Covered) {
120
288
    if (Covered)
121
258
      ++Executed;
122
288
    ++NumFunctions;
123
288
  }
124
125
102
  size_t getExecuted() const { return Executed; }
126
127
255
  size_t getNumFunctions() const { return NumFunctions; }
128
129
100
  bool isFullyCovered() const { return Executed == NumFunctions; }
130
131
120
  double getPercentCovered() const {
132
120
    assert(Executed <= NumFunctions && "Covered functions over-counted");
133
120
    if (NumFunctions == 0)
134
0
      return 0.0;
135
120
    return double(Executed) / double(NumFunctions) * 100.0;
136
120
  }
137
};
138
139
/// \brief Coverage statistics for a single line.
140
struct LineCoverageStats {
141
  uint64_t ExecutionCount;
142
  bool HasMultipleRegions;
143
  bool Mapped;
144
145
  LineCoverageStats(ArrayRef<const coverage::CoverageSegment *> LineSegments,
146
                    const coverage::CoverageSegment *WrappedSegment);
147
148
2.80k
  bool isMapped() const { return Mapped; }
149
150
514
  bool hasMultipleRegions() const { return HasMultipleRegions; }
151
};
152
153
/// \brief A summary of function's code coverage.
154
struct FunctionCoverageSummary {
155
  std::string Name;
156
  uint64_t ExecutionCount;
157
  RegionCoverageInfo RegionCoverage;
158
  LineCoverageInfo LineCoverage;
159
160
  FunctionCoverageSummary(const std::string &Name)
161
70
      : Name(Name), ExecutionCount(0), RegionCoverage(), LineCoverage() {}
162
163
  FunctionCoverageSummary(const std::string &Name, uint64_t ExecutionCount,
164
                          const RegionCoverageInfo &RegionCoverage,
165
                          const LineCoverageInfo &LineCoverage)
166
      : Name(Name), ExecutionCount(ExecutionCount),
167
88
        RegionCoverage(RegionCoverage), LineCoverage(LineCoverage) {}
168
169
  /// \brief Compute the code coverage summary for the given function coverage
170
  /// mapping record.
171
  static FunctionCoverageSummary get(const coverage::CoverageMapping &CM,
172
                                     const coverage::FunctionRecord &Function);
173
174
  /// Compute the code coverage summary for an instantiation group \p Group,
175
  /// given a list of summaries for each instantiation in \p Summaries.
176
  static FunctionCoverageSummary
177
  get(const coverage::InstantiationGroup &Group,
178
      ArrayRef<FunctionCoverageSummary> Summaries);
179
};
180
181
/// \brief A summary of file's code coverage.
182
struct FileCoverageSummary {
183
  StringRef Name;
184
  RegionCoverageInfo RegionCoverage;
185
  LineCoverageInfo LineCoverage;
186
  FunctionCoverageInfo FunctionCoverage;
187
  FunctionCoverageInfo InstantiationCoverage;
188
189
  FileCoverageSummary(StringRef Name)
190
      : Name(Name), RegionCoverage(), LineCoverage(), FunctionCoverage(),
191
83
        InstantiationCoverage() {}
192
193
134
  void addFunction(const FunctionCoverageSummary &Function) {
194
134
    RegionCoverage += Function.RegionCoverage;
195
134
    LineCoverage += Function.LineCoverage;
196
134
    FunctionCoverage.addFunction(/*Covered=*/Function.ExecutionCount > 0);
197
134
  }
198
199
154
  void addInstantiation(const FunctionCoverageSummary &Function) {
200
154
    InstantiationCoverage.addFunction(/*Covered=*/Function.ExecutionCount > 0);
201
154
  }
202
};
203
204
/// \brief A cache for demangled symbols.
205
struct DemangleCache {
206
  StringMap<std::string> DemangledNames;
207
208
  /// \brief Demangle \p Sym if possible. Otherwise, just return \p Sym.
209
63
  StringRef demangle(StringRef Sym) const {
210
63
    const auto DemangledName = DemangledNames.find(Sym);
211
63
    if (DemangledName == DemangledNames.end())
212
53
      return Sym;
213
10
    return DemangledName->getValue();
214
63
  }
215
};
216
217
} // namespace llvm
218
219
#endif // LLVM_COV_COVERAGESUMMARYINFO_H