Alex Lorenz | e82d89c | 2014-08-22 22:56:03 +0000 | [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 | |
Justin Bogner | 953e240 | 2014-09-20 15:31:56 +0000 | [diff] [blame] | 30 | void |
Justin Bogner | d5fca92 | 2014-11-14 01:50:32 +0000 | [diff] [blame] | 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) |
Alex Lorenz | e82d89c | 2014-08-22 22:56:03 +0000 | [diff] [blame] | 38 | continue; |
Justin Bogner | d5fca92 | 2014-11-14 01:50:32 +0000 | [diff] [blame] | 39 | FileSummaries.push_back(FileCoverageSummary::get( |
| 40 | Filename, makeArrayRef(FunctionSummaries.data() + PrevSize, Count))); |
Alex Lorenz | e82d89c | 2014-08-22 22:56:03 +0000 | [diff] [blame] | 41 | } |
| 42 | } |
| 43 | |
| 44 | FileCoverageSummary CoverageSummary::getCombinedFileSummaries() { |
| 45 | size_t NumRegions = 0, CoveredRegions = 0; |
| 46 | size_t NumLines = 0, NonCodeLines = 0, CoveredLines = 0; |
Alex Lorenz | cb1702d | 2014-09-30 12:45:13 +0000 | [diff] [blame] | 47 | size_t NumFunctionsExecuted = 0, NumFunctions = 0; |
Alex Lorenz | e82d89c | 2014-08-22 22:56:03 +0000 | [diff] [blame] | 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 | |
Alex Lorenz | cb1702d | 2014-09-30 12:45:13 +0000 | [diff] [blame] | 56 | NumFunctionsExecuted += File.FunctionCoverage.Executed; |
Alex Lorenz | e82d89c | 2014-08-22 22:56:03 +0000 | [diff] [blame] | 57 | NumFunctions += File.FunctionCoverage.NumFunctions; |
| 58 | } |
| 59 | return FileCoverageSummary( |
| 60 | "TOTAL", RegionCoverageInfo(CoveredRegions, NumRegions), |
| 61 | LineCoverageInfo(CoveredLines, NonCodeLines, NumLines), |
Alex Lorenz | cb1702d | 2014-09-30 12:45:13 +0000 | [diff] [blame] | 62 | FunctionCoverageInfo(NumFunctionsExecuted, NumFunctions), |
Craig Topper | e1d1294 | 2014-08-27 05:25:25 +0000 | [diff] [blame] | 63 | None); |
Alex Lorenz | e82d89c | 2014-08-22 22:56:03 +0000 | [diff] [blame] | 64 | } |