Stephen Hines | 37ed9c1 | 2014-12-01 14:51:49 -0800 | [diff] [blame] | 1 | //===- CoverageSummary.cpp - Code coverage summary ------------------------===// |
| 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 | // This class implements data management and rendering for the code coverage |
| 11 | // summaries of all files and functions. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "CoverageSummary.h" |
| 16 | #include "llvm/Support/FileSystem.h" |
| 17 | #include "llvm/Support/Format.h" |
| 18 | |
| 19 | using namespace llvm; |
| 20 | |
| 21 | unsigned CoverageSummary::getFileID(StringRef Filename) { |
| 22 | for (unsigned I = 0, E = Filenames.size(); I < E; ++I) { |
| 23 | if (sys::fs::equivalent(Filenames[I], Filename)) |
| 24 | return I; |
| 25 | } |
| 26 | Filenames.push_back(Filename); |
| 27 | return Filenames.size() - 1; |
| 28 | } |
| 29 | |
| 30 | void |
| 31 | CoverageSummary::createSummaries(const coverage::CoverageMapping &Coverage) { |
| 32 | for (StringRef Filename : Coverage.getUniqueSourceFiles()) { |
| 33 | size_t PrevSize = FunctionSummaries.size(); |
| 34 | for (const auto &F : Coverage.getCoveredFunctions(Filename)) |
| 35 | FunctionSummaries.push_back(FunctionCoverageSummary::get(F)); |
| 36 | size_t Count = FunctionSummaries.size() - PrevSize; |
| 37 | if (Count == 0) |
| 38 | continue; |
| 39 | FileSummaries.push_back(FileCoverageSummary::get( |
| 40 | Filename, makeArrayRef(FunctionSummaries.data() + PrevSize, Count))); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | FileCoverageSummary CoverageSummary::getCombinedFileSummaries() { |
| 45 | size_t NumRegions = 0, CoveredRegions = 0; |
| 46 | size_t NumLines = 0, NonCodeLines = 0, CoveredLines = 0; |
| 47 | size_t NumFunctionsExecuted = 0, NumFunctions = 0; |
| 48 | for (const auto &File : FileSummaries) { |
| 49 | NumRegions += File.RegionCoverage.NumRegions; |
| 50 | CoveredRegions += File.RegionCoverage.Covered; |
| 51 | |
| 52 | NumLines += File.LineCoverage.NumLines; |
| 53 | NonCodeLines += File.LineCoverage.NonCodeLines; |
| 54 | CoveredLines += File.LineCoverage.Covered; |
| 55 | |
| 56 | NumFunctionsExecuted += File.FunctionCoverage.Executed; |
| 57 | NumFunctions += File.FunctionCoverage.NumFunctions; |
| 58 | } |
| 59 | return FileCoverageSummary( |
| 60 | "TOTAL", RegionCoverageInfo(CoveredRegions, NumRegions), |
| 61 | LineCoverageInfo(CoveredLines, NonCodeLines, NumLines), |
| 62 | FunctionCoverageInfo(NumFunctionsExecuted, NumFunctions), |
| 63 | None); |
| 64 | } |