1 //===- GCOV.cpp - LLVM coverage tool --------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // GCOV implements the interface to read and write coverage files that use
13 //===----------------------------------------------------------------------===//
15 #include "llvm/Support/GCOV.h"
16 #include "llvm/ADT/STLExtras.h"
17 #include "llvm/Support/Debug.h"
18 #include "llvm/Support/FileSystem.h"
19 #include "llvm/Support/Format.h"
20 #include "llvm/Support/MemoryObject.h"
21 #include "llvm/Support/Path.h"
23 #include <system_error>
26 //===----------------------------------------------------------------------===//
27 // GCOVFile implementation.
29 /// readGCNO - Read GCNO buffer.
30 bool GCOVFile::readGCNO(GCOVBuffer &Buffer) {
31 if (!Buffer.readGCNOFormat()) return false;
32 if (!Buffer.readGCOVVersion(Version)) return false;
34 if (!Buffer.readInt(Checksum)) return false;
36 if (!Buffer.readFunctionTag()) break;
37 auto GFun = make_unique<GCOVFunction>(*this);
38 if (!GFun->readGCNO(Buffer, Version))
40 Functions.push_back(std::move(GFun));
43 GCNOInitialized = true;
47 /// readGCDA - Read GCDA buffer. It is required that readGCDA() can only be
48 /// called after readGCNO().
49 bool GCOVFile::readGCDA(GCOVBuffer &Buffer) {
50 assert(GCNOInitialized && "readGCDA() can only be called after readGCNO()");
51 if (!Buffer.readGCDAFormat()) return false;
52 GCOV::GCOVVersion GCDAVersion;
53 if (!Buffer.readGCOVVersion(GCDAVersion)) return false;
54 if (Version != GCDAVersion) {
55 errs() << "GCOV versions do not match.\n";
59 uint32_t GCDAChecksum;
60 if (!Buffer.readInt(GCDAChecksum)) return false;
61 if (Checksum != GCDAChecksum) {
62 errs() << "File checksums do not match: " << Checksum << " != "
63 << GCDAChecksum << ".\n";
66 for (size_t i = 0, e = Functions.size(); i < e; ++i) {
67 if (!Buffer.readFunctionTag()) {
68 errs() << "Unexpected number of functions.\n";
71 if (!Functions[i]->readGCDA(Buffer, Version))
74 if (Buffer.readObjectTag()) {
77 if (!Buffer.readInt(Length)) return false;
78 if (!Buffer.readInt(Dummy)) return false; // checksum
79 if (!Buffer.readInt(Dummy)) return false; // num
80 if (!Buffer.readInt(RunCount)) return false;
81 Buffer.advanceCursor(Length-3);
83 while (Buffer.readProgramTag()) {
85 if (!Buffer.readInt(Length)) return false;
86 Buffer.advanceCursor(Length);
93 /// dump - Dump GCOVFile content to dbgs() for debugging purposes.
94 void GCOVFile::dump() const {
95 for (const auto &FPtr : Functions)
99 /// collectLineCounts - Collect line counts. This must be used after
100 /// reading .gcno and .gcda files.
101 void GCOVFile::collectLineCounts(FileInfo &FI) {
102 for (const auto &FPtr : Functions)
103 FPtr->collectLineCounts(FI);
104 FI.setRunCount(RunCount);
105 FI.setProgramCount(ProgramCount);
108 //===----------------------------------------------------------------------===//
109 // GCOVFunction implementation.
111 /// readGCNO - Read a function from the GCNO buffer. Return false if an error
113 bool GCOVFunction::readGCNO(GCOVBuffer &Buff, GCOV::GCOVVersion Version) {
115 if (!Buff.readInt(Dummy)) return false; // Function header length
116 if (!Buff.readInt(Ident)) return false;
117 if (!Buff.readInt(Checksum)) return false;
118 if (Version != GCOV::V402) {
119 uint32_t CfgChecksum;
120 if (!Buff.readInt(CfgChecksum)) return false;
121 if (Parent.getChecksum() != CfgChecksum) {
122 errs() << "File checksums do not match: " << Parent.getChecksum()
123 << " != " << CfgChecksum << " in (" << Name << ").\n";
127 if (!Buff.readString(Name)) return false;
128 if (!Buff.readString(Filename)) return false;
129 if (!Buff.readInt(LineNumber)) return false;
132 if (!Buff.readBlockTag()) {
133 errs() << "Block tag not found.\n";
137 if (!Buff.readInt(BlockCount)) return false;
138 for (uint32_t i = 0, e = BlockCount; i != e; ++i) {
139 if (!Buff.readInt(Dummy)) return false; // Block flags;
140 Blocks.push_back(make_unique<GCOVBlock>(*this, i));
144 while (Buff.readEdgeTag()) {
146 if (!Buff.readInt(EdgeCount)) return false;
147 EdgeCount = (EdgeCount - 1) / 2;
149 if (!Buff.readInt(BlockNo)) return false;
150 if (BlockNo >= BlockCount) {
151 errs() << "Unexpected block number: " << BlockNo << " (in " << Name
155 for (uint32_t i = 0, e = EdgeCount; i != e; ++i) {
157 if (!Buff.readInt(Dst)) return false;
158 Edges.push_back(make_unique<GCOVEdge>(*Blocks[BlockNo], *Blocks[Dst]));
159 GCOVEdge *Edge = Edges.back().get();
160 Blocks[BlockNo]->addDstEdge(Edge);
161 Blocks[Dst]->addSrcEdge(Edge);
162 if (!Buff.readInt(Dummy)) return false; // Edge flag
167 while (Buff.readLineTag()) {
168 uint32_t LineTableLength;
169 // Read the length of this line table.
170 if (!Buff.readInt(LineTableLength)) return false;
171 uint32_t EndPos = Buff.getCursor() + LineTableLength*4;
173 // Read the block number this table is associated with.
174 if (!Buff.readInt(BlockNo)) return false;
175 if (BlockNo >= BlockCount) {
176 errs() << "Unexpected block number: " << BlockNo << " (in " << Name
180 GCOVBlock &Block = *Blocks[BlockNo];
181 // Read the word that pads the beginning of the line table. This may be a
182 // flag of some sort, but seems to always be zero.
183 if (!Buff.readInt(Dummy)) return false;
185 // Line information starts here and continues up until the last word.
186 if (Buff.getCursor() != (EndPos - sizeof(uint32_t))) {
188 // Read the source file name.
189 if (!Buff.readString(F)) return false;
191 errs() << "Multiple sources for a single basic block: " << Filename
192 << " != " << F << " (in " << Name << ").\n";
195 // Read lines up to, but not including, the null terminator.
196 while (Buff.getCursor() < (EndPos - 2 * sizeof(uint32_t))) {
198 if (!Buff.readInt(Line)) return false;
199 // Line 0 means this instruction was injected by the compiler. Skip it.
203 // Read the null terminator.
204 if (!Buff.readInt(Dummy)) return false;
206 // The last word is either a flag or padding, it isn't clear which. Skip
208 if (!Buff.readInt(Dummy)) return false;
213 /// readGCDA - Read a function from the GCDA buffer. Return false if an error
215 bool GCOVFunction::readGCDA(GCOVBuffer &Buff, GCOV::GCOVVersion Version) {
217 if (!Buff.readInt(Dummy)) return false; // Function header length
220 if (!Buff.readInt(GCDAIdent)) return false;
221 if (Ident != GCDAIdent) {
222 errs() << "Function identifiers do not match: " << Ident << " != "
223 << GCDAIdent << " (in " << Name << ").\n";
227 uint32_t GCDAChecksum;
228 if (!Buff.readInt(GCDAChecksum)) return false;
229 if (Checksum != GCDAChecksum) {
230 errs() << "Function checksums do not match: " << Checksum << " != "
231 << GCDAChecksum << " (in " << Name << ").\n";
235 uint32_t CfgChecksum;
236 if (Version != GCOV::V402) {
237 if (!Buff.readInt(CfgChecksum)) return false;
238 if (Parent.getChecksum() != CfgChecksum) {
239 errs() << "File checksums do not match: " << Parent.getChecksum()
240 << " != " << CfgChecksum << " (in " << Name << ").\n";
246 if (!Buff.readString(GCDAName)) return false;
247 if (Name != GCDAName) {
248 errs() << "Function names do not match: " << Name << " != " << GCDAName
253 if (!Buff.readArcTag()) {
254 errs() << "Arc tag not found (in " << Name << ").\n";
259 if (!Buff.readInt(Count)) return false;
262 // This for loop adds the counts for each block. A second nested loop is
263 // required to combine the edge counts that are contained in the GCDA file.
264 for (uint32_t BlockNo = 0; Count > 0; ++BlockNo) {
265 // The last block is always reserved for exit block
266 if (BlockNo >= Blocks.size()-1) {
267 errs() << "Unexpected number of edges (in " << Name << ").\n";
270 GCOVBlock &Block = *Blocks[BlockNo];
271 for (size_t EdgeNo = 0, End = Block.getNumDstEdges(); EdgeNo < End;
274 errs() << "Unexpected number of edges (in " << Name << ").\n";
278 if (!Buff.readInt64(ArcCount)) return false;
279 Block.addCount(EdgeNo, ArcCount);
282 Block.sortDstEdges();
287 /// getEntryCount - Get the number of times the function was called by
288 /// retrieving the entry block's count.
289 uint64_t GCOVFunction::getEntryCount() const {
290 return Blocks.front()->getCount();
293 /// getExitCount - Get the number of times the function returned by retrieving
294 /// the exit block's count.
295 uint64_t GCOVFunction::getExitCount() const {
296 return Blocks.back()->getCount();
299 /// dump - Dump GCOVFunction content to dbgs() for debugging purposes.
300 void GCOVFunction::dump() const {
301 dbgs() << "===== " << Name << " (" << Ident << ") @ " << Filename << ":"
302 << LineNumber << "\n";
303 for (const auto &Block : Blocks)
307 /// collectLineCounts - Collect line counts. This must be used after
308 /// reading .gcno and .gcda files.
309 void GCOVFunction::collectLineCounts(FileInfo &FI) {
310 // If the line number is zero, this is a function that doesn't actually appear
311 // in the source file, so there isn't anything we can do with it.
315 for (const auto &Block : Blocks)
316 Block->collectLineCounts(FI);
317 FI.addFunctionLine(Filename, LineNumber, this);
320 //===----------------------------------------------------------------------===//
321 // GCOVBlock implementation.
323 /// ~GCOVBlock - Delete GCOVBlock and its content.
324 GCOVBlock::~GCOVBlock() {
330 /// addCount - Add to block counter while storing the edge count. If the
331 /// destination has no outgoing edges, also update that block's count too.
332 void GCOVBlock::addCount(size_t DstEdgeNo, uint64_t N) {
333 assert(DstEdgeNo < DstEdges.size()); // up to caller to ensure EdgeNo is valid
334 DstEdges[DstEdgeNo]->Count = N;
336 if (!DstEdges[DstEdgeNo]->Dst.getNumDstEdges())
337 DstEdges[DstEdgeNo]->Dst.Counter += N;
340 /// sortDstEdges - Sort destination edges by block number, nop if already
341 /// sorted. This is required for printing branch info in the correct order.
342 void GCOVBlock::sortDstEdges() {
343 if (!DstEdgesAreSorted) {
344 SortDstEdgesFunctor SortEdges;
345 std::stable_sort(DstEdges.begin(), DstEdges.end(), SortEdges);
349 /// collectLineCounts - Collect line counts. This must be used after
350 /// reading .gcno and .gcda files.
351 void GCOVBlock::collectLineCounts(FileInfo &FI) {
352 for (SmallVectorImpl<uint32_t>::iterator I = Lines.begin(),
353 E = Lines.end(); I != E; ++I)
354 FI.addBlockLine(Parent.getFilename(), *I, this);
357 /// dump - Dump GCOVBlock content to dbgs() for debugging purposes.
358 void GCOVBlock::dump() const {
359 dbgs() << "Block : " << Number << " Counter : " << Counter << "\n";
360 if (!SrcEdges.empty()) {
361 dbgs() << "\tSource Edges : ";
362 for (EdgeIterator I = SrcEdges.begin(), E = SrcEdges.end(); I != E; ++I) {
363 const GCOVEdge *Edge = *I;
364 dbgs() << Edge->Src.Number << " (" << Edge->Count << "), ";
368 if (!DstEdges.empty()) {
369 dbgs() << "\tDestination Edges : ";
370 for (EdgeIterator I = DstEdges.begin(), E = DstEdges.end(); I != E; ++I) {
371 const GCOVEdge *Edge = *I;
372 dbgs() << Edge->Dst.Number << " (" << Edge->Count << "), ";
376 if (!Lines.empty()) {
377 dbgs() << "\tLines : ";
378 for (SmallVectorImpl<uint32_t>::const_iterator I = Lines.begin(),
379 E = Lines.end(); I != E; ++I)
380 dbgs() << (*I) << ",";
385 //===----------------------------------------------------------------------===//
386 // FileInfo implementation.
388 // Safe integer division, returns 0 if numerator is 0.
389 static uint32_t safeDiv(uint64_t Numerator, uint64_t Divisor) {
392 return Numerator/Divisor;
395 // This custom division function mimics gcov's branch ouputs:
396 // - Round to closest whole number
397 // - Only output 0% or 100% if it's exactly that value
398 static uint32_t branchDiv(uint64_t Numerator, uint64_t Divisor) {
401 if (Numerator == Divisor)
404 uint8_t Res = (Numerator*100+Divisor/2) / Divisor;
412 struct formatBranchInfo {
413 formatBranchInfo(const GCOVOptions &Options, uint64_t Count,
415 Options(Options), Count(Count), Total(Total) {}
417 void print(raw_ostream &OS) const {
419 OS << "never executed";
420 else if (Options.BranchCount)
421 OS << "taken " << Count;
423 OS << "taken " << branchDiv(Count, Total) << "%";
426 const GCOVOptions &Options;
431 static raw_ostream &operator<<(raw_ostream &OS, const formatBranchInfo &FBI) {
438 std::unique_ptr<MemoryBuffer> Buffer;
441 LineConsumer(StringRef Filename) {
442 ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr =
443 MemoryBuffer::getFileOrSTDIN(Filename);
444 if (std::error_code EC = BufferOrErr.getError()) {
445 errs() << Filename << ": " << EC.message() << "\n";
448 Buffer = std::move(BufferOrErr.get());
449 Remaining = Buffer->getBuffer();
452 bool empty() { return Remaining.empty(); }
453 void printNext(raw_ostream &OS, uint32_t LineNum) {
458 std::tie(Line, Remaining) = Remaining.split("\n");
459 OS << format("%5u:", LineNum) << Line << "\n";
464 /// Convert a path to a gcov filename. If PreservePaths is true, this
465 /// translates "/" to "#", ".." to "^", and drops ".", to match gcov.
466 static std::string mangleCoveragePath(StringRef Filename, bool PreservePaths) {
468 return sys::path::filename(Filename).str();
470 // This behaviour is defined by gcov in terms of text replacements, so it's
471 // not likely to do anything useful on filesystems with different textual
473 llvm::SmallString<256> Result("");
474 StringRef::iterator I, S, E;
475 for (I = S = Filename.begin(), E = Filename.end(); I != E; ++I) {
479 if (I - S == 1 && *S == '.') {
480 // ".", the current directory, is skipped.
481 } else if (I - S == 2 && *S == '.' && *(S + 1) == '.') {
482 // "..", the parent directory, is replaced with "^".
486 // Leave other components intact,
488 // And separate with "#".
489 Result.push_back('#');
499 std::string FileInfo::getCoveragePath(StringRef Filename,
500 StringRef MainFilename) {
501 if (Options.NoOutput)
502 // This is probably a bug in gcov, but when -n is specified, paths aren't
503 // mangled at all, and the -l and -p options are ignored. Here, we do the
507 std::string CoveragePath;
508 if (Options.LongFileNames && !Filename.equals(MainFilename))
510 mangleCoveragePath(MainFilename, Options.PreservePaths) + "##";
512 mangleCoveragePath(Filename, Options.PreservePaths) + ".gcov";
516 std::unique_ptr<raw_ostream>
517 FileInfo::openCoveragePath(StringRef CoveragePath) {
518 if (Options.NoOutput)
519 return llvm::make_unique<raw_null_ostream>();
522 auto OS = llvm::make_unique<raw_fd_ostream>(CoveragePath.str(), EC,
525 errs() << EC.message() << "\n";
526 return llvm::make_unique<raw_null_ostream>();
528 return std::move(OS);
531 /// print - Print source files with collected line count information.
532 void FileInfo::print(StringRef MainFilename, StringRef GCNOFile,
533 StringRef GCDAFile) {
534 for (StringMap<LineData>::const_iterator I = LineInfo.begin(),
535 E = LineInfo.end(); I != E; ++I) {
536 StringRef Filename = I->first();
537 auto AllLines = LineConsumer(Filename);
539 std::string CoveragePath = getCoveragePath(Filename, MainFilename);
540 std::unique_ptr<raw_ostream> S = openCoveragePath(CoveragePath);
541 raw_ostream &OS = *S;
543 OS << " -: 0:Source:" << Filename << "\n";
544 OS << " -: 0:Graph:" << GCNOFile << "\n";
545 OS << " -: 0:Data:" << GCDAFile << "\n";
546 OS << " -: 0:Runs:" << RunCount << "\n";
547 OS << " -: 0:Programs:" << ProgramCount << "\n";
549 const LineData &Line = I->second;
550 GCOVCoverage FileCoverage(Filename);
551 for (uint32_t LineIndex = 0;
552 LineIndex < Line.LastLine || !AllLines.empty(); ++LineIndex) {
553 if (Options.BranchInfo) {
554 FunctionLines::const_iterator FuncsIt = Line.Functions.find(LineIndex);
555 if (FuncsIt != Line.Functions.end())
556 printFunctionSummary(OS, FuncsIt->second);
559 BlockLines::const_iterator BlocksIt = Line.Blocks.find(LineIndex);
560 if (BlocksIt == Line.Blocks.end()) {
561 // No basic blocks are on this line. Not an executable line of code.
563 AllLines.printNext(OS, LineIndex + 1);
565 const BlockVector &Blocks = BlocksIt->second;
567 // Add up the block counts to form line counts.
568 DenseMap<const GCOVFunction *, bool> LineExecs;
569 uint64_t LineCount = 0;
570 for (BlockVector::const_iterator I = Blocks.begin(), E = Blocks.end();
572 const GCOVBlock *Block = *I;
573 if (Options.AllBlocks) {
574 // Only take the highest block count for that line.
575 uint64_t BlockCount = Block->getCount();
576 LineCount = LineCount > BlockCount ? LineCount : BlockCount;
578 // Sum up all of the block counts.
579 LineCount += Block->getCount();
582 if (Options.FuncCoverage) {
583 // This is a slightly convoluted way to most accurately gather line
584 // statistics for functions. Basically what is happening is that we
585 // don't want to count a single line with multiple blocks more than
586 // once. However, we also don't simply want to give the total line
587 // count to every function that starts on the line. Thus, what is
588 // happening here are two things:
589 // 1) Ensure that the number of logical lines is only incremented
590 // once per function.
591 // 2) If there are multiple blocks on the same line, ensure that the
592 // number of lines executed is incremented as long as at least
593 // one of the blocks are executed.
594 const GCOVFunction *Function = &Block->getParent();
595 if (FuncCoverages.find(Function) == FuncCoverages.end()) {
596 std::pair<const GCOVFunction *, GCOVCoverage>
597 KeyValue(Function, GCOVCoverage(Function->getName()));
598 FuncCoverages.insert(KeyValue);
600 GCOVCoverage &FuncCoverage = FuncCoverages.find(Function)->second;
602 if (LineExecs.find(Function) == LineExecs.end()) {
603 if (Block->getCount()) {
604 ++FuncCoverage.LinesExec;
605 LineExecs[Function] = true;
607 LineExecs[Function] = false;
609 ++FuncCoverage.LogicalLines;
610 } else if (!LineExecs[Function] && Block->getCount()) {
611 ++FuncCoverage.LinesExec;
612 LineExecs[Function] = true;
620 OS << format("%9" PRIu64 ":", LineCount);
621 ++FileCoverage.LinesExec;
623 ++FileCoverage.LogicalLines;
625 AllLines.printNext(OS, LineIndex + 1);
627 uint32_t BlockNo = 0;
629 for (BlockVector::const_iterator I = Blocks.begin(), E = Blocks.end();
631 const GCOVBlock *Block = *I;
633 // Only print block and branch information at the end of the block.
634 if (Block->getLastLine() != LineIndex+1)
636 if (Options.AllBlocks)
637 printBlockInfo(OS, *Block, LineIndex, BlockNo);
638 if (Options.BranchInfo) {
639 size_t NumEdges = Block->getNumDstEdges();
641 printBranchInfo(OS, *Block, FileCoverage, EdgeNo);
642 else if (Options.UncondBranch && NumEdges == 1)
643 printUncondBranchInfo(OS, EdgeNo, (*Block->dst_begin())->Count);
648 FileCoverages.push_back(std::make_pair(CoveragePath, FileCoverage));
651 // FIXME: There is no way to detect calls given current instrumentation.
652 if (Options.FuncCoverage)
658 /// printFunctionSummary - Print function and block summary.
659 void FileInfo::printFunctionSummary(raw_ostream &OS,
660 const FunctionVector &Funcs) const {
661 for (FunctionVector::const_iterator I = Funcs.begin(), E = Funcs.end();
663 const GCOVFunction *Func = *I;
664 uint64_t EntryCount = Func->getEntryCount();
665 uint32_t BlocksExec = 0;
666 for (GCOVFunction::BlockIterator I = Func->block_begin(),
667 E = Func->block_end(); I != E; ++I) {
668 const GCOVBlock &Block = **I;
669 if (Block.getNumDstEdges() && Block.getCount())
673 OS << "function " << Func->getName() << " called " << EntryCount
674 << " returned " << safeDiv(Func->getExitCount()*100, EntryCount)
675 << "% blocks executed "
676 << safeDiv(BlocksExec*100, Func->getNumBlocks()-1) << "%\n";
680 /// printBlockInfo - Output counts for each block.
681 void FileInfo::printBlockInfo(raw_ostream &OS, const GCOVBlock &Block,
682 uint32_t LineIndex, uint32_t &BlockNo) const {
683 if (Block.getCount() == 0)
686 OS << format("%9" PRIu64 ":", Block.getCount());
687 OS << format("%5u-block %2u\n", LineIndex+1, BlockNo++);
690 /// printBranchInfo - Print conditional branch probabilities.
691 void FileInfo::printBranchInfo(raw_ostream &OS, const GCOVBlock &Block,
692 GCOVCoverage &Coverage, uint32_t &EdgeNo) {
693 SmallVector<uint64_t, 16> BranchCounts;
694 uint64_t TotalCounts = 0;
695 for (GCOVBlock::EdgeIterator I = Block.dst_begin(), E = Block.dst_end();
697 const GCOVEdge *Edge = *I;
698 BranchCounts.push_back(Edge->Count);
699 TotalCounts += Edge->Count;
700 if (Block.getCount()) ++Coverage.BranchesExec;
701 if (Edge->Count) ++Coverage.BranchesTaken;
704 if (Options.FuncCoverage) {
705 const GCOVFunction *Function = &Block.getParent();
706 GCOVCoverage &FuncCoverage = FuncCoverages.find(Function)->second;
707 if (Block.getCount()) ++FuncCoverage.BranchesExec;
708 if (Edge->Count) ++FuncCoverage.BranchesTaken;
709 ++FuncCoverage.Branches;
713 for (SmallVectorImpl<uint64_t>::const_iterator I = BranchCounts.begin(),
714 E = BranchCounts.end(); I != E; ++I) {
715 OS << format("branch %2u ", EdgeNo++)
716 << formatBranchInfo(Options, *I, TotalCounts) << "\n";
720 /// printUncondBranchInfo - Print unconditional branch probabilities.
721 void FileInfo::printUncondBranchInfo(raw_ostream &OS, uint32_t &EdgeNo,
722 uint64_t Count) const {
723 OS << format("unconditional %2u ", EdgeNo++)
724 << formatBranchInfo(Options, Count, Count) << "\n";
727 // printCoverage - Print generic coverage info used by both printFuncCoverage
728 // and printFileCoverage.
729 void FileInfo::printCoverage(const GCOVCoverage &Coverage) const {
730 outs() << format("Lines executed:%.2f%% of %u\n",
731 double(Coverage.LinesExec)*100/Coverage.LogicalLines,
732 Coverage.LogicalLines);
733 if (Options.BranchInfo) {
734 if (Coverage.Branches) {
735 outs() << format("Branches executed:%.2f%% of %u\n",
736 double(Coverage.BranchesExec)*100/Coverage.Branches,
738 outs() << format("Taken at least once:%.2f%% of %u\n",
739 double(Coverage.BranchesTaken)*100/Coverage.Branches,
742 outs() << "No branches\n";
744 outs() << "No calls\n"; // to be consistent with gcov
748 // printFuncCoverage - Print per-function coverage info.
749 void FileInfo::printFuncCoverage() const {
750 for (FuncCoverageMap::const_iterator I = FuncCoverages.begin(),
751 E = FuncCoverages.end(); I != E; ++I) {
752 const GCOVCoverage &Coverage = I->second;
753 outs() << "Function '" << Coverage.Name << "'\n";
754 printCoverage(Coverage);
759 // printFileCoverage - Print per-file coverage info.
760 void FileInfo::printFileCoverage() const {
761 for (FileCoverageList::const_iterator I = FileCoverages.begin(),
762 E = FileCoverages.end(); I != E; ++I) {
763 const std::string &Filename = I->first;
764 const GCOVCoverage &Coverage = I->second;
765 outs() << "File '" << Coverage.Name << "'\n";
766 printCoverage(Coverage);
767 if (!Options.NoOutput)
768 outs() << Coverage.Name << ":creating '" << Filename << "'\n";