Coverage Report

Created: 2019-01-18 03:29

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/llvm-cov/CoverageSummaryInfo.cpp
Line
Count
Source
1
//===- CoverageSummaryInfo.cpp - 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
#include "CoverageSummaryInfo.h"
16
17
using namespace llvm;
18
using namespace coverage;
19
20
FunctionCoverageSummary
21
FunctionCoverageSummary::get(const CoverageMapping &CM,
22
193
                             const coverage::FunctionRecord &Function) {
23
193
  // Compute the region coverage.
24
193
  size_t NumCodeRegions = 0, CoveredRegions = 0;
25
956
  for (auto &CR : Function.CountedRegions) {
26
956
    if (CR.Kind != CounterMappingRegion::CodeRegion)
27
246
      continue;
28
710
    ++NumCodeRegions;
29
710
    if (CR.ExecutionCount != 0)
30
545
      ++CoveredRegions;
31
710
  }
32
193
33
193
  // Compute the line coverage
34
193
  size_t NumLines = 0, CoveredLines = 0;
35
193
  CoverageData CD = CM.getCoverageForFunction(Function);
36
1.30k
  for (const auto &LCS : getLineCoverageStats(CD)) {
37
1.30k
    if (!LCS.isMapped())
38
33
      continue;
39
1.27k
    ++NumLines;
40
1.27k
    if (LCS.getExecutionCount())
41
1.07k
      ++CoveredLines;
42
1.27k
  }
43
193
44
193
  return FunctionCoverageSummary(
45
193
      Function.Name, Function.ExecutionCount,
46
193
      RegionCoverageInfo(CoveredRegions, NumCodeRegions),
47
193
      LineCoverageInfo(CoveredLines, NumLines));
48
193
}
49
50
FunctionCoverageSummary
51
FunctionCoverageSummary::get(const InstantiationGroup &Group,
52
145
                             ArrayRef<FunctionCoverageSummary> Summaries) {
53
145
  std::string Name;
54
145
  if (Group.hasName()) {
55
119
    Name = Group.getName();
56
119
  } else {
57
26
    llvm::raw_string_ostream OS(Name);
58
26
    OS << "Definition at line " << Group.getLine() << ", column "
59
26
       << Group.getColumn();
60
26
  }
61
145
62
145
  FunctionCoverageSummary Summary(Name);
63
145
  Summary.ExecutionCount = Group.getTotalExecutionCount();
64
145
  Summary.RegionCoverage = Summaries[0].RegionCoverage;
65
145
  Summary.LineCoverage = Summaries[0].LineCoverage;
66
145
  for (const auto &FCS : Summaries.drop_front()) {
67
34
    Summary.RegionCoverage.merge(FCS.RegionCoverage);
68
34
    Summary.LineCoverage.merge(FCS.LineCoverage);
69
34
  }
70
145
  return Summary;
71
145
}