+ FileCoverages.push_back(std::make_pair(CoveragePath, FileCoverage));
+ }
+
+ // FIXME: There is no way to detect calls given current instrumentation.
+ if (Options.FuncCoverage)
+ printFuncCoverage(InfoOS);
+ printFileCoverage(InfoOS);
+ return;
+}
+
+/// printFunctionSummary - Print function and block summary.
+void FileInfo::printFunctionSummary(raw_ostream &OS,
+ const FunctionVector &Funcs) const {
+ for (const GCOVFunction *Func : Funcs) {
+ uint64_t EntryCount = Func->getEntryCount();
+ uint32_t BlocksExec = 0;
+ for (const GCOVBlock &Block : Func->blocks())
+ if (Block.getNumDstEdges() && Block.getCount())
+ ++BlocksExec;
+
+ OS << "function " << Func->getName() << " called " << EntryCount
+ << " returned " << safeDiv(Func->getExitCount() * 100, EntryCount)
+ << "% blocks executed "
+ << safeDiv(BlocksExec * 100, Func->getNumBlocks() - 1) << "%\n";
+ }
+}
+
+/// printBlockInfo - Output counts for each block.
+void FileInfo::printBlockInfo(raw_ostream &OS, const GCOVBlock &Block,
+ uint32_t LineIndex, uint32_t &BlockNo) const {
+ if (Block.getCount() == 0)
+ OS << " $$$$$:";
+ else
+ OS << format("%9" PRIu64 ":", Block.getCount());
+ OS << format("%5u-block %2u\n", LineIndex + 1, BlockNo++);
+}
+
+/// printBranchInfo - Print conditional branch probabilities.
+void FileInfo::printBranchInfo(raw_ostream &OS, const GCOVBlock &Block,
+ GCOVCoverage &Coverage, uint32_t &EdgeNo) {
+ SmallVector<uint64_t, 16> BranchCounts;
+ uint64_t TotalCounts = 0;
+ for (const GCOVEdge *Edge : Block.dsts()) {
+ BranchCounts.push_back(Edge->Count);
+ TotalCounts += Edge->Count;
+ if (Block.getCount())
+ ++Coverage.BranchesExec;
+ if (Edge->Count)
+ ++Coverage.BranchesTaken;
+ ++Coverage.Branches;
+
+ if (Options.FuncCoverage) {
+ const GCOVFunction *Function = &Block.getParent();
+ GCOVCoverage &FuncCoverage = FuncCoverages.find(Function)->second;
+ if (Block.getCount())
+ ++FuncCoverage.BranchesExec;
+ if (Edge->Count)
+ ++FuncCoverage.BranchesTaken;
+ ++FuncCoverage.Branches;
+ }
+ }
+
+ for (uint64_t N : BranchCounts)
+ OS << format("branch %2u ", EdgeNo++)
+ << formatBranchInfo(Options, N, TotalCounts) << "\n";
+}
+
+/// printUncondBranchInfo - Print unconditional branch probabilities.
+void FileInfo::printUncondBranchInfo(raw_ostream &OS, uint32_t &EdgeNo,
+ uint64_t Count) const {
+ OS << format("unconditional %2u ", EdgeNo++)
+ << formatBranchInfo(Options, Count, Count) << "\n";
+}
+
+// printCoverage - Print generic coverage info used by both printFuncCoverage
+// and printFileCoverage.
+void FileInfo::printCoverage(raw_ostream &OS,
+ const GCOVCoverage &Coverage) const {
+ OS << format("Lines executed:%.2f%% of %u\n",
+ double(Coverage.LinesExec) * 100 / Coverage.LogicalLines,
+ Coverage.LogicalLines);
+ if (Options.BranchInfo) {
+ if (Coverage.Branches) {
+ OS << format("Branches executed:%.2f%% of %u\n",
+ double(Coverage.BranchesExec) * 100 / Coverage.Branches,
+ Coverage.Branches);
+ OS << format("Taken at least once:%.2f%% of %u\n",
+ double(Coverage.BranchesTaken) * 100 / Coverage.Branches,
+ Coverage.Branches);
+ } else {
+ OS << "No branches\n";
+ }
+ OS << "No calls\n"; // to be consistent with gcov
+ }
+}
+
+// printFuncCoverage - Print per-function coverage info.
+void FileInfo::printFuncCoverage(raw_ostream &OS) const {
+ for (const auto &FC : FuncCoverages) {
+ const GCOVCoverage &Coverage = FC.second;
+ OS << "Function '" << Coverage.Name << "'\n";
+ printCoverage(OS, Coverage);
+ OS << "\n";
+ }
+}
+
+// printFileCoverage - Print per-file coverage info.
+void FileInfo::printFileCoverage(raw_ostream &OS) const {
+ for (const auto &FC : FileCoverages) {
+ const std::string &Filename = FC.first;
+ const GCOVCoverage &Coverage = FC.second;
+ OS << "File '" << Coverage.Name << "'\n";
+ printCoverage(OS, Coverage);
+ if (!Options.NoOutput)
+ OS << Coverage.Name << ":creating '" << Filename << "'\n";
+ OS << "\n";