1 //===- CoverageSummaryInfo.cpp - 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 #include "CoverageSummaryInfo.h"
18 using namespace coverage
;
20 FunctionCoverageSummary
21 FunctionCoverageSummary::get(const CoverageMapping
&CM
,
22 const coverage::FunctionRecord
&Function
) {
23 // Compute the region coverage.
24 size_t NumCodeRegions
= 0, CoveredRegions
= 0;
25 for (auto &CR
: Function
.CountedRegions
) {
26 if (CR
.Kind
!= CounterMappingRegion::CodeRegion
)
29 if (CR
.ExecutionCount
!= 0)
33 // Compute the line coverage
34 size_t NumLines
= 0, CoveredLines
= 0;
35 CoverageData CD
= CM
.getCoverageForFunction(Function
);
36 for (const auto &LCS
: getLineCoverageStats(CD
)) {
40 if (LCS
.getExecutionCount())
44 return FunctionCoverageSummary(
45 Function
.Name
, Function
.ExecutionCount
,
46 RegionCoverageInfo(CoveredRegions
, NumCodeRegions
),
47 LineCoverageInfo(CoveredLines
, NumLines
));
50 FunctionCoverageSummary
51 FunctionCoverageSummary::get(const InstantiationGroup
&Group
,
52 ArrayRef
<FunctionCoverageSummary
> Summaries
) {
54 if (Group
.hasName()) {
55 Name
= Group
.getName();
57 llvm::raw_string_ostream
OS(Name
);
58 OS
<< "Definition at line " << Group
.getLine() << ", column "
62 FunctionCoverageSummary
Summary(Name
);
63 Summary
.ExecutionCount
= Group
.getTotalExecutionCount();
64 Summary
.RegionCoverage
= Summaries
[0].RegionCoverage
;
65 Summary
.LineCoverage
= Summaries
[0].LineCoverage
;
66 for (const auto &FCS
: Summaries
.drop_front()) {
67 Summary
.RegionCoverage
.merge(FCS
.RegionCoverage
);
68 Summary
.LineCoverage
.merge(FCS
.LineCoverage
);