Coverage Report

Created: 2019-05-19 14:56

/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
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
// These structures are used to represent code coverage metrics
10
// for functions/files.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#include "CoverageSummaryInfo.h"
15
16
using namespace llvm;
17
using namespace coverage;
18
19
FunctionCoverageSummary
20
FunctionCoverageSummary::get(const CoverageMapping &CM,
21
199
                             const coverage::FunctionRecord &Function) {
22
199
  // Compute the region coverage.
23
199
  size_t NumCodeRegions = 0, CoveredRegions = 0;
24
980
  for (auto &CR : Function.CountedRegions) {
25
980
    if (CR.Kind != CounterMappingRegion::CodeRegion)
26
250
      continue;
27
730
    ++NumCodeRegions;
28
730
    if (CR.ExecutionCount != 0)
29
560
      ++CoveredRegions;
30
730
  }
31
199
32
199
  // Compute the line coverage
33
199
  size_t NumLines = 0, CoveredLines = 0;
34
199
  CoverageData CD = CM.getCoverageForFunction(Function);
35
1.33k
  for (const auto &LCS : getLineCoverageStats(CD)) {
36
1.33k
    if (!LCS.isMapped())
37
33
      continue;
38
1.30k
    ++NumLines;
39
1.30k
    if (LCS.getExecutionCount())
40
1.09k
      ++CoveredLines;
41
1.30k
  }
42
199
43
199
  return FunctionCoverageSummary(
44
199
      Function.Name, Function.ExecutionCount,
45
199
      RegionCoverageInfo(CoveredRegions, NumCodeRegions),
46
199
      LineCoverageInfo(CoveredLines, NumLines));
47
199
}
48
49
FunctionCoverageSummary
50
FunctionCoverageSummary::get(const InstantiationGroup &Group,
51
157
                             ArrayRef<FunctionCoverageSummary> Summaries) {
52
157
  std::string Name;
53
157
  if (Group.hasName()) {
54
128
    Name = Group.getName();
55
128
  } else {
56
29
    llvm::raw_string_ostream OS(Name);
57
29
    OS << "Definition at line " << Group.getLine() << ", column "
58
29
       << Group.getColumn();
59
29
  }
60
157
61
157
  FunctionCoverageSummary Summary(Name);
62
157
  Summary.ExecutionCount = Group.getTotalExecutionCount();
63
157
  Summary.RegionCoverage = Summaries[0].RegionCoverage;
64
157
  Summary.LineCoverage = Summaries[0].LineCoverage;
65
157
  for (const auto &FCS : Summaries.drop_front()) {
66
34
    Summary.RegionCoverage.merge(FCS.RegionCoverage);
67
34
    Summary.LineCoverage.merge(FCS.LineCoverage);
68
34
  }
69
157
  return Summary;
70
157
}