Coverage Report

Created: 2018-10-23 15:26

/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
191
                             const coverage::FunctionRecord &Function) {
23
191
  // Compute the region coverage.
24
191
  size_t NumCodeRegions = 0, CoveredRegions = 0;
25
934
  for (auto &CR : Function.CountedRegions) {
26
934
    if (CR.Kind != CounterMappingRegion::CodeRegion)
27
240
      continue;
28
694
    ++NumCodeRegions;
29
694
    if (CR.ExecutionCount != 0)
30
529
      ++CoveredRegions;
31
694
  }
32
191
33
191
  // Compute the line coverage
34
191
  size_t NumLines = 0, CoveredLines = 0;
35
191
  CoverageData CD = CM.getCoverageForFunction(Function);
36
1.27k
  for (const auto &LCS : getLineCoverageStats(CD)) {
37
1.27k
    if (!LCS.isMapped())
38
33
      continue;
39
1.23k
    ++NumLines;
40
1.23k
    if (LCS.getExecutionCount())
41
1.03k
      ++CoveredLines;
42
1.23k
  }
43
191
44
191
  return FunctionCoverageSummary(
45
191
      Function.Name, Function.ExecutionCount,
46
191
      RegionCoverageInfo(CoveredRegions, NumCodeRegions),
47
191
      LineCoverageInfo(CoveredLines, NumLines));
48
191
}
49
50
FunctionCoverageSummary
51
FunctionCoverageSummary::get(const InstantiationGroup &Group,
52
144
                             ArrayRef<FunctionCoverageSummary> Summaries) {
53
144
  std::string Name;
54
144
  if (Group.hasName()) {
55
116
    Name = Group.getName();
56
116
  } else {
57
28
    llvm::raw_string_ostream OS(Name);
58
28
    OS << "Definition at line " << Group.getLine() << ", column "
59
28
       << Group.getColumn();
60
28
  }
61
144
62
144
  FunctionCoverageSummary Summary(Name);
63
144
  Summary.ExecutionCount = Group.getTotalExecutionCount();
64
144
  Summary.RegionCoverage = Summaries[0].RegionCoverage;
65
144
  Summary.LineCoverage = Summaries[0].LineCoverage;
66
144
  for (const auto &FCS : Summaries.drop_front()) {
67
34
    Summary.RegionCoverage.merge(FCS.RegionCoverage);
68
34
    Summary.LineCoverage.merge(FCS.LineCoverage);
69
34
  }
70
144
  return Summary;
71
144
}